# Inferitance question

**URL:** <https://forum.kirupa.com/t/inferitance-question/260783>\
**Category:** Uncategorized\
**Created:** [May 19, 2008, 9:13pm UTC](https://forum.kirupa.com/t/inferitance-question/260783 "2008-05-19T21:13:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sasxa](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sasxa](https://forum.kirupa.com/u/sasxa)\
**Post date:** [May 19, 2008, 9:13pm UTC](https://forum.kirupa.com/t/inferitance-question/260783/1 "2008-05-19T21:13:12Z")

</div>

Is it possible to have multiple listeners inclasses that inherit one another? uhm, sounds confusing :P, here:

```auto

package {
  //...imports and stuff
  public class CsA extends Sprite {
    //...constructor and stuff
    addEventListener(MouseEvent.CLICK, eHa)

    private function eHa(e:MouseEvent):void {
      //...doing some cool stuff here (:
    }
  }

  public class CsB extends CsA {
     //...constructor and stuff
    addEventListener(MouseEvent.CLICK, eHb)

    private function eHb(e:MouseEvent):void {
      //...animating/tweening some cool stuff here (,
    }
  }
}

```

The thing is, I made some cool class that works great (CsA), and I’d like to use it’s functionality and expand it… But I’m stuck… Can’t figure out a way to make this work… I had an idea to dispatch some other event back to the CsB class when MouseEvent occurs, but that seams like too much trouble (for today at least 😛 ).

If someone could tell me is this thing possible, and/or explain how inheritance works in AS3 (what can I do, and what isn’t possible), or knows some other way it would be gr8!

Sasxa

---

<div class="post-metadata">

**Author:** ![Gundark](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@Gundark](https://forum.kirupa.com/u/Gundark)\
**Post date:** [May 19, 2008, 9:50pm UTC](https://forum.kirupa.com/t/inferitance-question/260783/2 "2008-05-19T21:50:34Z")

</div>

You could always override the eHa function instead of creating eHb. Then in the eHa function in CsB you’d just call the original function by doing “super.eHa(e);”.

Then you’d only have to add the event listener once in your CsA class.

---

<div class="post-metadata">

**Author:** ![sasxa](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sasxa](https://forum.kirupa.com/u/sasxa)\
**Post date:** [May 19, 2008, 10:14pm UTC](https://forum.kirupa.com/t/inferitance-question/260783/3 "2008-05-19T22:14:21Z")

</div>

Brilliant! That’s exactly what I wanted. Thanks a lot man, I’ll give it a try asap

Sasxa

---

<div class="post-metadata">

**Author:** ![rahul\_7star](https://avatars.discourse-cdn.com/v4/letter/r/e36b37/32.png) [@rahul\_7star](https://forum.kirupa.com/u/rahul_7star)\
**Post date:** [May 20, 2008, 7:00am UTC](https://forum.kirupa.com/t/inferitance-question/260783/4 "2008-05-20T07:00:57Z")

</div>

[quote=sasxa;2328387]Brilliant! That’s exactly what I wanted. Thanks a lot man, I’ll give it a try asap

Sasxa[/quote]  
can you show me how this is working with exp

---

<div class="post-metadata">

**Author:** ![sasxa](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sasxa](https://forum.kirupa.com/u/sasxa)\
**Post date:** [May 20, 2008, 1:14pm UTC](https://forum.kirupa.com/t/inferitance-question/260783/5 "2008-05-20T13:14:41Z")

</div>

```auto

package {
  //...imports and stuff
  public class CsA extends Sprite {
    //...constructor and stuff
    addEventListener(MouseEvent.CLICK, eHa)

    protected function eHa(e:MouseEvent):void {
      //...doing some cool stuff here (:
    }
  }

  public class CsB extends CsA {
     //...constructor and stuff

    override protected function eHa(e:MouseEvent):void {
       // To get all functionality of parent class
       super.eHa(e);
      // Then you can do anything you want here...

      //...animating/tweening some cool stuff here (,
    }
  }
}

```

this is how classes should look to get inheritance to work properly… Tnx again Gundark!

---

<div class="post-metadata">

**Author:** ![Gundark](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@Gundark](https://forum.kirupa.com/u/Gundark)\
**Post date:** [May 20, 2008, 3:42pm UTC](https://forum.kirupa.com/t/inferitance-question/260783/6 "2008-05-20T15:42:41Z")

</div>

No problem! Glad it worked for you!
