|
;it’s useful in situations where you want to stop listening after the first event has fired, for example. You can use it when the listener is an anonymous inner function, if you don’t know the type of the event, if the dispatcher is unknown or any combination of these.
Most of the time using weak references is probably more appropriate, but in some situations the snipplet above is handy.
A more complete example:
function registerHandler( handler : Function ) : void { dispatcher.addEventListener("somethingChanged", handler); }
// ...
registerHandler(somethingChangedHandler);
// ...
function somethingChangedHandler( event : Event ) : void { event.currentTarget.removeEventListener(event.type, arguments.callee);
performActionInResponseToEvent(); }
If we assume that the three parts of the code above are separated so that the first and the last don’t know about each other, but the middle part knows about both, we can see that the generic way of removing an event listener is more or less the only way to do it. Answered by: nvreddy
|