AS1 OOP: Custom Classes with MovieClips
         by senocular  

MovieClip Constructors
When a movieclip symbol is setup to be created as an alternative class instance with Object.registerClass, even though a movieclip instance isn’t created with a call to the constructor function of that class, the constructor function still gets run for that movieclip instance when its made. So don’t pass off your class constructor as useless for classes used to extend movieclip instances. They still get run like any other objects enabling you to define properties etc. as you please. Consider the following example:

EnhancedClip = function(){
this.abilities = "enhanced";
};
EnhancedClip.prototype = new MovieClip();
Object.registerClass("libraryItemA", EnhancedClip);

 
this.attachMovie("libraryItemA", "myEnhanced_mc", 1);
trace(myEnhanced_mc.constructor == EnhancedClip); // traces true
trace(myEnhanced_mc.abilities); // traces "enhanced"

(Note that super wasn’t used, and isn’t needed, to add default movieclip properties to the movieclip instance created. Setting up the inheritance with class.prototype = new MovieClip() is all you need to take care of that).

 

Prev Page
 



SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.