Fires one or more action events after a specified delay.
For example, an animation object can use a Timer
as the trigger for drawing its frames.
Setting up a timer
involves creating a Timer
object,
registering one or more action listeners on it,
and starting the timer using
the start
method.
For example,
the following code creates and starts a timer
that fires an action event once per second
(as specified by the first argument to the Timer
constructor).
The second argument to the Timer
constructor
specifies a listener to receive the timer's action events.
var delay:Number = 1000; //milliseconds var listener:Object = new Object(); listener.taskPerformer = function() { //...Perform a task... } var timer:Timer = new Timer(delay); timer.addActionListener(listener.taskPerformer, listener); timer.start();
new Timer()
public function addActionListener(func:Function, obj:Object):Object
Adds an action listener to the Timer
.
func | the listener function |
obj | the listener obj |
the listener just added.
public function setDelay(delay:Number):Void
Sets the Timer
's delay, the number of milliseconds
between successive events.
delay | the delay in milliseconds |
Error | when set delay <= 0 or delay == null |
public function setInitialDelay(initialDelay:Number):Void
Sets the Timer
's initial delay,
which by default is the same as the between-event delay.
This is used only for the first action event.
Subsequent events are spaced
using the delay property.
initialDelay | the delay, in milliseconds,
between the invocation of the start
method and the first event
fired by this timer
|
Error | when set initialDelay <= 0 or initialDelay == null |
public function setRepeats(flag:Boolean):Void
If flag
is false
,
instructs the Timer
to send only once
action event to its listeners after a start.
flag | specify false to make the timer
stop after sending its first action event.
Default value is true.
|
public function isRepeats():Boolean
Returns true
(the default)
if the Timer
will send
an action event
to its listeners multiple times.