闪存AS3崩溃后一个多次点击 - 参数错误 - noSource错误 [英] Flash AS3 Crashing After A Multiple Clicks - Argument Error - noSource error

查看:172
本文介绍了闪存AS3崩溃后一个多次点击 - 参数错误 - noSource错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有,一些AS3用于创建一个19键的交互式信息亭。它要求20个不同video_files以一种FLVPLayer播放。当点击一个按钮,它吸引玩家和指定源

I have here, some AS3 that is used to create a 19 button interactive kiosk. It calls 20 different video_files to be played in an FLVPLayer. When one button is clicked, it draws the player and specifies the source.

发生了什么,是我们的PC上,是我们的疯狂小子测试,在这里我们点击了几个不同的按钮启动和停止视频,和几个按钮$ P $后psses的SWF崩溃。

Whats happening is on our PC, is our crazy-kid-test, where we click a few different buttons starting and stopping the videos, and after a few button presses the SWF crashes.

我有参数错误(据到Adobe童军) 我有一个noSource错误present调试器(指向 removeChild之(movie_container); 和一对夫妇等看似随机的错误/错误消息。

I've had Argument Errors (according to Adobe Scout) I have a noSource error present in debugger (points to the removeChild(movie_container); And a couple other seemingly random bugs/error messages.

会有人介意一起来看看code。谢谢。注:Becauser它的一些500lines多久,我就贴上去,以buttonTwo

Would someone mind taking a look at the code. Thank you. Note: Becauser it's some 500lines long I'll paste up to buttonTwo.

    import flash.events.*;
import flash.display.*;
import flash.ui.Mouse;
import fl.video.*;
import flash.utils.Timer;


//Mouse.hide();

stop();

addEventListener(Event.ENTER_FRAME, timerHandler);

//===================== Primary Event Listeners ==========================//
buttonOne.addEventListener(MouseEvent.MOUSE_DOWN, playVideoOne);
buttonTwo.addEventListener(MouseEvent.MOUSE_DOWN, playVideoTwo);

// Show buttons so users can click - cheaper than adding/removing 20 e:listeners
function showTheButtons(): void {
    buttonOne.visible = true;
    buttonTwo.visible = true;

}

// Hide buttons so users cant crazy-click resulting in massive slowdown - cheaper than adding/removing 20 e:listeners
function hideTheButtons(): void {
    buttonOne.visible = false;
    buttonTwo.visible = false;

}

// ADD ALL EVENT Listeners after AttractLoop removed

//=====================
var attractTimer: Timer = new Timer(300000); //should be 7min OR 420000ms in production
attractTimer.addEventListener(TimerEvent.TIMER, timerHandler, false, 0, true);
attractTimer.start();
//=====================

this.aLoopMovie.visible = false;

aLoopMovie.addEventListener(MouseEvent.CLICK, stopRemoveVideo);
function stopRemoveVideo(event: Event): void {
    showTheButtons();
    aLoopMovie.visible = false;
    aLoopMovie.gotoAndStop(1);
    //=====================
    attractTimer.start();
    //=====================
}

function timerHandler(event: Event): void {
    attractTimer.stop();
    hideTheButtons();
    //++
    removeEventListener(Event.ENTER_FRAME, timerHandler);
    //++
    if (this.aLoopMovie.visible != true) {
        this.aLoopMovie.visible = true;
        this.aLoopMovie.play();
    }
}

//////////// BUILD PLAYER ///////////////
var movie_container: MovieClip = new MovieClip();

function launchVideo(vBox, vFile): void {
    hideTheButtons();

    var flvPlayer: FLVPlayback = new FLVPlayback();

    flvPlayer.source = vFile;
    flvPlayer.skinAutoHide = true;
    flvPlayer.skinBackgroundColor = 0x000000;

    flvPlayer.width = 1920;
    flvPlayer.height = 1080;
    flvPlayer.autoRewind = true;

    vBox.addChild(flvPlayer);

    // Allow Playabck timer //
    var playbackTimer: Timer = new Timer(5000); //should be 2sec OR 2000ms in production
    playbackTimer.addEventListener(TimerEvent.TIMER, allowPlayback);
    function allowPlayback(event: Event): void {
        playbackTimer.stop();
        movie_container.addEventListener(MouseEvent.CLICK, stopRemoveVideo);

        function stopRemoveVideo(event: Event): void {
            showTheButtons();
            flvPlayer.stop();
            //=====================
            movie_container.removeEventListener(MouseEvent.CLICK, stopRemoveVideo);
            //=====================
            removeChild(movie_container);
            attractTimer.start();
        }

        flvPlayer.addEventListener(fl.video.VideoEvent.COMPLETE, completeHandler);
        function completeHandler(event: fl.video.VideoEvent): void {
            flvPlayer.stop();
            playbackTimer.stop();
            showTheButtons();
            flvPlayer.removeEventListener(fl.video.VideoEvent.COMPLETE, completeHandler);
            //=====================
            removeChild(movie_container);
            //=====================
            attractTimer.start();
        }
    }
    playbackTimer.start();
    //////////////////////////

}
//////////// END BUILD PLAYER ///////////////

//===================== Primary Functions
function playVideoOne(event: Event): void {

    //=====================
    attractTimer.stop();
    hideTheButtons();
    //=====================

    // Place container on stage
    addChild(movie_container);
    movie_container.x = 0;
    movie_container.y = 0;

    //Video Source
    var video_file = "MPVideos/MP-01.mp4";

    launchVideo(movie_container, video_file);
}

function playVideoTwo(event: Event): void {

    //=====================
    attractTimer.stop();
    hideTheButtons();
    //=====================

    // Place container on stage
    addChild(movie_container);
    movie_container.x = 0;
    movie_container.y = 0;

    //Video Source
    var video_file = "MPVideos/MP-02.mp4";

    launchVideo(movie_container, video_file);

}

更新

function playVideoOne(event: Event): void {

    //=====================
    attractTimer.stop();
    hideTheButtons();
    //=====================

    var movie_container: MovieClip = new MovieClip();

    // Place container on stage
    addChild(movie_container);
    movie_container.x = 0;
    movie_container.y = 0;

    //Video Source
    var video_file = "MPVideos/MP-01.mp4";
    var flvPlayer: FLVPlayback = new FLVPlayback();

    function launchVideo(vBox, vFile): void {

        flvPlayer.source = vFile;
        flvPlayer.skinAutoHide = true;
        flvPlayer.skinBackgroundColor = 0x000000;

        flvPlayer.width = 1920;
        flvPlayer.height = 1080;
        flvPlayer.autoRewind = true;

        vBox.addChild(flvPlayer);

    }

    flvPlayer.addEventListener(fl.video.VideoEvent.COMPLETE, completeHandler);
    function completeHandler(event: fl.video.VideoEvent): void {
        flvPlayer.stop();
        flvPlayer.closeVideoPlayer(0);
        showTheButtons();
        flvPlayer.removeEventListener(fl.video.VideoEvent.COMPLETE, completeHandler);
        //=====================
        attractTimer.start();
        //=====================
        removeChild(movie_container);
        //=====================
    }

    movie_container.addEventListener(MouseEvent.CLICK, stopRemoveVideo);
    function stopRemoveVideo(event: Event): void {
        flvPlayer.stop();
        flvPlayer.closeVideoPlayer(0);
        showTheButtons();
        removeChild(movie_container);
        //=====================
        attractTimer.start();
        //=====================
        movie_container.removeEventListener(MouseEvent.CLICK, stopRemoveVideo);
        //=====================

    }

    launchVideo(movie_container, video_file);
}

移动嵌套函数上升了一个层次。这些事件侦听器(完全与放大器;单击)。不的的playVideoOne功能的工作之外

Moved the nested functions up a level. These event listeners (Complete & CLICK) don't work outside of the of the playVideoOne function.

推荐答案

您的主要错误是,你是为了声明函数中的变量,它在嵌套函数中使用。你认为这些不工作,而实际上我怀疑这是不是不确定的行为描述的类型。而且,你有很多的功能,这样设计的。你应该改为做的是:有无 flvPlayer 是一个变量在顶层,在事件监听器初始化,与相应的事件监听器来清除播放器,并重新定位函数launchVideo(VBOX,vFile)顶端级别,以及 - 这些完全复制在您的每一个听众。你也应该换所有的听众的公共部分为一个参数化功能,将创建 movie_container ,并使用所提供的字符串来推出正确的视频。

Your primary mistake is that you declare a variable in a function in order for it to be used in a nested function. These don't work as you think, and actually I doubt this is not a described type of undefined behavior. And, you have a lot of function designed this way. What you should instead do is: Have flvPlayer be a variable at the top level, initialized in an event listener, with corresponding event listeners to clear the player, and relocate function launchVideo(vBox, vFile) to the top level as well - these perfectly duplicate in each of your listeners. Also you should wrap the common part of all the listeners into a parameterized function that will create the movie_container and use the provided string to launch a correct video.

//===================== Additional variables
var flvPlayer:FLVPlayback;
var movie_container:MovieClip;

//===================== Primary Functions
function playVideoByString(source:String):void {
    attractTimer.stop();
    hideTheButtons();
    movie_container = new MovieClip();
    addChild(movie_container);
    movie_container.x = 0;
    movie_container.y = 0;

    launchVideo(movie_container, source); // that's it
}

function playVideoOne(event: Event): void {
    playVideoByString("MPVideos/MP-01.mp4"); // that's it as well
}

现在,你不处理适当的去除的FLVPlayback 实例,他们有听众所以这是他们堵塞你的记忆。泄漏甚至对象已经是不利的,而你正在泄漏的整体视频播放器。这已经不是什么,你用完了这个快速的内存惊喜。所以,你必须正确地停止和分离视频播放器或者是否有新的按钮是pressed,或者玩家完成播放。根据你的问题的更新,你的功能设计要做到这一点,并让他们的工作,你只需要在全球层面的变量。但是,你的错误是你在初始化时增加两个监听器,但只有一个在任的清除功能删除 - 在其他的侦听保持和prevent无论是 movie_container flvPlayer 进行垃圾回收,有效地渗出了整个视频播放器实例。

Now, you don't handle proper removal of FLVPlayback instance, they have listeners so it's them that clog your memory. Leaking even an Object is already detrimental, and you are leaking a whole video player. It's no surprise that you run out of memory this quick. So you have to properly stop and detach the video player either if a new button is pressed, or the player completes playback. According to your update of the question, you have functions devised to do this, and to make them work, you just need the variables at the global level. But your mistake is that you add two listeners when initializing, but remove only one at either of the removal functions - the other listener remains and prevent either the movie_container or the flvPlayer to be garbage collected, effectively leaking a whole video player instance.

// Primary functions (cont.)
function stopRemoveVideo(event: Event): void {
    doCleanup();
}
function completeHandler(event: fl.video.VideoEvent): void {
    doCleanup();
}
function doCleanup():void {
    // these actions are common between handlers, so put em in one place
    flvPlayer.stop();
    flvPlayer.closeVideoPlayer(0);
    showTheButtons();
    removeChild(movie_container);
    attractTimer.start();
    movie_container.removeEventListener(MouseEvent.CLICK, stopRemoveVideo);
    flvPlayer.removeEventListener(fl.video.VideoEvent.COMPLETE, completeHandler);
    // clear the references just in case
    movie_container=null;
    flvPlayer=null;
    // you need to remove both listeners in either case, otherwise you leak objects!
}
function launchVideo(vBox, vFile): void {
    flvPlayer=new FLVPlayback();
    flvPlayer.source = vFile;
    flvPlayer.skinAutoHide = true;
    flvPlayer.skinBackgroundColor = 0x000000;

    flvPlayer.width = 1920;
    flvPlayer.height = 1080;
    flvPlayer.autoRewind = false; // this changes as well
    // you close the vid if you hit movie end, why allow the player to autorewind?

    vBox.addChild(flvPlayer);
    // adding listeners in here
    flvPlayer.addEventListener(fl.video.VideoEvent.COMPLETE, completeHandler);
    movie_container.addEventListener(MouseEvent.CLICK, stopRemoveVideo);
}

这也许可能是不够的,消除源所有的错误,但它应该给你如何优化你的应用程序和使用实例化其中的一个对象的功能一个良好的开端。

This might probably be not enough to eliminate all mistakes in your source, but it should give you a good start in how to optimize your application and functions that use objects instantiated in one of them.

这篇关于闪存AS3崩溃后一个多次点击 - 参数错误 - noSource错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆