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 51
The following example adds the symbolName, symbolOwner, and className properties to the
MyButton class:
class MyButton extends mx.controls.Button {
static var symbolName:String = "myPackage.MyButton";
static var symbolOwner = myPackage.MyButton;
var className:String = "MyButton";
...
}
About the component instantiation life cycle
When you instantiate a new component, Flex calls a number of methods, and those methods call
other methods that you can override. Instantiating a new control in your application triggers the
following method calls by Flex:
1.
Class constructor
After the class constructor is called, Flex calls the
constructObject2() method.
2.
The constructObject2() method
When you implement the
constructObject2() method, you must call the
super.constructObject2() method or make manual calls to the init() and
createChildren() methods.
3.
The init() method
Flex calls the
init() method from the parent class’s constructObject2() method.
4.
The createChildren() method
Flex calls the
createChildren() method from the parent class’s constructObject2()
method.
5.
The measure() method
Flex calls the
measure() method.
6.
The layoutChildren() method
Flex calls the
layoutChildren() method.
7.
The draw() method
Flex calls the
draw() method.
Each of the
measure(), layoutChildren(), and draw() methods has a corresponding invalidate
function. For more information, see “About invalidation” on page 68.
The remaining sections describe each of these methods. For the purposes of initialization, you do
not need to add any explicit calls to these methods, because Flex initiates each call. However, you
might be required to explicitly call some of these methods to refresh the object’s state after it has
been created and displayed.