Created
July 7, 2009 17:43
-
-
Save RandomEtc/142235 to your computer and use it in GitHub Desktop.
callNextFrame for as3
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
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