Created
August 15, 2011 21:28
-
-
Save jjgonecrypto/1147909 to your computer and use it in GitHub Desktop.
Giving closures a name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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