User Guide

Table Of Contents
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;
}