How to pass variables to a listener in AS3

Posted: June 5, 2009 in Actionscript
Tags: , ,

Sometimes you need to pass more than one arguements other than the “event” object. In that case you can use the following code:

//–Listener Function–//

private function listenerFunction(e:MouseEvent,passedVariable:Object): void {
        trace(passedVariable.name);
 }

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

//--Caller--//
private function callerFunction(): void {
      var callerObject:Object = {name:"I have a name for sure..."};

            someObject.addEventListener(MouseEvent.CLICK,function (e:MouseEvent) : void {
                  listenerFunction(e,callerObject);
            });
}

Hope that was useful.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s