Class extension and inheritance

Is it possible for a class to extend 2 different classes?

I basically want to create a “base class” that has certain properties/methods. Then I want a class that extends the movieclip class but that also inherits all properties from said “base class”.

ActionScript does not support multiple inheritance, which would allow you to have a class with two direct parents like you want.

However, ahmednuaman’s suggestion is a good one. It is possible to represent any multiple inheritance class structure using single inheritance because any directed acyclic graph can be converted to a forest, or tree in most cases.

I disagree with my esteemed colleague Krilnon, and argue that acyclic graphs are best converted into average to small sized shrubberies, very occasionally hedges.

You can inherit multiple interfaces but they are very limited to only function definitions, meaning no code. An interface basically defines what functions need to be implemented in the implementing classes.

Interfaces anso are used to typecast multiple classes which are not the same
FirstBase extends MovieClip { … }
Base extends Event { … }
These can not be typecasted to anything, but
FirstBase extends MovieClip implements ISomeInterface { … }
Base extends Event implements ISomeInterface { … }
Can be typeCasted to ISomeInterface.

Usually the most common way of usage is:

  • I extend some class, but i also want use Events
public class MyClass extends OtherClass implements IEventDispatcher {
    private var dispatcher:EventDispatcher;
    public function MyClass() {
        dispatcher = new EventDispatcher(this);
    }
    public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void{
        dispatcher.addEventListener(type, listener, useCapture, priority);
    }
    public function dispatchEvent(evt:Event):Boolean{
        return dispatcher.dispatchEvent(evt);
    }
    public function hasEventListener(type:String):Boolean{
        return dispatcher.hasEventListener(type);
    }
    public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void{
        dispatcher.removeEventListener(type, listener, useCapture);
    }
    public function willTrigger(type:String):Boolean {
        return dispatcher.willTrigger(type);
    }
}

This class will typecast to: MyClass, OtherClass, EventDispatcher.