Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 366

Programming actionscript 3.0
Table of Contents

Advertisement

Providing notification when something happens is the job that events are made for. The
AlarmClock class exposes the Alarm event, which other objects can listen for in order to
perform desired actions. In addition, the AlarmClock class uses an instance of the Timer class
to determine when to trigger its alarm. Like the AlarmClock class, the Timer class provides an
event to notify other objects (an AlarmClock instance, in this case) when a certain amount of
time has passed. As with most ActionScript applications, events form an important part of the
functionality of the Alarm Clock example application.
Triggering the alarm
As mentioned previously, the only functionality that the AlarmClock class actually provides
relates to setting and triggering the alarm. The built-in Timer class (flash.utils.Timer)
provides a way for a developer to define code that will be executed after a specified amount of
time. The AlarmClock class uses a Timer instance to determine when to set off the alarm.
import flash.events.TimerEvent;
import flash.utils.Timer;
/**
* The Timer that will be used for the alarm.
*/
public var alarmTimer:Timer;
...
/**
* Instantiates a new AlarmClock of a given size.
*/
public override function initClock(faceSize:Number = 200):void
{
super.initClock(faceSize);
alarmTimer = new Timer(0, 1);
alarmTimer.addEventListener(TimerEvent.TIMER, onAlarm);
}
366
Handling Events

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents