Timer class triggers time-based events in ActionScript 3.0. Nearly any application that involves real-world time uses a timer. Timers can be useful for animation, delaying an action, timing out when an asynchronous action takes too long to execute, triggering an action repeatedly or after a delay, or synchronizing several actions.
ActionScript 3.0 also provides access to several old-school timer methods that aren't object-oriented and don't use the event framework but can have their purposes.
In this chapter, I'll discuss how to set up your own timers, and offer a few tricks to help you get the most out of them.
For working with time, you'll be using the
Each instance of a
Timer will, while it's running, repeatedly fire events spaced out by a set amount of time. Using events rather than callback functions not only makes
Timers more consistent and easier to use, but it allows you to trigger multiple functions with a single
Timers are similar in some ways to
for loops in that both structures can be used to repeat a bit of code several times but are otherwise quite different.
for loops execute every iteration without pause and without coming up for air. No other code is executed until the
for loop is finished. Long
for loops can prevent your ...