开发者

ActionScript 3 event forwarding illegal?

开发者 https://www.devze.com 2022-12-21 23:12 出处:网络
If I do this stuff.addEventListener(FooEvent.NAME, function(e:FooEvent) { dispatchE开发者_如何学Cvent(e);

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

精彩评论

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