2 Replies Latest reply on Apr 18, 2010 2:59 AM by pauland

    Reference to existing functions

    mxvx Level 1

      Is it possible to create a reference for a function in ActionScript?

       

      for eg.

      rivate

      private function clickHandler(event:MouseEvent,index:int):void

      {

      ...........

      ...........

      }

       

       

       

       

      I need a reference to the above function

        • 1. Re: Reference to existing functions
          David_F57 Level 5

          hi,

           

          not sure of what you are after here, you can call any function as long as it has a matching paramters, if you have 3 buttons and you wish to assign them the same click function you can do this in actionscript with a listener,

           

          i..e mybtn.addEventListener(MouseEvent.CLICK,clickHandler)

           

          obviously when assigning a listener to 'custom' events you need to deal with how the paramters are handled, there is plenty of information out there about custom event handlers.

           

           

          David.

          • 2. Re: Reference to existing functions
            pauland Level 4

            All function names are references, and variables can reference functions.

             

            David showed you the addEventListener(someEvent, someFunctionName) use.

             

             

            Paul

             

            ---------------------------------------------------------------

             

            private var foo:Function;

             

            private function init():void{

             

                      foo = bar;

                      foo("calling the bar function");

             

            }

             

            private function bar(str:String):void{

            //whatever

            }