views:

52

answers:

1

If I do this

stuff.addEventListener(FooEvent.NAME, function(e:FooEvent) {
   dispatchEvent(e);
}

I get a runtime error saying that Event cannot be converted to FooEvent. However, it works fine if I do:

stuff.addEventListener(FooEvent.NAME, function(e:FooEvent) {
   dispatchEvent(new FooEvent(e.things));
}

Why?

+2  A: 

dispatchEvent calls clone on the passed event, if that event is already "used" (i.e. has been dispatched). from what you say, I am quite sure you did not override FooEvent's clone-method and thus it uses Event's implementation which returns a plain vanilla Event. That's the source of your error.

You need to override the clone method in FooEvent in order to return appropriate instances of FooEvent.

greetz

back2dos

back2dos