Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 202

Programming actionscript 3.0
Table of Contents

Advertisement

Here is a small sample application showing the Timer class in action:
package
{
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class ShortTimer extends Sprite
{
public function ShortTimer()
{
// creates a new five-second Timer
var minuteTimer:Timer = new Timer(1000, 5);
// designates listeners for the interval and completion events
minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE,
onTimerComplete);
// starts the timer ticking
minuteTimer.start();
}
public function onTick(evt:TimerEvent):void
{
// displays the tick count so far
// The target of this event is the Timer instance itself.
trace("tick " + evt.target.currentCount);
}
public function onTimerComplete(evt:TimerEvent):void
{
trace("Time's Up!");
}
}
}
When the ShortTimer class is created, it creates a Timer instance that will tick once per
second for five seconds. Then it adds two listeners to the timer: one that listens to each tick,
and one that listens for the
Next, it starts the timer ticking, and from that point forward, the
at one-second intervals.
The
method simply displays the current tick count. After five seconds have passed,
onTick()
the
onTimerComplete()
202
Working with Dates and Times
event.
timerComplete
method executes, telling you that the time is up.
method executes
onTick()

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents