Skip to content

Instantly share code, notes, and snippets.

@ThomasBurleson
Created August 19, 2011 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasBurleson/1157828 to your computer and use it in GitHub Desktop.
Save ThomasBurleson/1157828 to your computer and use it in GitHub Desktop.
AS3 Closures Cleanup
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