Macromedia flex 2 Manuale

Pagina di 254
Metadata tags
53
You can specify the event name, as the following example shows:
[Bindable(event="changeShortNames")]
public function set shortNames(val:Boolean):void {
...
// Create and dispatch event. 
dispatchEvent(new Event("changeShortNames"));
}
// Get method. 
public function get shortNames():Boolean {
...
}
In this case, you are responsible for generating and dispatching the event, typically in the 
setter method. You can specify a 
[Bindable]
 tag that includes the 
event
 specification to 
name the event, even when you already specified the 
[Bindable]
 tag at the class level. 
The following example makes the 
maxFontSize
 and 
minFontSize
 properties that you 
defined as variables that can be used as the sources for data bindings:
// Define public vars for tracking font size.
[Bindable]
public var maxFontSize:Number = 15;
[Bindable]
public var minFontSize:Number = 5;
In the following example, you make a public property that you defined by using a setter and a 
getter method that is usable as the source for data binding The 
[Bindable]
 metadata tag 
includes the name of the event broadcast by the setter method when the property changes:
// Define private variable.
private var _maxFontSize:Number = 15;
[Bindable(event="maxFontSizeChanged")]
// Define public getter method.
public function get maxFontSize():Number {
return _maxFontSize;
}
// Define public setter method.
public function set maxFontSize(value:Number):void {
if (value <= 30) {
_maxFontSize = value;
} else _maxFontSize = 30;
// Create event object. 
var eventObj:Event = new Event("maxFontSizeChanged");
dispatchEvent(eventObj);
}