ActionScript 3 event forwarding illegal?
If I do this
stuff.addEventListener(FooEvent.NAME, function(e:FooEvent) {
dispatchE开发者_如何学Cvent(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 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
.
精彩评论