|
-
 Originally Posted by metafurionx
To anyone that ended here looking for a simple solution to a problem like Andreq85's, it does exist:
PHP Code:
var someHandlerFunc:Function = someFunc(someArgs);
myBtn.addEventListener(MouseEvent.CLICK, someHandlerFunc);
//myBtn.removeEventListener(MouseEvent.CLICK, someHandlerFunc);
function someFunc(someArgs:Object):Function {
return function(e:MouseEvent):void {
trace(someArgs);
};
}
For multiple elements you can do:
PHP Code:
btn1.addEventListener(MouseEvent.CLICK, addPage(1));
btn2.addEventListener(MouseEvent.CLICK, addPage(2));
btn3.addEventListener(MouseEvent.CLICK, addPage(3));
function addPage(_nPage:int):Function {
return function(e:MouseEvent):void {
nPage += _nPage;
};
}
Nifty trick for a one-off, and for lazy prototyping, but I think it would be a bit risky for a production system as it makes clean up code rather tough eg: it's rather tough to find a function reference to removeEventListener!
All the same, thanks for some food for thought.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|