Get and Set Functions
ActionScript has support for special get and set functions that can encapsulate property access behind function calls, but without changing the property access syntax.
Before further explanation, let's see an example of a property exposed via get/set functions:
public class Person { private var _name:String; public function get name():String { return this.name; } public function set name( value:String ):void { this.name = value; } }
Note the extra get and set keywords in the function declarations.
This tells ActionScript that the functions are for property access.
While the code looks quite different than just using a public property,
the usage is exactly the same.
The above code is analogous to the below code:
public class Person { public var name:String; }
Both examples of code, a public property and get/set functions, can be used as followed:
person.name = "John"; var example:String = person.name; // returns "John"
The key point of get and set functions is that you can start with public properties and later move to get/set functions, if necessary, without changing how the class is used.
Another example, this time making a read-only property (just a get function):
public function get isReadOnly():Boolean { return true; }
Usage of a read-only property:
if( object.isReadyOnly ) // calls the get isReadyOnly() function { // do something } // will not work object.isReadOnly = false;

