The question is at the very bottom. Here's the scenario:

Let's say I have a base class Animal, and subclasses Dog and Cat that 
extend Animal.
Animal has a protected Speak() method which Dog and Cat each override: 
when aDog instance and aCat Speak(), they each raise an event, a 
CreatureSpeakingEvent.


class Dog extends Animal {
override protected class Speak() {
  var sound:String = "woof";
   var eventObj:CreatureSpeakingEvent = new CreatureSpeaking ( 
"CreatureSpeakingEvent", sound,  true, false );
     this.dispatchEvent(eventObj);
}
}

class Cat extends Animal {
override protected class Speak() {
  var sound:String="meow";
   var eventObj:CreatureSpeakingEvent = new CreatureSpeakingEvent ( 
"CreatureSpeakingEvent", sound,  true, false );
     this.dispatchEvent(eventObj);
}
}

In the main class, which can instantiate either or both of these 
animals, a listener is attached to the CreatureSpeakingEvent event:

var aDog = new Dog();
var aCat = new Cat();
aDog.addEventListener("CreatureSpeakingEvent", onCreatureSpeaking);
aCat.addEventListener("CreatureSpeakingEvent", onCreatureSpeaking);

The onCreatureSpeaking() function listens:

private function onCreatureSpeaking(e:CreatureSpeakingEvent) {
//  is the following cast to the base-class Animal acceptable?
Animal (e.target).removeEventListener("CreatureSpeakingEvent", 
onCreatureSpeaking);
}


Thanks for the help!
Tim


Reply via email to