swfloader: can I catch all the exceptions from the

2019-06-10 08:04发布

I am loading a swf into another swf using swfloader, I want to catch all the exceptions thrown by the inner swf, is it doable?

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-06-10 08:10

Here are some basics that may help. In short, you cannot use try/catch here.

Errors in loading external content cannot be caught with try..catch..finally statements. Instead you have to create event handlers to handle and “catch” the error events. If you do not have an event listener assigned to an error event and that error occurs, the Flash player will inform you of the unhandled error event.

// creating listeners for error events handles
// asynchronous errors
target.addEventListener(ErrorEvent.TYPE, handler);
function handler(event:ErrorEvent):void {
// handle error
}

If you want to invoke your own asynchronous errors, all you need to do is dispatch an event using dispatchEvent that is of the type ErrorEvent. When an unhandled ErrorEvent reaches the Flash player when authoring in Flash, the output window will display the error.

target.dispatchEvent(new ErrorEvent(”type”));
查看更多
Juvenile、少年°
3楼-- · 2019-06-10 08:26

As of Flash 10.1 it is now possible to catch all errors thrown by both the main swf and any swfs loaded inside of it.

To do this you need to listen for an UncaughtErrorEvent dispatched from the loaderInfo.uncaughtErrorEvents object, like so:

loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, handleUncaughtErrors);

function handleUncaughtErrors(e:UncaughtErrorEvent):void
{
    e.preventDefault();
}

Please use with caution, as this will suppress all errors from being shown by the debug version of the player, and the flashlog.txt.

查看更多
登录 后发表回答