Using ActionScript 2.0 Components |
|
|
|
| Creating Components > Creating the ActionScript class file > Adding component metadata > About the Bindable tag | |||
Data binding connects components to each other. You achieve visual data binding through the Bindings tab of the Component inspector. From there, you add, view, and remove bindings for a component.
Although data binding works with any component, its main purpose is to connect user interface components to external data sources, such as web services and XML documents. These data sources are available as components with properties, which you can bind to other component properties.
Use the Bindable tag before a property in an ActionScript class to make the property appear in the Bindings tab in the Component inspector. You can declare a property by using var or getter/setter methods. If a property has both a getter and a setter method, you only need to apply the Bindable tag to one.
The Bindable tag has the following syntax:
[Bindable "readonly"|"writeonly",type="datatype"]
Both attributes are optional.
The following example defines the variable flavorStr as a property that is accessible on the Bindings tab of the Component inspector:
[Bindable] public var flavorStr:String = "strawberry";
The Bindable tag takes three options that specify the type of access to the property, as well as the data type of that property. The following table describes these options:
|
Option |
Description |
|---|---|
readonly
|
Indicates that when you create bindings in the Component inspector, you can only create bindings that use this property as a source. However, if you use ActionScript to create bindings, there is no such restriction. [Bindable("readonly")]
|
writeonly
|
Indicates that when you create bindings in the Component inspector, this property can only be used as the destination of a binding. However, if you use ActionScript to create bindings, there is no such restriction. [Bindable("writeonly")]
|
|
Indicates the type that data binding uses for the property. The rest of Flash uses the declared type. If you do not specify this option, data binding uses the property's data type as declared in the ActionScript code. In the following example, data binding will treat |
All properties of all components can participate in data binding. The Bindable tag merely controls which of those properties are available for binding in the Component inspector. If a property is not preceded by the Bindable tag, you can still use it for data binding, but you have to create the bindings using ActionScript.
The Bindable tag is required when you use the ChangeEvent tag. For more information, see About the ChangeEvent tag.
For information on creating data binding in the Flash authoring environment, see "Data binding" in Using Flash.
|
|
|
|