Actionscript 3 如何强制调试播放器不启动调试窗口,而是以静默方式输出消息
我想在firefox浏览器中测试一个cpu非常密集的swf文件。但问题是,每当遇到未经处理的错误时,就会显示调试窗口。我试图处理每一个错误,但这变得非常困难,因为在每一个错误,浏览器完全挂起。我必须重新开始。 那么,有没有什么好办法,比如通过编译器等,我可以告诉调试播放器,不要在窗口中显示,并停止进程,而只是用其他方式显示输出 我用的是通用的try..catch块。但还是有很多次,窗户会弹出。看起来,试试看……抓块并不是在所有情况下都有效 下面是一个简单的示例:代码将目录中的所有文件都列在列表组件中。单击时,必须加载选定的文件。因此,swf或图片文件(jpg、png等)没有问题。但是,我点击了一个“FLA”,它显然不应该加载。错误窗口意外弹出:错误#2044:未处理的IOErrorEvent:。text=错误#2124:加载的文件是未知类型Actionscript 3 如何强制调试播放器不启动调试窗口,而是以静默方式输出消息,actionscript-3,Actionscript 3,我想在firefox浏览器中测试一个cpu非常密集的swf文件。但问题是,每当遇到未经处理的错误时,就会显示调试窗口。我试图处理每一个错误,但这变得非常困难,因为在每一个错误,浏览器完全挂起。我必须重新开始。 那么,有没有什么好办法,比如通过编译器等,我可以告诉调试播放器,不要在窗口中显示,并停止进程,而只是用其他方式显示输出 我用的是通用的try..catch块。但还是有很多次,窗户会弹出。看起来,试试看……抓块并不是在所有情况下都有效 下面是一个简单的示例:代码将目录中的所有文件都列在列表组
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!");
}
}
在应用程序的根目录中使用UncaughtErrorEvent。 这将捕获应用程序中所有未捕获的错误 PS:你需要使用flash player+10.x.x 示例应用程序
<?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>
好问题,让我试试!!!