触发 MouseEvent 的dispatchEvent 不起作用

发布于 2024-12-19 08:25:38 字数 1793 浏览 5 评论 0原文

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

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

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

I am adding the same image (play button) to a movie clip those images later when pressed toggle states and play a video.

What I am trying to accomplish is automatically toggle the default image since that video is playing automatically.

        //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));
}

So this does the same thing as click the first image but it happens automatically.

THIS IS MY ERROR:

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

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

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

发布评论

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

评论(1

_蜘蛛 2024-12-26 08:25:38

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

Try adding the thumb_Loader to the Display List in callThumbs rather than thumbLoaded.

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