This is a discussion on Timer vs ENTER_FRAME within the Tutorials forums, part of the Flash English category; Timer vs ENTER_FRAME This a good question? As we saw, we can use the Timer Class or the event Event.ENTER_FRAME ...
Timer vs ENTER_FRAME
This a good question?
As we saw, we can use the Timer Class or the event Event.ENTER_FRAME to create animations.
But which one is best to use? Which method is more performing with the minimum CPU use for the user?
Let us look at a few facts to keep in mind?
If the application needs a change of frame rate
When a SWF is loaded into another SWF, the main SWF could have a different frame rate and (as we know that a loaded SWF inherits the frame rate of the main SWF) it could lead to have animations reproduced too slow or too fast.
In this case, the Timer Class offers the independence of the frame rate.
Using more instances of Timer requires more memory
In an application with a large number of animations, using the Timer Class requires more memory that the same number of animations created with the event ENTER_FRAME.
So it is advised, when we have more animations to run, to use ENTER_FRAME.
Using more instances of Timer can cause an excessive request of screen refreshes
In a Flash CS3 application, using a Timer, with the method updateAfterEvent() to check the animation of each object, would lead to an abnormal request to refresh the screen and so, there is a good chance to drive the user?s machine to its limit which would result in a drop of performance.
Based on those 3 facts described above, there are a few recommendations to obtain the best performance with a minimum effort:
- In applications that must synchronize animations created by Actionscript with animations created on frames of the timeline, to use Event.ENTER_FRAME
- In applications where the variations of the frame rate happen in runtime, to use a single and unique Timer to manage all the animations and their speeds.
- When the variations in runtime of the frame rate are considered acceptable, to use Event.ENTER_FRAME because the code to be used to create animations is generally simpler in comparison to the equivalent animation developed with the Timer Class.
- To avoid to use individual Timer to animate individual objects. Where possible, to use a single Timer that manages all the objects. This means that a unique Timer with a unique method UpdateAfterEvent() would be perfect.
See you soon!
Bookmarks