Passing Additional Parameters To Event Listener

While configuring the event listeners for the a component, some time we want to pass additional parameters to the event listener.

Here is the trick how to do that;

First configure the the listener in this way;


myComponent.addEventListener(MouseEvent.CLICK, function(e:mouseEvent):void{
          var parm1:String = "First Parameter";
          var parm2:String = "Second Parameter";
          myClickHandler(e,parm1,parm2);
});

The write the listener function like this;


function myClickHandler(e,str1,str2):void{
    trace("Parameter 1 :"+str1);
    trace("Parameter 2 :"+str2);
}

Trick Always works well :)


About this entry