活动结束后获得由MovieClip的包含(父)类 [英] Get composed MovieClip's containing (parent) class after event

查看:145
本文介绍了活动结束后获得由MovieClip的包含(父)类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在父(非显示对象)类组成的影片剪辑。我们对注册的影片剪辑事件侦听器 - a。单击处理程序,例如

I have a MovieClip that is composed in a parent (non-display object) class. We register an event listener against that movieclip - a CLICK handler for example.

使用将event.target 我可以从事件处理程序中得到一个引用影片剪辑。但我怎么能拉一提及其构成的类?

With event.target I can get a reference to the MovieClip from within the event handler. But how can I pull a reference to its composing class?

我可以简单地对动态MovieClip类添加一个父类属性,但我不知道是否有这样做的更优雅/惯用的方式,我应该考虑?

I could simply add a "parentClass" property on the dynamic MovieClip class, but I'm wondering if there's a more elegant/idiomatic way of doing it that I should consider?

推荐答案

如果创建你的影片剪辑的类不是显示对象,然后它真的不能被认为是其母公司。父元素将是,你的影片剪辑附加到。所有这一切的创作类包含一个引用一个对象,只是一样的,如果你再参考其他地方的影片剪辑。

If the class that creates your MovieClip is not a display object then it cannot really be considered its parent. The parent element will be that which your MovieClip is attached to. All that the creating class contains is a reference to an object, just the same as if you then refer to the MovieClip elsewhere.

我的preferred的方法是创建一个子类影片剪辑,可以包含引用创建类,你会再使用,而不是影片剪辑

My preferred way would be to create a descendant class of MovieClip that can contain a reference to the creating class, which you would then use instead of MovieClip.

package {
    import flash.display.MovieClip;

    public class MovieClipWithRef extends MovieClip
    {
        private var _parentRef:Object;  //obviously cast this as accurately as possible

        public function MovieClipWithRef($ref:Object):void
        {
            _parentRef = $ref;
        }

        public function get parentRef():Object
        {
            return _parentRef;
        }
        //no setter makes this property read-only once set by the constructor
    }
}

这篇关于活动结束后获得由MovieClip的包含(父)类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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