User Guide

About ActionScript 1 327
This new class is assigned to all instances of the movie clip that are added to the application by
the Timeline or that are added to the application with the
attachMovie() or
duplicateMovieClip() method. If you want these movie clips to have access to the methods
and properties of the built-in MovieClip object, you need to make the new class inherit from
the MovieClip class.
3.
Enter code, such as the following example:
// inherit from MovieClip class
myClipClass.prototype = new MovieClip();
Now, the class myClipClass inherits all the properties and methods of the MovieClip class.
4.
Enter code, such as the following example, to define the event handler methods for the new
class:
// define event handler methods for myClipClass class
myClipClass.prototype.onLoad = function() {trace ("movie clip loaded");}
myClipClass.prototype.onEnterFrame = function() {trace ("movie clip entered
frame");}
5.
Select Window > Library to open the Library panel if it isn’t already open.
6.
Select the symbols that you want to associate with your new class, and select Linkage from the
Library panel options menu.
7.
In the Linkage Properties dialog box, select Export for ActionScript.
8.
Enter an identifier in the Identifier text box.
The identifier must be the same for all symbols that you want to associate with the new class.
In the
myClipClass example, the identifier is theID.
9.
Enter code, such as the following example, in the Script pane:
// register class
Object.registerClass("theID", myClipClass);
this.attachMovie("theID","myName",1);
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");
}