vendredi 27 janvier 2017

How to handle the SecurityError #2070 and #2000 in Loader.load()

I have a AIR project that loads a any swf. But when the loaded swf dispatches a SecurityError, I can't handle this error! My code is bellow:

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

The exceptions from FlashDevelop:

[Fault] exception, information=SecurityError: Error #2070: Security sandbox violation: caller file.swf cannot access Stage owned by app:/myApp.swf.

[Fault] exception, information=SecurityError: Error #2000: No active security context.

The problem is that my program quits and I can not catch these security errors. How can I prevent my program from closing?

Aucun commentaire:

Enregistrer un commentaire