Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 132

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

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:
<?xml version="1.0"?>
<!-- as/myComponents/TextAreaDefaultPropMXML.mxml -->
<MyComp:TextAreaDefaultProp xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:defaultText>Hello</MyComp:defaultText>
</MyComp:TextAreaDefaultProp>
Making properties accessible in Flex Builder
You can make your property definitions accessible in Flex Builder by adding the
metadata tag to the property definition. For example, if you are using Adobe
[Inspectable]
Flex Builder, you can insert the
editable (or inspectable), as the following example shows:
[Inspectable]
var prop1:Number;
You can also use the
[Inspectable]
information, see
Chapter 5, "Using Metadata Tags in Custom Components," on page
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 following example shows a Text control that gets its data from a
property. The property name inside the curly braces ({ }) specifies a binding expression that
copies the value of the source property,
Text
control's
property.
text
<mx:Slider id="mySlider"/>
<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.
132
Creating Simple Visual Components in ActionScript
metadata tag to define the property as user-
[Inspectable]
metadata tag with setter and getter methods. For more
mySlider.value
Slider
control's
, into the destination property, the
45.
value

Advertisement

Table of Contents
loading

Table of Contents