Macromedia flex 2 Manual

Page of 254
Implementing the component
157
Implementing the constructor
Your ActionScript class should define a public constructor method for a class that is a subclass 
of the UIComponent class, or a subclass of any child of the 
UIComponent
 class. The 
constructor has the following characteristics:
No return type
Should be declared public
No arguments
Calls the 
super()
 method to invoke the superclass’s constructor
Each class can contain only one constructor method; ActionScript does not support 
overloaded constructor methods. For more information, see 
Use the constructor to set the initial values of class properties. For example, you can set 
default values for properties and styles, or initialize data structures, such as Arrays. 
Do not create child display objects in the constructor; you should use it only for setting initial 
properties of the component. If your component creates child components, create them in the 
createChildren()
 method. 
Implementing the createChildren() method
A component that creates other components or visual objects within it is called a composite 
component
. For example, the Flex 
ComboBox
 control contains a 
TextInput
 control to define 
the text area of the ComboBox, and a 
Button
 control to define the ComboBox arrow. 
Components implement the 
createChildren()
 method to create child objects (such as 
other components) in the component.
You do not call the 
createChildren()
 method directly; Flex calls it when the call to the 
addChild()
 method occurs to add the component to its parent. Notice that the 
createChildren()
 method has no invalidation method, which means that you do not have 
to call it a second time after the component is added to its parent. 
For example, you might define a new component that consists of a Button control and a 
TextArea control, where the Button control enables and disables user input to the TextArea 
control. The following example creates the TextArea and Button controls:
// Declare two variables for the component children.
private var text_mc:TextArea;
private var mode_mc:Button;
override protected function createChildren():void {