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 53
When it instantiates the component, the Flex framework creates an initialization object ({foo:
"myvalue"}
) and passes it to the constructObject2() method. The constructObject2()
method sets this property.
Clip parameters can take any number of comma-separated arguments. Flex stores the clip
parameters as an array. Every argument in the clip parameter definition must have a “:1” after it in
order for Flex to let you use it.
The following example creates the clip parameters
text, html, and autoSize, and then calls the
applyProperties() method from within the constructObject2() method:
var clipParameters:Object = { text: 1, html: 1, autoSize: 1};
function constructObject2(obj:Object):Void {
...
applyProperties(obj, Label.prototype.clipParameters);
}
The applyProperties() method has the following signature:
applyProperties(Object, Object):Void
Thus, when you have a component like the following:
class MyComponent extends UIComponent {
...
private var clipParameters:Object = {someProperty: 1};
private static var mergedClipParameters =
mx.core.UIObject.mergeClipParameters(MyComponent.prototype.
clipParameters,UIComponent.prototype.clipParameters);
public var someProperty:String;
...
}
You can do this:
function constuctObject2(initObj:Object) {
super.constructObject2(initObj);
this.applyProperties(initObj, clipParameters);
}
This example uses the bracket notation to get around type-checking. If it runs in Flash, the
constructObject2() method is never called and UIObject.init takes care of all property
initialization. If it runs in Flex, it calls the
constructObject2() method and this function
applies properties as required.
You can dynamically create a list of clip parameters using the
mergeClipParameters() method.
This method creates the list of clip parameters using ActionScript shorthand; for example:
static function mergeClipParameters(obj, par):Boolean {
for (var i in par) {
obj[i] = par[i];
}
return true;
}