User Guide

Using ActionScript 31
To define getter and setter methods, precede the method name with the keyword get or set,
followed by a space and the property name. The following example shows the declaration of a
public property named
initialCount, and the getter and setter methods that get and set the
value of this property:
// Define internal private variable.
private var _initialCount:uint = 42;
// Define public getter.
public function get initialCount():uint {
return _initialCount;
}
// Define public setter.
public function set initialCount(value:uint):void {
_initialCount = value;
}
By convention, setters use the identifier value for the name of the argument.
The variable that stores the property’s value cannot have the same name as the getter or setter.
By convention, precede the name of the variables with one (_) or two underscores (__). In
addition, Adobe recommends that you declare the variable as private or protected.
Users of the class can access the public property as the following example shows:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myControls.*" >
<MyComp:MyButton label="Submit" initialCount="24"/>
</mx:Application>
If the getter or setter overrides a getter or setter in a superclass, ensure that you include the
override keyword, as the following example shows:
override public function get label():String {}
override public function set label(value:String):void {}