> It seems that it is impossible to send information via the addEventListener as a parameter

 

Since event handlers like ShowMessage() should be methods, they have a 'this' object and can access any instance variables of their class. Therefore there does not need to be a way to pass in additional information beyond the event object.

 

- Gordon

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of meathead
Sent: Wednesday, July 12, 2006 2:13 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Pass a parameter in the event function of an addEventListener?

 

hi all and thanks in advance,

So I'm setting up buttons on the fly via actionscript and I want to
pass an ID number based on which button was selected. I was going
to use an addEventListener for the click event of the newly created
button, but then I saw this on the live docs

listener:Function — The listener function that processes the event.
This function must accept an Event object as its only parameter and
must return nothing, as this example shows:
function(evt:Event):void

It seems that it is impossible to send information via the
addEventListener as a parameter or a packed ID name, etc.

Anyone have an idea on how to dynamically build buttons and pass
info on to a click event? Here is my code so far. Comments
included to help debug....
***********CODE***************
// so far I've set up an array to return data from XML and am
//looping thru adding buttons where needed.
if(arrSection[i].MLSEID != null) {
var btn:Button = new Button()
btn.label = "MLSE Info";
btn.x = intX;
//tried to pack the info into the button ID property, no worky
btn.id = "MLSE" + arrSection[i].MLSEID;
//tried to send info as a parameter in the function, no worky
btn.addEventListener(MouseEvent.CLICK, ShowMessage);
btn.y = intY;
can.addChild(btn);
intY += 30;
}

public function ShowMessage(event:Event):void
{
//this is just a test to see if I can pass info.
Alert.show ();
}
*********END OF CODE***********

thanks again,
Aaron

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





YAHOO! GROUPS LINKS




__,_._,___

Reply via email to