# Class extension and inheritance

**URL:** <https://forum.kirupa.com/t/class-extension-and-inheritance/262893>\
**Category:** flash\
**Created:** [June 10, 2008, 9:23pm UTC](https://forum.kirupa.com/t/class-extension-and-inheritance/262893 "2008-06-10T21:23:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![substance](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@substance](https://forum.kirupa.com/u/substance)\
**Post date:** [June 10, 2008, 9:23pm UTC](https://forum.kirupa.com/t/class-extension-and-inheritance/262893/1 "2008-06-10T21:23:25Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 10, 2008, 9:47pm UTC](https://forum.kirupa.com/t/class-extension-and-inheritance/262893/2 "2008-06-10T21:47:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 10, 2008, 9:53pm UTC](https://forum.kirupa.com/t/class-extension-and-inheritance/262893/3 "2008-06-10T21:53:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fidodo](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@Fidodo](https://forum.kirupa.com/u/Fidodo)\
**Post date:** [June 10, 2008, 10:53pm UTC](https://forum.kirupa.com/t/class-extension-and-inheritance/262893/4 "2008-06-10T22:53:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)\
**Post date:** [June 10, 2008, 11:32pm UTC](https://forum.kirupa.com/t/class-extension-and-inheritance/262893/5 "2008-06-10T23:32:22Z")

</div>

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

```auto
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.
