9.6.4 Accessor methods

A method defined with the get or set keyword adds a get or set method trait to the instance or static traits of the defining class object. Accessor methods are called when the name of the accessor is used in a reference that reads or writes the value of that name.

class A 
{
    private var _x
    function get x() { return _x }
    function set x(v) { _x = v }
}
var a  = new A
a.x = 10       // calls set accessor of A
trace(a.x)     // traces 10, calls get accessor of A

Accessor methods are very similar in definition to regular methods. The differences are expressed by the following error conditions:

NOTE

 

Accessors may only be defined at the top level of a class. They must not be nested inside another method or defined outside of a class.


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification92.html