Passing Arguments to Event Handler AS3:
25 November 2008
4 Comments
In AS2 we use Delegate class to pass arguments to event handlers and scoping event handlers. But there is no Delegate class in AS3.
Still sending extra argument to event handlers is not a big deal.
We are going to use one way of sending extra parameters to event handlers in actionscript 3.0,
code:
button.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){handleClickEvent(e,"Home")});
function handleClickEvent(e:MouseEvent,str:String) {
trace("Argument :"+str,"- Event target :"+e.target.name);
}
output:
Argument :Home – Event target :button
Here note,
We are adding event handler for button symbol. On click we call an inline function where inturn we are passing the MouseEvent and a parameter.
Simple is’nt it.
Cheers
Translate this post











































Hi
This really helped me.I can pass arguments on panel onclick in flex 3 actionscript .
Thanks
Palash
Hmm. but how do you remove the eventListener again?
Now, this is genius!!
Thanks mate! I actually knew that… i just forgot how to make inline functions in AS3 (and forgot they were called “inline”)… LOL!
Passing arguments to event handlers this way is so much better for small apps, than making a custom Event class or dynamic class or any other similar overkill (which googling shows first as a way of dealing with the problem, sadly).
Leave your response!
Blog Rating
Average blog rating:
7.3
56 votes cast for 27 posts
Recent Posts
Categories
Recent Comments
Archives
Blogroll
Pages
Search Me
Archives
Most Commented
Tags
UserOnline