Introduction

Flash is a lightweight cross-platform runtime for rich media, enterprise applications and mobile applications, as well as an integrated development environment. Flash can be programmed in ActionScript 1/2/3.

Monday, July 7th, 2003 at 1:56 pm

Multiple Inheritance

I needed a multiple inheritance script for one of my projects and I thought maybe it would be helpful for other’s too. It also enables you to edit the prototype chain during runtime. So here is the code:

o = _global.MultipleInheritance=function () {}
o.initialize = function(obj) {
        if(obj.classes == undefined) obj.classes = new Object();
        obj.__resolve = this.__resolve;
        obj.addClass = this.addClass;
        obj.removeClass = this.removeClass;
        return obj;
}
o.__resolve = function() {
        for (var i in this.classes) {
                var f = this.classes[i].prototype[arguments];
                if(f != undefined) return f;
        }
}
o.addClass = function() {
        if(arguments.length>1){
                for(var i in arguments){
                        this.classes[arguments[i]] = eval(arguments[i]);
                }
        } else {
                this.classes[arguments] = eval(arguments);
        }
}
o.removeClass = function() {
        if(arguments.length>1){
                for(var i in arguments){
                        delete this.classes[arguments[i]];
                }
        } else {
                delete this.classes[arguments];
        }
}
delete o;

// example
SuperClass1 = function () {}
SuperClass2 = function () {}

// 1
SubClass = function () {}
MultipleInheritance.initialize(SubClass.prototype);
SubClass.prototype.addClass(”SuperClass1“, “SuperClass2“);

// 2
this.createEmptyMovieClip(”mc“, 1);
MultipleInheritance.initialize(this.mc);
this.mc.addClass(”SuperClass1“, “SuperClass2“);

One Response to “Multiple Inheritance”

  1. Andre Michelle

    Works fine for me.
    So sad, that the methods of the SuperClasses cannot be named equal. But this is the non private function madness in flash :o)