Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 206

Programming actionscript 3.0
Table of Contents

Advertisement

Starting the timer
After creating the clock face, the
// creates a Timer that fires an event once per second
ticker = new Timer(1000);
// designates the onTick() method to handle Timer events
ticker.addEventListener(TimerEvent.TIMER, onTick);
// starts the clock ticking
ticker.start();
First this method instantiates a Timer instance that will dispatch an event once per second
(every 1000 milliseconds). Since no second
constructor, the Timer will keep repeating indefinitely.
The
SimpleClock.onTick()
received:
public function onTick(evt:TimerEvent):void
{
// updates the clock display
face.draw();
}
The
AnalogClockFace.draw()
Displaying the current time
Most of the code in the AnalogClockFace class involves setting up the clock face's display
elements. When the AnalogClockFace is initialized, it draws a circular outline, places a
numeric text label at each hour mark, and then creates three Shape objects, one each for the
hour hand, the minute hand, and the second hand on the clock.
Once the SimpleClock application is running, it calls the
each second, as follows:
/**
* Called by the parent container when the display is being drawn.
*/
public override function draw():void
{
// stores the current date and time in an instance variable
currentTime = new Date();
showTime(currentTime);
}
206
Working with Dates and Times
method sets up a timer:
initClock()
repeatCount
method will execute once per second when the
method simply draws the clock face and hands.
parameter is passed to the
timer
AnalogClockFace.draw()
Timer()
event is
method

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents