Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 99

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

Advertisement

Supporting data binding in custom properties
The Flex data binding mechanism provides a syntax for automatically copying the value of a
property of one object to a property of another object at run time. The following example
shows a
Text
control that gets its data from
name inside the curly braces ({ }) is a binding expression that copies the value of the source
property,
mySlider.value
the following example shows:
<mx:Slider id="mySlider"/>
<mx:Text text="{mySlider.value}"/>
Data binding is usually triggered whenever the value of the source property changes.
Properties that you define in your custom controls can also take advantage of data binding.
You can automatically use any property defined by using an MXML tag, such as
, and any ActionScript property defined as a variable or defined by using setter
<mx:Boolean>
and getter methods as the destination of a binding expression.
For example,
"Defining properties by using setters and getters" on page 96
property of StateComboBoxGetSet.mxml by using setter and getter methods.
shortNames
With no modification to that component, you can use
binding expression, as the following example shows:
<MyComp:StateComboBoxSetGet shortNames="{some_prop}"/>
However, you can also write your component to use the
a binding expression, as the following example shows for the nex component
StateComboBoxGetSetBinding.mxml:
<?xml version="1.0"?>
<!-- mxmlAdvanced/MainPropSetGetBinding.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:StateComboBoxSetGetBinding id="myStateCB" shortNames="false"/>
<mx:TextArea text="The value of shortNames is {myStateCB.shortNames}"/>
<mx:Button click="myStateCB.shortNames=!myStateCB.shortNames;"/>
</mx:Application>
Slider
, to the destination property, the Text control's
Adding custom properties and methods to a component
control's
property. The property
value
as the destination of a
shortNames
property as the source of
shortNames
property, as
text
defined the
99

Advertisement

Table of Contents
loading

Table of Contents