![MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual Download Page 9](http://html1.mh-extra.com/html/macromedia/flex-creating-advanced-components/flex-creating-advanced-components_manual_3385290009.webp)
Writing the component’s ActionScript code
9
Each class can contain only one constructor method; overloaded constructor methods are not
supported in ActionScript 2.0.
Implementing the init() method
Flash calls the
init()
method when the class is created. At a minimum, the
init()
method
should call the superclass’s
init()
method. The
width
and
height
of the component are not set
until after this method is called.
function init(Void):Void {
super.init();
invalidate();
}
Note:
Do not create child objects in the
init()
method.
You
should use it only for setting up initial
properties.
This
init()
method calls the
invalidate()
method. The
invalidate()
method signals to Flex
that just the visuals for the object have changed, but the size and position of subobjects have not
changed. The
invalidate()
method calls the
draw()
method.
Implementing the createChildren() method
Components implement the
createChildren()
method to create subobjects (such as other
components) in the component. Rather than calling the subobject’s constructor in the
createChildren()
method, you call the
createClassObject()
method to instantiate a
subobject of your component.
The
createClassObject()
method has the following signature:
createClassObject(
className
,
instanceName
,
depth
,
initObject
)
The following table describes the arguments:
To call the
createClassObject()
method, you must know what those children are (for example,
a border or a button that you always need), because you must specify the name and type of the
object, plus any initialization parameters in the call to
createClassObject()
.
The following example calls the
createClassObject()
method to create a new Label object for
use inside a component:
createClassObject(Label, "label_mc", 1); // Create a label in the holder
You set properties in the call to the
createClassObject()
method by adding them as part of the
initObject
argument. The following example sets the value of the
label
property:
createClassObject(CheckBox, "cb", 0, {label:"Check this"});
You can also pass style properties within the
initObj
argument, as the following example shows:
createClassObject(CheckBox, "cb", 0, {label:"Check this",
fontSize : 14
});
Argument
Type
Description
className
Object
The name of the class.
instanceName
String
The name of the instance.
depth
Number
The depth for the instance.
initObject
Object
The object that contains the initialization properties.
Summary of Contents for FLEX-CREATING ADVANCED COMPONENTS
Page 1: ...Creating Advanced Components...
Page 4: ...4 Contents...