views:

34

answers:

1

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...Thanks for the reply...

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 http://stackoverflow.com/questions/3438789/as3-pass-custom-event-data-question

+1  A: 

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.

Matti
ic...thanks for the answer...
Jerry