
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Classes and Object-Oriented Programming
|
299
The end of the inheritance chain
All objects descend from the top-level Object class. Hence, all objects inherit the prop-
erties defined in the Object constructor (for example, the toString( ) and valueOf( )
methods). We can, therefore, add new properties to every object in a movie by add-
ing new properties to the Object class. Properties attached to
Object.prototype will
proliferate throughout the entire class hierarchy, including all built-in objects, such as
Array, TextField, and even MovieClip objects. This approach can be used to make a
sort of global variable or function. In the following code, for example, we hardcode
the Stage width and height dimensions into the Object class
prototype. We can then
access that information from any movie clip (this technique was common in Flash 5
movies, although in Flash Player 6, the Stage dimensions are available as
Stage.width
and Stage.height):
Object.prototype.mainstageWidth = 550;
Object.prototype.mainstageHeight = 400;
trace(anyClip.mainstageWidth); // Displays: 550
Object.prototype properties are inherited not only by movie clips, but also by every
object, so even our own custom objects and instances of built-in classes such as
XML, Date, and Sound inherit properties assigned to
Object.prototype ...