13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Handling ev<strong>en</strong>ts<br />

File Description<br />

AlarmClockApp.mxml<br />

or<br />

AlarmClockApp.fla<br />

Alarm Clock overview<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The primary functionality of the clock in this example, including tracking the time and displaying the clock face, reuses<br />

the SimpleClock application code, which is described in “Date and time example: Simple analog clock” on page 6. The<br />

AlarmClock class ext<strong>en</strong>ds the SimpleClock class from that example by adding the functionality required for an alarm<br />

clock, including setting the alarm time and providing notification wh<strong>en</strong> the alarm “goes off.”<br />

Providing notification wh<strong>en</strong> something happ<strong>en</strong>s is the job that ev<strong>en</strong>ts are made for. The AlarmClock class exposes the<br />

Alarm ev<strong>en</strong>t, which other objects can list<strong>en</strong> for in order to perform desired actions. In addition, the AlarmClock class<br />

uses an instance of the Timer class to determine wh<strong>en</strong> to trigger its alarm. Like the AlarmClock class, the Timer class<br />

provides an ev<strong>en</strong>t to notify other objects (an AlarmClock instance, in this case) wh<strong>en</strong> a certain amount of time has<br />

passed. As with most ActionScript applications, ev<strong>en</strong>ts form an important part of the functionality of the Alarm Clock<br />

sample application.<br />

Triggering the alarm<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The main application file in Flash (FLA) or Flex (MXML).<br />

com/example/programmingas3/clock/AlarmClock.as A class which ext<strong>en</strong>ds the SimpleClock class, adding alarm clock<br />

functionality.<br />

com/example/programmingas3/clock/AlarmEv<strong>en</strong>t.as A custom ev<strong>en</strong>t class (a subclass of flash.ev<strong>en</strong>ts.Ev<strong>en</strong>t) which serves as<br />

the ev<strong>en</strong>t object for the AlarmClock class’s alarm ev<strong>en</strong>t.<br />

com/example/programmingas3/clock/AnalogClockFace.as Draws a round clock face and hour, minute, and seconds hands based<br />

on the time (described in the SimpleClock example).<br />

com/example/programmingas3/clock/SimpleClock.as A clock interface compon<strong>en</strong>t with simple timekeeping functionality<br />

(described in the SimpleClock example).<br />

As m<strong>en</strong>tioned previously, the only functionality that the AlarmClock class actually provides relates to setting and<br />

triggering the alarm. The built-in Timer class (flash.utils.Timer) provides a way for a developer to define code that will<br />

be executed after a specified amount of time. The AlarmClock class uses a Timer instance to determine wh<strong>en</strong> to set off<br />

the alarm.<br />

Last updated 6/6/2012<br />

141

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!