User Guide
Table Of Contents
- Contents
- Working with Flash MX 2004
- Creating Basic Components in Flash MX 2004
- Creating Advanced Components in Flash MX 2004
- Contents
- About Creating components
- Writing the component’s ActionScript code
- Simple example of a class file
- General process for writing a class file
- Selecting a parent class
- Identifying the class, symbol, and owner names
- About the component instantiation life cycle
- Writing the constructor
- Specifying clip parameters
- Implementing the constructObject2() method
- Implementing the init() method
- Implementing the createChildren() method
- Implementing the commitProperties() method
- Implementing the measure() method
- Implementing the layoutChildren() method
- Implementing the draw() method
- Defining getters and setters
- Component metadata
- Defining component parameters
- Handling events
- Using the Event metadata
- About invalidation
- Skinning custom controls
- Adding styles
- Making components accessible
- Improving component usability
- Best practices when designing a component
- Using the ModalText example
- Troubleshooting
- Index

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 instance’s 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 superclass’s
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)