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
constructor has the following characteristics:
No return type
■
Should be declared public
■
No arguments
■
Calls the
super()
■
Each class can contain only one constructor method; ActionScript does not support
overloaded constructor methods. For more information, see
constructor," on page
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
method.
createChildren()
Implementing the createChildren() method
A component that creates other components or visual objects within it is called a composite
component. For example, the Flex
the text area of the ComboBox, and a
Components implement the
other components) in the component.
You do not call the
createChildren()
method occurs to add the component to its parent. Notice that the
addChild()
method has no invalidation method, which means that you do not have
createChildren()
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 {
method to invoke the superclass's constructor
28.
ComboBox
Button
createChildren()
method directly; Flex calls it when the call to the
UIComponent
Chapter 3, "Defining the
control contains a
TextInput
control to define the ComboBox arrow.
method to create child objects (such as
Implementing the component
class. The
control to define
157
Need help?
Do you have a question about the FLEX 2 - CREATING AND EXTENDING COMPONENTS and is the answer not in the manual?
Questions and answers