我有一个加载任何swf的AIR项目。但是当加载的swf调度SecurityError时,我无法处理此错误!我的代码如下:
var loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, swfErrors);
_loader.contentLoaderInfo.addEventListener(Event.INIT, swfInit);
_loader.contentLoaderInfo.addEventListener(Event.OPEN, swfOpen);
_loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatus);
_loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, swfSecurityError);
_loader.contentLoaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrors);
try {
_loader.load(new URLRequest('path.swf'));
}
catch(e:SecurityError) {
trace("trying handle error!");
}
function swfComplete(e:Event):void {
trace("complete");
}
function swfErrors(e:IOErrorEvent):void {
trace("swf error: " + e.toString() );
}
function swfInit(e:Event):void {
trace("swf init");
}
function swfOpen(e:Event):void {
trace("swf open. this listener dispatch!");
}
function httpStatus(e:HTTPStatusEvent):void {
trace("http status: " + e.toString() );
}
function swfSecurityError(e:SecurityErrorEvent):void {
trace("trying handle security error. :(");
}
function uncaughtErrorEvent(e:UncaughtErrorEvent):void {
trace("uncaught error: " + e.toString() );
}
FlashDevelop的例外:
[Fault] exception,information = SecurityError:错误#2070:安全沙箱冲突:调用者file.swf无法访问app所拥有的Stage:/myApp.swf。
[Fault] exception,information = SecurityError:Error#2000:No active security context。
问题是我的程序退出,我无法捕获这些安全错误。如何阻止我的程序关闭?
答案 0 :(得分:2)
您的代码无法处理此异常,因为它不是加载例程违规。当加载的内容试图访问该阶段时(并且由于沙盒策略而无权访问它),就会发生这种情况。
您可以(可能)以多种方式解决它: