MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 799

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

All constructor functions have a
function is defined. The
created with that function. You can use the
methods to a class. (For more information, see
ActionScript 1.0" on page
All instances of a class have a
inherit. When you use a constructor function to create an object, the
set to refer to the
prototype
Inheritance proceeds according to a definite hierarchy. When you call an object's property or
method, ActionScript looks at the object to see if such an element exists. If it doesn't exist,
ActionScript looks at the object's
(
myObject.__proto__
ActionScript looks at
The following example defines the constructor function
function Bike(length, color) {
this.length = length;
this.color = color;
this.pos = 0;
}
The following code adds the
Bike.prototype.roll = function() {return this.pos += 20;};
Then, you can trace the position of the bike with the following code:
var myBike = new Bike(55, "blue");
trace(myBike.roll());
trace(myBike.roll());
Instead of adding
roll()
MountainBike class with Bike as its superclass, as shown in the following example:
MountainBike.prototype = new Bike();
Now you can call the
var myKona = new MountainBike(20, "teal");
trace(myKona.roll());
Movie clips do not inherit from each other. To create inheritance with movie clips, you can
use
Object.registerClass()
prototype
property indicates the default property values for objects
prototype
795.)
property that tells you the object from which they
__proto__
property of its constructor function.
__proto__
). If the property is not a property of the object's
myObject.__proto__.__proto__
method to the Bike class:
roll()
// traces 20.
// traces 40.
to the MountainBike class and the Tricycle class, you can create the
method of MountainBike, as shown in the following example:
roll()
// traces 20
to assign a class other than the MovieClip class to movie clips.
property that is created automatically when the
property to assign properties and
prototype
"Assigning methods to a custom object in
property for the information
, and so on.
:
Bike()
Creating inheritance in ActionScript 1.0
property is
__proto__
object,
__proto__
799

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents