Remove event listeners from anonymous functions
One issue with using anonymous functions as event handlers is that you cannot remove the listener, which ultimately hinders garbage collection.
A simple way around it is by using the EMCAScript "arguments" object.
event.currentTarget.removeEventListener(event.type, arguments.callee);
So for example:
public function showWindow():void
{
var popup:NativeWindow = new NativeWindow();
popup.addEventListener(Event.CLOSE, function(event:Event):void {
event.currentTarget.removeEventListener(event.type, arguments.callee);
trace("the window was closed");
}
}
http://blog.blakebarrett.net/2011/04/generic-event-listener-removal-from-any.html
Written by Blake Barrett
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Actionscript 3
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#