Home > Action Script 3 > Passing Variables to EventListeners in AS 3

Passing Variables to EventListeners in AS 3

March 6th, 2009

Instead of using anonymous functions we can write something like this to access variables from within eventListeners:


private classVar:String    = 'A string just for fun';

private function myClassFunction():void{

    var FunctionVar:String = 'A string just for fun';

    var myHandler:Function = function(e:Event):void{

        classVar           = 'Something else';

        FunctionVar        = 'Something else';

        trace('----Event.CLOSE-----');

        pslnote.removeEventListener(Event.CLOSE, myhandler);

        pslnote            = null;

        return;

    }//handlerEnd

    pslnote.addEventListener(Event.CLOSE,myHandler);

}//functionEnd
If you found this useful, leave a comment...I love comments :-).

  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • E-mail this story to a friend!
  • Print this article!
  • Spurl
  • StumbleUpon
  • Technorati

stevie Action Script 3

  1. No comments yet.
  1. No trackbacks yet.