2 Replies Latest reply on Sep 17, 2009 1:49 PM by msakrejda

    How to pass a function?



      I have a custom module with one button. I would like to use it in many places in my application, and I would like to call another function each time when I'll clik this button. I don't like to write many functions inside this module and call the right function base on some parameters passed to this module, I would like to write function in this module from what I will call my custom module. Coul anyone give me some tips how to do that, or give some link to any example or white papers?


      Best regards.

        • 1. Re: How to pass a function?
          TodLoch Level 1

          In other words, is it possible to call function defined in parent document, without using in child "parentDocument"? and don't use event dispatching?

          (you can assing a value to properties delcared in child module, it is possible to assing a "content of function" ?)

          • 2. Re: How to pass a function?
            msakrejda Level 4

            Look at the Function class and its apply method.


            In your module class, you can have



            public var callback:Function;


            private function handleClick(e:Event):void {

               var args:Array = []; // or whatever arguments you want to call the callback with

               callback.apply(null, args);