User Guide

About creating advanced components 151
The following example creates a Button control in ActionScript and adds it to a container:
// Create a Box container.
var boxContainer:Box = new Box();
// Configure the Box container.
// Create a Button control.
var b:Button = new Button()
// Configure the button control.
b.label = "Submit";
...
// Add the Button control to the Box container.
boxContainer.addChild(b);
The following steps show what occurs when you execute the code to create the Button
control, and add the control to the Box container:
1. You call the component’s constructor, as the following code shows:
// Create a Button control.
var b:Button = new Button()
2.
You configure the component by setting its properties, as the following code shows:
// Configure the button control.
b.label = "Submit";
Component setter methods might call the invalidateProperties(),
invalidateSize(), or invalidateDisplayList() methods.
3. You call the addChild() method to add the component to its parent, as the following code
shows:
// Add the Button control to the Box container.
boxContainer.addChild(b);
Flex performs the following actions:
a. Sets the parent property for the component to reference its parent container.
b. Computes the style settings for the component.
c. Dispatches the preinitialize event on the component.
d. Calls the component’s createChildren() method.
e. Calls the invalidateProperties(), invalidateSize(), and
invalidateDisplayList() methods to trigger later calls to the
commitProperties(), measure(), or updateDisplayList() methods during the
next
render event.
The only exception to this rule is that Flex does not call the
measure() method when
the user sets the height and width of the component.