MACROMEDIA FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manuale Utente Pagina 108

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 184
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 107
108 Binding
The following is a Flex 2 example of a getter/setter pair that uses the [Bindable] metadata
tag:
// 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);
}
You can omit the event name in the metadata tag, as the following example shows:
// Define private variable.
private var _maxFontSize:Number = 15;
[Bindable]
// 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;
}
The Flex compiler automatically generates an event named propertyChange. In this case,
specifying the
[Bindable] metadata tag with no event is the same as specifying the following:
[Bindable(event="propertyChange")]
Vedere la pagina 107
1 2 ... 103 104 105 106 107 108 109 110 111 112 113 ... 183 184

Commenti su questo manuale

Nessun commento