AS3事件处理事件

2023-09-09 21:51:40 作者:胯下阻击手

我有奇怪的问题,事件处理在AS3中。

I've got strange problem with Event handling in AS3.

我有两个类:

public class Configurator extends Sprite {

    public function Configurator () {
        this.addEventListener(FramedPhoto.FRAMED_PHOTO_LOADED, this._test);
        var fp = new FramedPhoto();
    }

    protected function _test(event:Event) {
        trace('_test()');
    }
}

和第二个

public class FramedPhoto extends Sprite {

    public static const FRAMED_PHOTO_LOADED = 'framedPhotoLoaded';

    public function FramedPhoto () {
        trace('FramedPhoto()');
        this.dispatchEvent(new Event(FramedPhoto.FRAMED_PHOTO_LOADED, true, false));
    }
}

问题是,_test()不被解雇。任何想法可能是错在这里做什么?

Problem is that _test() is not being fired. Any ideas what could be done wrong here?

测试包的源文件可从 http://blackbox.home.pl/test.zip

推荐答案

事件的调度是一个分层的方式,所以只是听某个事件的地方不会做的伎俩。 你需要做的是让你配置器听调度事件或者一个的上方的它显示列表中的对象。如果你想捕获所有的事件,你需要听他们所有的最顶层的对象,在

Events are dispatched in a hierarchical fashion, so just listening for an event wherever won't do the trick. What you need to do is to make your configurator listen to the object that dispatches the event or one above it in the display list. If you want to catch all events you'll need to listen to the topmost object of them all, the stage.