User Guide
204 Working with Dates and Times
Example: Simple analog clock
A simple analog clock example illustrates two of the date and time concepts discussed in this
chapter:
■ Getting the current date and time and extracting values for the hours, minutes, and
seconds
■ Using a Timer to set the pace of an application
The SimpleClock application files can be found in the folder Samples/SimpleClock. The
application consists of the following files:
Defining the SimpleClock class
The clock example is simple, but it’s a good idea to organize even simple applications well so
you could easily expand them in the future. To that end, the SimpleClock application uses the
SimpleClock class to handle the startup and time-keeping tasks, and then uses another class
named AnalogClockFace to actually display the time.
Here is the code that defines and initializes the SimpleClock class:
public class SimpleClock extends UIComponent
{
/**
* The time display component.
*/
private var face:AnalogClockFace;
/**
* The Timer that acts like a heartbeat for the application.
*/
private var ticker:Timer;
File Description
SimpleClockApp.mxml The main application file in MXML for Flex.
SimpleClockApp.fla The main application file as a FLA file for the
Flash authoring tool.
com/example/programmingas3/
simpleclock/SimpleClock.as
The main application file.
com/example/programmingas3/
simpleclock/AnalogClockFace.as
Draws a round clock face and hour, minute, and
seconds hands based on the time.