AS3 调度事件的方法

发布于 2024-09-13 04:56:25 字数 1053 浏览 10 评论 0原文

我想知道这两个dispatchEvent方法之间的区别...

//1.
    eventObj:YouTubeSearchEvent = new YouTubeSearchEvent(YouTubeSearchEvent.CHANGE_VIDEO_READY);
                    eventObj.videoId = theOneVideoId;
                    dispatchEvent(event);

//2
    dispatchEvent(new YouTubeSearchEvent(YouTubeSearchEvent.CHANGE_VIDEO_READY, videoId));

根据我的自定义事件,我需要有两个参数...但想知道第一个方法是否与第二个不同...

我的自定义事件:

package com.search.events
{
    import flash.events.Event;

    public class YouTubeSearchEvent extends Event
    {
        public static const FEED_VIDEO_READY:String="feed_video_ready";
        public static const CHANGE_VIDEO_READY:String="change_video_ready";

        public var videoResult:*;

        public function YouTubeSearchEvent(type:String, videoResult:*)
        {
            super(type);

            this.videoResult=videoResult;

        }
    }
}

问题是来自我的另一篇文章 AS3 Pass 自定义事件数据问题

I was wondering the difference between these two dispatchEvent method...

//1.
    eventObj:YouTubeSearchEvent = new YouTubeSearchEvent(YouTubeSearchEvent.CHANGE_VIDEO_READY);
                    eventObj.videoId = theOneVideoId;
                    dispatchEvent(event);

//2
    dispatchEvent(new YouTubeSearchEvent(YouTubeSearchEvent.CHANGE_VIDEO_READY, videoId));

According my custom event, I need to have two arguments...but was wondering if the first method is different than the second one...

My custom event:

package com.search.events
{
    import flash.events.Event;

    public class YouTubeSearchEvent extends Event
    {
        public static const FEED_VIDEO_READY:String="feed_video_ready";
        public static const CHANGE_VIDEO_READY:String="change_video_ready";

        public var videoResult:*;

        public function YouTubeSearchEvent(type:String, videoResult:*)
        {
            super(type);

            this.videoResult=videoResult;

        }
    }
}

The question is from my another post
AS3 Pass Custom Event Data Question

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫七 2024-09-20 04:56:26

从内部来看,它们并没有什么不同。运行时可能会对代码进行一些优化,但我对此表示怀疑。

最大的区别是第一个比第二个更具可读性。另外,我认为您的意思是在第一个而不是 videoId 中设置 videoResult ,因为类中没有。

编辑:
实际上,有一点细微的区别,即您在第一个对象中创建显式对象引用,这取决于代码所在的位置,可能会或可能不会停留一段时间,从而消耗内存。这是Flash,虽然我不会太担心,但你已经使用了相当多的内存,我不认为一个事件对象引用会导致问题。此外,当运行时发现它没有被使用时,它会被垃圾收集。

Internally they are not different. The runtime might do some optimisation to the code but I doubt that.

The biggest difference then is that the first one is a bit more readable than the second. Also I think you mean to set the videoResult in the first one not the videoId since there isn't one in the class.

EDIT:
Actually there is the slight difference that you are creating an excplicit object reference in the first one which depending on where the code is might or might not hang around for some time thus consuming memory. This being Flash though I wouldn't be too concerned about that, you're using quite a bit of memory already I don't think one event object reference will cause a problem. Besides it'll get garbage collected when the runtime sees that it's not being used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文