User Guide

Advanced topics 141
The Shape class and the Circle class are now linked together in an inheritance relationship
that is commonly known as the prototype chain. The diagram illustrates the relationships in a
prototype chain:
The base class at the end of every prototype chain is the Object class. The Object class
contains a static property named
Object.prototype that points to the base prototype object
for all objects created in ActionScript 1.0. The next object in our example prototype chain is
the Shape object. This is because the
Shape.prototype property was never explicitly set, so it
still holds a generic object (an instance of the Object class). The final link in this chain is the
Circle class, which is linked to its prototype, the Shape class (the
Circle.prototype property
holds a Shape object).
If we create an instance of the Circle class, as in the following example, the instance inherits
the prototype chain of the Circle class:
// Create an instance of the Circle class.
myCircle = new Circle();
Recall that we created a property named visible as a member of the Shape class. In our
example, the
visible property does not exist as a part of the myCircle object, only as a
member of the Shape object, yet the following line of code outputs
true:
trace(myCircle.visible); // true
Flash Player is able to ascertain that the myCircle object inherits the visible property by
walking up the prototype chain. When executing this code, Flash Player first searches through
the properties of the
myCircle object for a property named visible, but does not find such
a property. Flash Player looks next in the
Circle.prototype object, but still does not find a
property named
visible. Continuing up the prototype chain, Flash Player finally finds the
visible property defined on the Shape.prototype object and outputs the value of that
property.
In the interest of simplicity, this section omits many of the details and intricacies of the
prototype chain, and aims instead to provide enough information to help you understand the
ActionScript 3.0 object model.
Object.prototype
Shape.prototype
Circle.prototype