Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > Object > prototype (Object.prototype property) | |||
public static prototype : Object
A reference to the superclass of a class or function object. The prototype property is automatically created and attached to any class or function object you create. This property is static in that it is specific to the class or function you create. For example, if you create a custom class, the value of the prototype property is shared by all instances of the class, and is accessible only as a class property. Instances of your custom class cannot directly access the prototype property, but can access it through the __proto__ property.
Availability: ActionScript 1.0; Flash Player 6
The following example creates a class named Shape and a subclass of Shape named Circle.
// Shape class defined in external file named Shape.as
class Shape {
function Shape() {}
}
// Circle class defined in external file named Circle.as
class Circle extends Shape{
function Circle() {}
}
The Circle class can be used to create two instances of Circle:
var oneCircle:Circle = new Circle(); var twoCircle:Circle = new Circle();
The following trace statement shows that the prototype property of the Circle class points to its superclass Shape. The identifier Shape refers to the constructor function of the Shape class.
trace(Circle.prototype.constructor == Shape); // Output: true
The following trace statement shows how you can use the prototype property and the __proto__ property together to move two levels up the inheritance hierarchy (or prototype chain). The Circle.prototype.__proto__ property contains a reference to the superclass of the Shape class.
trace(Circle.prototype.__proto__ == Shape.prototype); // Output: true
__proto__ (Object.__proto__ property)
Version 8
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/8/main/00002586.html
Comments
William_Donelson said on Mar 17, 2006 at 12:45 AM :