03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

trace(Circle.prototype == twoCircle.__proto__); // Output: true<br />

See also<br />

prototype (Object.prototype property)<br />

prototype (Object.prototype property)<br />

public static prototype : Object<br />

A reference to the superclass of a class or function object. The prototype property is<br />

automatically created <strong>and</strong> attached to any class or function object you create. This property is<br />

static in that it is specific to the class or function you create. For example, if you create a<br />

custom class, the value of the prototype property is shared by all instances of the class, <strong>and</strong> is<br />

accessible only as a class property. Instances of your custom class cannot directly access the<br />

prototype property, but can access it through the __proto__ property.<br />

Example<br />

The following example creates a class named Shape <strong>and</strong> a subclass of Shape named Circle.<br />

// Shape class defined in external file named Shape.as<br />

class Shape {<br />

function Shape() {}<br />

}<br />

// Circle class defined in external file named Circle.as<br />

class Circle extends Shape{<br />

function Circle() {}<br />

}<br />

The Circle class can be used to create two instances of Circle:<br />

var oneCircle:Circle = new Circle();<br />

var twoCircle:Circle = new Circle();<br />

The following trace statement shows that the prototype property of the Circle class points<br />

to its superclass Shape. The identifier Shape refers to the constructor function of the Shape<br />

class.<br />

trace(Circle.prototype.constructor == Shape); // Output: true<br />

The following trace statement shows how you can use the prototype property <strong>and</strong> the<br />

__proto__ property together to move two levels up the inheritance hierarchy (or prototype<br />

chain). The Circle.prototype.__proto__ property contains a reference to the superclass of<br />

the Shape class.<br />

trace(Circle.prototype.__proto__ == Shape.prototype); // Output: true<br />

Object 527

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!