In the previous section, we learned how to use
Event.ENTER_FRAME to create animations
synchronized with the Flash runtime's frame rate. In this section,
we'll see how to synchronize animations with an arbitrary time
interval, specified using the flash.utils.Timer class.
The Timer class is a
general utility class for executing code after a specified time
interval. Each Timer object
at a programmer-specified frequency. Functions wishing to be executed
at that frequency register with the Timer object for
The Timer class does not guarantee the frequency with which its listener functions are executed. If the system or the Flash runtime is busy at the time a Timer is scheduled to execute its listener functions, the execution will be delayed. For information on accounting for these delays in an animation, see the section "Velocity-Based Animation."
The general steps required to use the Timer class are as follows:
Create a new Timer object:
var timer:Timer = new Timer();
Set the frequency with which
TimerEvent.TIMER events should be
triggered, in milliseconds. For example, the following code sets
the frequency to 100 milliseconds (10
TimerEvent.TIMER event dispatches per
timer.delay = 100;
Set the total number of
TimerEvent.TIMER events to be triggered.
For example, the following code tells timer to dispatch a total of
timer.repeatCount = 5;
The special value ...