Inferitance question

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


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 :stuck_out_tongue: ).

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

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.

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

Sasxa

[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


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!

No problem! Glad it worked for you!