18
Jul
08

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 :)


4 Responses to “Passing Additional Parameters To Event Listener”


  1. 2 Shubhra
    August 26, 2008 at 7:24 am

    Thanks Srikant this problem was causing me a lot of trouble.

  2. 3 nylarch
    February 28, 2009 at 9:23 pm

    Bravo! This is a tough one to figure when you first want to do it in a project…thanks…

  3. 4 Luise
    December 28, 2009 at 10:49 pm

    Thanks very much!!!


Leave a Reply