开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜