dispatchEvent触发MouseEvent无法正常工作

时间:2011-12-01 20:59:17

标签: flash actionscript-3 mouseevent event-dispatching

我将相同的图像(播放按钮)添加到影片剪辑中,这些图像稍后会在按下切换状态并播放视频时显示。

我想要完成的是自动切换默认图像,因为该视频正在自动播放。

        //Setup thumb Container
         thumbs = new Sprite();
        thumbs.addEventListener (MouseEvent.CLICK, playVideo);
        thumbs.x = thumbs_x;
        thumbs.y = thumbs_y;
            thumbs.buttonMode = true;
            main_container.addChild (thumbs);
    //Call Function that gets all the thumbs using loader and adds it to the thumb movieClip

    callThumbs ();
    setDefaultButton ();

    function callThumbs ():void {



        for (var i:Number = 0; i < my_total; i++) {



                var thumb_url = my_videos[i].@THUMB;
                var thumb_loader = new Loader();
                thumb_loader.name = i;
                trace(thumb_loader.name);
                thumb_loader.load (new URLRequest(root_path + thumb_url));
                thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);
                thumb_loader.y = (thumb_height+210)*i;

    }

        function thumbLoaded (e:Event):void {
        var my_thumb:Loader = Loader(e.target.loader);
        thumbs.addChild (my_thumb);
    }


function setDefaultButton ():void {
thumbs.getChildAt(0).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
//or 
thumbs.getChildByName('0').dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}

所以这与点击第一张图片完全相同,但它会自动发生。

这是我的错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at LowesPlayerCS4_fla::MainTimeline/setDefaultButton()
    at LowesPlayerCS4_fla::MainTimeline/processXML()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

1 个答案:

答案 0 :(得分:1)

尝试将thumb_Loader添加到callThumbs中的显示列表而不是thumbLoaded。