Macromedia flex 2 Manual
132
Creating Simple Visual Components in ActionScript
The one place where Flex prohibits the use of a default property is when you use the
ActionScript class as the root tag of an MXML component. In this situation, you must use
child tags to define the property, as the following example shows:
ActionScript class as the root tag of an MXML component. In this situation, you must use
child tags to define the property, as the following example shows:
<?xml version="1.0"?>
<!-- as/myComponents/TextAreaDefaultPropMXML.mxml -->
<MyComp:TextAreaDefaultProp xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<!-- as/myComponents/TextAreaDefaultPropMXML.mxml -->
<MyComp:TextAreaDefaultProp xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:defaultText>Hello</MyComp:defaultText>
</MyComp:TextAreaDefaultProp>
</MyComp:TextAreaDefaultProp>
Making properties accessible in Flex Builder
You can make your property definitions accessible in Flex Builder by adding the
[Inspectable]
metadata tag to the property definition. For example, if you are using Adobe
Flex Builder, you can insert the
[Inspectable]
metadata tag to define the property as user-
editable (or inspectable), as the following example shows:
[Inspectable]
var prop1:Number;
var prop1:Number;
You can also use the
[Inspectable]
metadata tag with setter and getter methods. For more
information, see
.
Using data binding with custom properties
Data binding defines a syntax for automatically copying the value of a property of one object,
the source property, to a property of another object, the destination property, at run time. Data
binding is usually triggered when the value of the source property changes.
the source property, to a property of another object, the destination property, at run time. Data
binding is usually triggered when the value of the source property changes.
The following example shows a Text control that gets its data from a
Slider
control’s
value
property. The property name inside the curly braces ({ }) specifies a binding expression that
copies the value of the source property,
copies the value of the source property,
mySlider.value
, into the destination property, the
Text
control’s
text
property.
<mx:Slider id="mySlider"/>
<mx:Text text="{mySlider.value}"/>
<mx:Text text="{mySlider.value}"/>
Using properties as the destination of a binding expression
Properties in your custom components can take advantage of data binding. Any property
defined as a variable or defined by using a setter and getter method can automatically be used
as the destination of a binding expression.
defined as a variable or defined by using a setter and getter method can automatically be used
as the destination of a binding expression.