Does AS3 Event.ENTER_FRAME run on every frame, always? Even on slow computers?

zechdc picture zechdc · Jul 6, 2011 · Viewed 13k times · Source

I have a script that relies on ENTER_FRAME event to run every time. I have noticed on some slower computers there can be some lag when a flash movie is playing.

Does ENTER_FRAME run on every frame, even if its on a slow computer? If the flash movie lags, does the ENTER_FRAME event still run and the rendering just try to catch up?

Is running code on ENTER_FRAME a reliable way to execute code every time a frame is entered?

Answer

Michael Antipin picture Michael Antipin · Jul 6, 2011

Yep. Every frame, no exceptions. If something is slowing a movie down (either heavy scripts or heavy graphics), it Event.ENTER_FRAME handlers are still being executed before a frame is rendered.

Hence, it's generally a good idea to use a Timer instance with TimerEvent.TIMER, even if it's delay is set to be equal to 'ideal' frame duration for your movie's fps. Because timer handler is not bound to be triggered at exactly uniform rate.

See the following link for more in-depth explanation: The Elastic Racetrack