【问题标题】:dispatchEvent to fire MouseEvent not workingdispatchEvent 触发 MouseEvent 不起作用
【发布时间】:2011-12-01 20:59:16
【问题描述】:

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

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

        //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()

【问题讨论】:

    标签: flash actionscript-3 mouseevent event-dispatching


    【解决方案1】:

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

    【讨论】:

    • 这个thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);在添加之前?
    • 没有。在加载之前,任何加载器中都不会有任何内容,但是一旦它们被加载,您就会看到它们。你可以像添加一个空的 Sprite 一样向 Display 列表添加一个空的加载器。
    猜你喜欢
    • 1970-01-01
    • 2019-02-12
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多