AS3事件处理 [英] as3 event handling

查看:184
本文介绍了AS3事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有奇怪的问题,事件处理在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.

这篇关于AS3事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆