Macromedia flex 2 Manuale

Pagina di 254
Adding properties and methods to a component
133
For example, in the section 
created a class with the public property 
maxFontSize
. You can use the 
maxFontSize
 property 
as the destination of a binding expression, as the following example shows:
<?xml version="1.0"?> 
<!-- as/MainTextAreaFontControlBindingDest.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:MyComp="myComponents.*" >
    <MyComp:TextAreaFontControl id="myTA" 
        maxFontSize="{Number(myTI.text)}"/>
    <mx:Label text="Enter max font size."/>
    <mx:TextInput id="myTI" text="25"/>
</mx:Application>
In this example, any value that the user enters into the 
TextInput
 control is automatically 
copied to the 
maxFontSize
 property.
Using properties as the source of a data binding expression
When a property is the source of a data binding expression, Flex automatically copies the 
value of the source property to any destination property when the source property changes. 
However, in order to signal to Flex to perform the copy, you must register the property with 
Flex and the source property must dispatch an event. 
To register a property as a source for data bindings, you use the 
[Bindable]
 metadata tag. 
You can use this tag in three places:
Before a class definition to make all public properties defined as variables or by using setter 
and getter methods usable as the source of a binding expression
Before a property that a variable defines to make that specific property support binding
Before a getter method for a property implemented by using setter and getter methods
For more information on the 
[Bindable]
 metadata tag, see 
NO
TE
When you use the 
[Bindable]
 metadata tag before a public class definition, it only 
applies to public properties; it does not apply to private or protected properties, or to 
properties defined in any other namespace. You must insert the 
[Bindable]
 metadata 
tag before a nonpublic property to make it usable as the source for a data binding 
expression.