Skip to content

Instantly share code, notes, and snippets.

@RandomEtc
Created July 7, 2009 17:43
Show Gist options
  • Save RandomEtc/142235 to your computer and use it in GitHub Desktop.
Save RandomEtc/142235 to your computer and use it in GitHub Desktop.
callNextFrame for as3
protected var delayedCalls:Array = [];
protected function callNextFrame(callback:Function, args:Array=null):void
{
delayedCalls.push({ callback: callback, args: args });
if (!hasEventListener(Event.ENTER_FRAME)) {
addEventListener(Event.ENTER_FRAME, onEnterForCallNextFrame);
}
}
protected function onEnterForCallNextFrame(event:Event):void
{
while (delayedCalls.length > 0) {
var delayedCall:Object = delayedCalls.shift();
if (delayedCall.callback) {
(delayedCall.callback as Function).apply(this, delayedCall.args);
}
}
removeEventListener(Event.ENTER_FRAME, onEnterForCallNextFrame);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment