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 47
Simple example of a class file
The following is a simple example of a class file called MyComponent.as. If you were creating this
component, you would link this file to the component in the Flash IDE.
This example contains a minimal set of imports, methods, and declarations for a component that
inherits from the UIObject class.
//Import packages.
import mx.core.UIObject;
//Declare the class and extend from the parent class.
class myPackage.MyComponent extends UIObject {
// Identify the symbol name that this class is bound to.
static var symbolName:String = "myPackage.MyComponent";
// Identify the fully qualified package name of the symbol owner.
static var symbolOwner:Object = Object(myPackage.MyComponent);
// Provide the className variable.
var className:String = "MyComponent";
// Define an empty constructor.
function MyComponent() {
}
// Override the init method, and call the parent’s init method.
function init(Void):Void {
super.init();
// Call invalidate() to display graphics.
invalidate();
}
}
General process for writing a class file
Use the following general process when you write a component’s ActionScript class file.
Depending on the type of component that you create, whether you override any of the superclass’s
methods is optional. For the simplest form of component, you are not required to implement any
of these methods.
To write the ActionScript file for a component:
1.
Select and extend a parent class.
2.
Define the symbolName, symbolOwner, and className properties.
3.
Write an empty class constructor.
4.
Specify properties that can be set using an MXML tag property (clip parameters).
5.
Implement the constructObject2() method.
6.
Implement the init() method.