User Guide
Adding properties and methods to a component 131
You can use the [DefaultProperty] metadata tag in your ActionScript component to define
a single default property, as the following example shows:
package myComponents
{
// as/myComponents/TextAreaDefaultProp.as
import mx.controls.TextArea;
// Define the default property.
[DefaultProperty("defaultText")]
public class TextAreaDefaultProp extends TextArea {
public function TextAreaDefaultProp()
{
super();
}
// Define a setter method to set the text property
// to the value of the default property.
public function set defaultText(value:String):void {
if (value!=null)
text=value;
}
public function get defaultText():String {
return text;
}
}
}
In this example, you add a new property to the TextArea control, called defaultProperty,
and specify it as the default property of the control. The setter method for
defaultProperty
just sets the value of the
text property of the control. You can then use the default property in
MXML, as the following example shows:
<?xml version="1.0"?>
<!-- as/MainTextAreaDefaultProp.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:TextAreaDefaultProp>Hello</MyComp:TextAreaDefaultProp>
</mx:Application>