User Guide

Table Of Contents
54 Chapter 3: Creating Advanced Components in Flash MX 2004
Implementing the constructObject2() method
The
constructObject2() method is effectively the constructor for your class. The
UIObject.constructObject2() method calls the init() and createChildren() methods. It
should apply any properties in the initObj that are needed by
init() and createChildren(),
and then call
super.constructObject2().
The
constructObject2() method has the following signature:
constructObject2(initObj:Object):Void
In addition, if you use clip parameters, you should add a call to the applyProperties() method
at the end of the
constructObject2() method; for example:
function constructObject2(o:Object):Void {
super.constructObject2(o);
applyProperties(o, Label.prototype.clipParameters);
}
If you override the constructObject2() method, you must at least call the
super.constructObject2() method.
The initObj contains all the component instances properties that are set in the MXML tag
(and stored as clip parameters). Flex creates this object implicitly during instantiation of the
component.
Implementing the init() method
Flash calls the
init() method when the class is created. At a minimum, the init() method
should call the superclasss
init() method. The width, height, and clip parameters are not
properly set until after this method is called.
function init(Void):Void {
super.init();
}
The implicit init object (initObj) contains everything passed in through the initObj argument to
the
createClassObject() method. You can access it in the init() method.
Note: Do not create child objects in the init() method. You should use it only for setting up initial
properties.
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, call the createClassObject() method to instantiate a subobject
of your component.
The
createClassObject() method has the following signature:
createClassObject(className, instanceName, depth, initObject)