开发者

How to pass a property to an event with a Button

开发者 https://www.devze.com 2022-12-23 07:11 出处:网络
I\'m gen开发者_运维问答erating buttons dynamically that I want it to call a method like this: private function fetchTheDay(day:String):void {

I'm gen开发者_运维问答erating 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号