Created
August 19, 2011 19:52
-
-
Save ThomasBurleson/1157828 to your computer and use it in GitHub Desktop.
AS3 Closures Cleanup
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 | |
{ | |
public function doSomething(index:int) : void | |
{ | |
// Async closure for timer completion event | |
function onComplete_doSomething(evt:TimerEvent) : void | |
{ | |
// Always clean up 1st, then notify listeners | |
timer.removeEventListener(TimerEvent.TIMER, onComplete_Timer ); | |
dispatchEvent(new SomethingEvent(SomethingEvent.SOMETHING_HAPPENED, index)); | |
}; | |
var timer : Timer = new Timer(1000, 1); // wait 1 second | |
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete_doSomething); | |
timer.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment