User Guide
Advanced topics 143
The ActionScript 3.0 class object
A common object-oriented programming paradigm, most commonly associated with Java and
C++, uses classes to define types of objects. Programming languages that adopt this paradigm
also tend to use classes to construct instances of the data type that the class defines.
ActionScript uses classes for both of these purposes, but its roots as a prototype-based
language add an interesting characteristic. ActionScript creates for each class definition a
special class object that allows sharing of both behavior and state. For many ActionScript
programmers, however, this distinction may have no practical coding implications.
ActionScript 3.0 is designed such that you can create sophisticated object-oriented
ActionScript applications without using, or even understanding, these special class objects.
For advanced programmers who want take advantage of class objects, this section discusses the
issues in depth.
The following diagram shows the structure of a class object that represents a simple class
named A that is defined with the statement
class A {}:
Each rectangle in the diagram represents an object. Each object in the diagram has a subscript
character A to represent that it belongs to class A. The class object (C
A
) contains references to
a number of other important objects. An instance traits object (T
A
) stores the instance
properties that are defined within a class definition. A class traits object (T
CA
) represents the
internal type of the class and stores the static properties defined by the class (the subscript
character C stands for “class”). The prototype object (P
A
) always refers to the class object to
which it was originally attached through the
constructor property.
T
CA
P
A
C
A
T
A
Class.prototype Object.prototype
delegate
constructor
delegate
prototype
type
traits