We've created our Ball class constructor, and we have seen how to instantiate Ball objects with attachMovie( ). Now we have to make our Ball class a subclass of the MovieClip class. As we saw in Chapter 12, we declare a class's superclass like this:
SubClass.prototype = new SuperClass( );
Hence, it comes as no surprise that we declare MovieClip as Ball's superclass like this:
/* * Set MovieClip as Ball's superclass. */ org.moock.Ball.prototype = new MovieClip( );
However, although we've defined Ball as a subclass of MovieClip, we still need to tell the interpreter to execute the Ball constructor when we create a new instance of our exported ballSymbol from the Library. To associate an exported symbol with the desired class constructor, we use Object.registerClass( ). Here we associate ballSymbol with the Ball class:
/* * Associate the Library's ballSymbol with the Ball class. */ Object.registerClass("ballSymbol", org.moock.Ball);
In plain English, this tells the interpreter, "when a ballSymbol instance is created, invoke the org.moock.Ball( ) constructor, with the this keyword pointing to the new ballSymbol instance."
|
For more information on Object.registerClass( ), see the ActionScript Language Reference.