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

Writing the component’s ActionScript code 55
The following table describes the arguments:
To call t h e
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:
up_mc.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:
form.createClassObject(CheckBox, "cb", 0, {label:"Check this"});
The following example creates TextInput and SimpleButton components:
function createChildren():Void {
if (text_mc == undefined)
createClassObject(TextInput, "text_mc", 0, { preferredWidth: 80,
editable:false });
text_mc.addEventListener("change", this);
text_mc.addEventListener("focusOut", this);
if (mode_mc == undefined)
createClassObject(SimpleButton, "mode_mc", 1, { falseUpSkin:
modeUpSkinName, falseOverSkin: modeOverSkinName, falseDownSkin:
modeDownSkinName });
mode_mc.addEventListener("click", this);
}
If your component is a container, and you do not know exactly which children it contains, call the
createComponents() method. This method creates all child objects. For more information on
using the
createComponents() method, see Developing Flex Applications.
At the end of the
createChildren() method, call the necessary invalidate methods
(
invalidate(), invalidateSize(), or invalidateLayout()) to refresh the screen. For more
information, see “About invalidation” on page 68.
Implementing the commitProperties() method
Flex calls the
commitProperties() method before it calls the measure() method. It provides a
chance to set variables that are used by the
measure() method after the constructor has finished
and MXML attributes have been applied.
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.