如何强制调试播放器不启动调试窗口,而是静默输出消息

时间:2014-03-06 07:43:13

标签: actionscript-3

我想在firefox浏览器中测试一个非常cpu密集的swf文件。但问题是遇到未处理的错误时,它会显示调试窗口。我试图处理每一个错误,但它变得非常困难,因为在每次错误时,浏览器都会完全挂起。我必须重新启动。 那么,有什么好办法,比如说。通过编译器等,我可以告诉调试播放器,不显示在窗口中,并停止进程,但只是一些其他方式来显示输出?

我使用一般的try..catch块。但仍有很多次,窗口弹出。好像,try..catch块在每种情况下都不起作用。

这是一个简单的示例:代码将目录中的所有文件列入列表组件。单击时,必须加载所选文件。因此,swf或图片文件(jpg,png等)没有问题。但是说,我点击“FLA”,显然不应该加载。错误窗口不可预测地弹出:错误#2044:未处理的IOErrorEvent:。 text =错误#2124:加载的文件是未知类型。

var loader:Loader =new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,doneLoad);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadingError);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,updateInfo);

function fileList_Lst_CLICK(e:MouseEvent):void 
{
    doLoad();
}

function doLoad(e:MouseEvent=null):void {

    try
    {
    loader.load(new URLRequest(fileList_Lst.selectedItem.label));
    }
    catch(e:Error)
    {
        trace(e.toString());
    }

    //infoBox.text="Loading starts...";


}

function updateInfo(e:ProgressEvent):void {

    trace("Loading: "+String(Math.floor(e.bytesLoaded/1024))+" KB of "+String(Math.floor(e.bytesTotal/1024))+" KB.");

}

function loadingError(e:IOErrorEvent):void {

     trace("There has been an error loading the image.");

         }


function doneLoad(e:Event):void {

    try
    {
        loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,doneLoad);
        loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,updateInfo);
        loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,loadingError);
        displayView_Mc.addChild(loader);
    }
    catch(e:*)
    {
        trace("error loading!");
    }

  }

1 个答案:

答案 0 :(得分:2)

在应用的根目录中使用 UncaughtErrorEvent 。 这将捕获应用程序内所有未捕获的错误 PS:你需要使用flash player + 10.x.x

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/UncaughtErrorEvent.html#propertySummary

SAMPLE App

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/halo"
                       applicationComplete="applicationCompleteHandler();">

    <fx:Script>
        <![CDATA[
            import flash.events.ErrorEvent;
            import flash.events.MouseEvent;
            import flash.events.UncaughtErrorEvent;

            private function applicationCompleteHandler():void
            {
                loaderInfo.uncaughtErrorEvents.addEventListener( UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
            }

            private function uncaughtErrorHandler(event:UncaughtErrorEvent):void
            {
                // use prevent default and stopPropagation to prevent the Flash debug window appear
                event.preventDefault();
                event.stopImmediatePropagation();

                if (event.error is Error)
                {
                    var error:Error = event.error as Error;
                    // do something with the error
                }
                else if (event.error is ErrorEvent)
                {
                    var errorEvent:ErrorEvent = event.error as ErrorEvent;
                    // do something with the error
                }
                else
                {
                    // a non-Error, non-ErrorEvent type was thrown and uncaught
                }
            }

            private function clickHandler(event:MouseEvent):void
            {
                throw new Error("Gak!");
            }
        ]]>
    </fx:Script>

    <s:Button label="Cause Error" click="clickHandler(event);"/>
</s:WindowedApplication>