Giving closures a name
public class Something extends EventDispatcher | |
{ | |
private var outterHandler:Function; | |
private var innerHandler:Function; | |
public function init():void | |
{ | |
outerHandler = function(evt:UserEvent):void | |
{ | |
service = new Service(); | |
innerHandler = function(serviceEvt:ServiceEvent):void | |
{ | |
doSomething(evt.username, serviceEvt.result); | |
}; | |
service.addEventListener(ServiceEvent.STARTED, innerHandler); | |
service.start(evt.username): | |
}; | |
addEventListener(Event.COMPLETE, handler); | |
} | |
public function dispose():void | |
{ | |
if (service.hasEventListener(ServiceEvent.STARTED, innerHandler)) | |
{ | |
service.removeEventListener(ServiceEvent.STARTED, innerHandler); | |
} | |
removeEventListener(Event.COMPLETE, handler); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment