views:

28

answers:

1

I'm generating buttons dynamically that I want it to call a method like this:

private function fetchTheDay(day:String):void {
...             
}

But I wasn't sure how to make the button pass the string to it

button.addEventListener(MouseEvent.CLICK,fetchTheDay);
buttonVGroup.addElement(button);

trying to do something like this didn't work:

 button.addEventListener(MouseEvent.CLICK,fetchTheDay(myString));

How should I do this?

+1  A: 

You can just use an inline function for this, it's the simplest solution:

button.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void
{
    fetchTheDay(myString));
});

Hope that helps, Lance

viatropos
This link provides a bit better solution along the same concept http://nwebb.co.uk/blog/?p=243
Tam