This section describes how to build a component using the analog clock as a guide. Follow along by opening the AnalogClock_Basic.as file from the sample ZIP file (see the Requirements section).
The structure of the file uses the following pattern:
Step 1.import mx.core.UIComponents;
[Style(…)]
[Event(…)]
class AnalogClock extends UIComponent
{
// data members (for example, properties)
function AnalogClock_Basic()
{
}
function init()
{
}
function createChildren() : Void
{
}
function measure() : Void
{
}
function layoutChildren() : Void
{
}
function draw() : Void
{
}
}
Here is a description of the code:
init() method, set your component’s initial properties. If your component contains scalar values, set them in their declarations. Create objects (such as Array) here.createChildren() method. If, for example, your component has a Label, create the label here. In the AnalogClock_Basic component, create several empty SWF files. At this time, however, the subcomponents exist, but they do not yet have any size.measure() method. If you specify a specific width and height for the component, the Flex framework does not call this method.layoutChildren() method. draw() method to draw the graphics, set fonts, change colors, and so forth.