798 Object-Oriented Programming with ActionScript 1.0
This step registers the symbol whose linkage identifier is theID with the class
myClipClass. All instances of myClipClass have event handler methods that behave as
defined in step 4. They also behave the same as all instances of the MovieClip class
because you told the new class to inherit from the class MovieClip in step 3.
The complete code is shown in the following example:
function myClipClass(){}
myClipClass.prototype = new MovieClip();
myClipClass.prototype.onLoad = function(){
trace("movie clip loaded");
}
myClipClass.prototype.onPress = function(){
trace("pressed");
}
myClipClass.prototype.onEnterFrame = function(){
trace("movie clip entered frame");
}
myClipClass.prototype.myfunction = function(){
trace("myfunction called");
}
Object.registerClass("myclipID",myClipClass);
this.attachMovie("myclipID","clipName",3);
Creating inheritance in ActionScript 1.0
Inheritance is a means of organizing, extending, and reusing functionality. Subclasses inherit
properties and methods from superclasses, and add their own specialized properties and
methods. For example, reflecting the real world, Bike would be a superclass and
MountainBike and Tricycle would be subclasses of the superclass. Both subclasses contain, or
inherit, the methods and properties of the superclass (for example,
wheels). Each subclass also
has its own properties and methods that extend the superclass (for example, the
MountainBike subclass would have a
gears property). You can use the elements prototype
and
__proto__ to create inheritance in ActionScript.
NOTE
Many Flash users can greatly benefit from using ActionScript 2.0, especially with
complex applications. For information on using ActionScript 2.0, see Chapter 7,
“Classes,” on page 225.