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?
dispatchEvent calls
cloneon 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 overrideFooEvent‘sclone-method and thus it usesEvent‘s implementation which returns a plain vanillaEvent. That’s the source of your error.You need to override the
clonemethod inFooEventin order to return appropriate instances ofFooEvent.