Passing args with event ?
Hi,
I'm a professional flash game developer and my week planning is to learn AS3 (kinda...cool ;) )
I've just started something but there is one minor problem.... I can't find a way to pass args with eventListener
back in the day (...like last week) in AS2 I used something like this :
Code:
myBtn.onRelease = Delegate.create(this, someFunc, someArgs)
Let's say I was using a custom Delegate with args...
but now with AS3 I need to do this
Code:
myBtn.addEventListener(Event.CLICK, someHandlerFunc)
function someHandlerFunc(){
someFunc(someArgs)
}
It's still work well... but it's kinda a pain to write an handler function for each btn (or whatever event sending object) I need. I mean.. if I have something like
Code:
function addPage(_nPage){
nPage += _nPage
}
and I got 3 button with "+1", "+2" and "+3" ... I'll do something like this ?
Code:
btn1.addEventListener(Event.CLICK, btn1Handler)
btn2.addEventListener(Event.CLICK, btn2Handler)
btn3.addEventListener(Event.CLICK, btn3Handler)
function btn1Handler(){
addPage(1);
}
function btn2Handler(){
addPage(2);
}
function btn3Handler(){
addPage(3);
}
is it me or it's kinda "ugly" ? I mean.. I could write 3 onRelease with Delegate in AS2... now I need 3 addEventListener with 3 function...
Thanks !