MovieClip Inheritance Total Solution Experiment v1.08


Download the source file


This shows one way of utilizing Event Engines such as TK Event Engine, and Inheritance All-Rounder.
What's done here is make _level0 and all the dependent movieclips inherit from the classes defined for each all together. Multiple-level inheritance is supported too.
The following is a simple example swf file that demonstrates MovieClip Inheritance Total Solution.

 


- A movieclip called "holder", on _root, that has two single-frame movieclips "asterisk1" and "asterisk2" inside.
- A start/stop button, on _root, with the following code.

on(press) {
        onPress();
}

- TK Event Engine is placed on the stage. Inheritance All-Rounder written in frame 2.
- The following codes written after that.



////////////////////////// MovieClip Inheritance Total Solution 1.08 ////////////////////////////
//                                                                   Jan.24.2002 Tatsuo Kato
/////////////////////////////////////////////////////////////////////////////////////////////////

/*
Define classes with the same names as the movieclips.
And make them nested if needed so they form the same hierarchy as the movieclips'
in order to make it intuitive.
And then make each movieclip inherit from the class with the same name.
The classes can be inheritting from other classes.
*/

//Define a class that _root will inherit from.
Root = function (oArgs) {
        this.centerX = oArgs.centerX;
        this.centerY = oArgs.centerY;

        //Define a class that the mc 'holder' will inherit from.
        var Holder = function () {
                this._x = _parent.centerX;
                this._y = _parent.centerY;
                
                //Define a class that the movieclips 'asterisk1' and 'asterisk2' will inherit from.
                var Asterisk = function (oArgs) {
                        this._x = oArgs.posX;
                }
                //Make the 'Asterisk' class inherit from the 'Holder' class.
                Object.inheritPrototype(Asterisk, arguments.callee);
                //Make the mc 'asterisk1' and 'asterisk2' inherit instance properties and prototype
                //from the 'Asterisk' class.
                this.asterisk1.inherit(Asterisk, {posX: -50});
                this.asterisk2.inherit(Asterisk, {posX: 50});
                
        }
        //Define a method that the mc 'holder' will use.
        //And it's inherited to 'asterisk1' and 'asterisk2' by the 'inheritPrototype' method above.
        Holder.prototype.rotate = function (oArgs) {
                _rotation += oArgs.degree * oArgs.dir;
        }
        //Make the 'Holder' class inherit from the 'Root' class.
       Object.inheritPrototype(Holder, arguments.callee);
        //Make the mc 'holder' inherit instance properties and prototype from the 'Holder' class.
        this.holder.inherit(Holder);
}

//Define a method that the mc's "asterisk1" and "asterisk2" will use.
//This is inheritted to them via the mc "holder" by the "inheritPrototype" method above.
Root.prototype.changeAlpha = function () {
        if (changed = !changed) {
                _alpha = 30;
        } else {
                _alpha = 100;
        }
}
//Define a method that the start/stop button on _root will use.
Root.prototype.onPress = function () {
        if (pressed = !pressed) {
                eventEngine.subscribe("enterFrame", "_root.holder.asterisk1.rotate", {degree:10, dir:-1});
                eventEngine.subscribe("enterFrame", "_root.holder.asterisk2.rotate", {degree:10, dir:-1});
                eventEngine.subscribe("enterFrame", "_root.holder.rotate", {degree:2, dir:1});
                _root.holder.asterisk1.changeAlpha();
                _root.holder.asterisk2.changeAlpha();
        } else {
                delete eventEngine["enterFrame"];
        }
}
//Make _root inherit instance properties and prototype from the 'Root' class
_root.inherit(Root, {centerX:200, centerY:75});
delete Root;
/////////////////////////////////////////////////////////////////////////////////////////////////

Back to Flash Home

Copyright©2000-2002 STUDIO FIRST RAYS. All rights reserved