ActionScript 3 Language Specification |
|||
| ActionScript 3.0 Language Specification > 1 Tutorial introduction > 1.6 Classes | |||
A class is an object that can be used as a constructor of instances that share the same type and properties. An example of a class follows:
class Greeter {
var saying = "hello, world"
function hello() {
trace(saying)
}
}
var greeter : Greeter = new Greeter
greeter.hello()
Class definitions are used to define the fixed properties of a class object. Property definitions that are marked with the static attribute become properties of the class object, and those that are not become properties of instances of the class.
Class and instance properties are either methods or slots. A method is defined by a function definition inside a class definition. A method has a definition (called a method trait) that is shared among all instances of the same type. Unlike an ordinary function object, a method is tightly bound to the object it is associated with. Whenever and however it gets invoked, the meaning of the expression this is always the same. In fact, methods can be extracted from their instance and treated as first class objects (called bound methods), much like function objects can be. There is one important difference between a function closure and a bound method. With a bound method, the this reference is bound into the object so that whenever it is invoked the original this reference is used. With a function closure, this is generic and refers to any object the function happens to be associated with when it is invoked.
Slots are defined by variable definitions inside a class definition. An instance variable has a definition (called a slot trait) that is shared among all instances of the same type, but a unique location in each object.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification8.html
Comments
robertpaquette said on Nov 20, 2006 at 12:50 PM :