开发者

Anyone else unable to listen to uncaughtErrorEvent when loaded by another swf?

When I try to access the uncaughtErrorEvents dispatcher when loaded directly, everything works well. But when I try the same code when loaded by another swf I get a reference error.

protected function onAddedToStage(e:Event):void {
    trace("Flash version: " + Capabilities.version);
    try {
      loaderInfo.uncaughtErrorEvents.addEventListener("uncaughtError", onUncaughtError);
      trace("YAY!");
    } catch (e:Error) {
      trace(e);
    }
}

Output when loaded directly (in browser):

Flash version: MAC 10,1,53,64
YAY!

Output when loaded by another "loader" SWF:

Flash version: MAC 1开发者_JS百科0,1,53,64
ReferenceError: Error #1069: Property uncaughtErrorEvents not found on flash.display.LoaderInfo and there is no default value.

If others can replicate this I'd be appreciative.

EDIT: Also have tried this with stage.loaderInfo, instead of just loaderInfo. Same issue...


the loaderInfo of a loaded object is different from that of an initialised object, and content through a Loader class is delt with differently. in the documentation is states that you have to add the listener to uncaughtErrorEvents on the loader, not the loaderInfo assosiated with it:

To detect uncaught errors that happen in a loaded SWF, use the Loader.uncaughtErrorEvents property, not the Loader.contentLoaderInfo.uncaughtErrorEvents property.

-livedocs link

so presumably you have to either add it to the loader rather than the loaded or detect if loaded and then add it to parent or something instead. inelegant i know, but all i can think of to get around it.


see this link: https://bugs.adobe.com/jira/browse/FP-4978

There are a bug in the Flash Player which affect the handler uncaughtErrorEvents on modules

If you register in Adobe's JIRA and vote, the bug will be repared sooner...


I attached the event listener to the 'root', which worked for me:

sprite.root.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);

In the debug Flash Player this will still error, but in the non-debug version the error will appear in Flash Player's dialog box - and then the handler will respond. To stop the dialog box from appearing, add:

event.preventDefault();

so:

    private function onUncaughtError(event:UncaughtErrorEvent):void
    {
        event.preventDefault();
        // do something with this error
    }

I was using this in AIR, but I assume it works for standard AS3 projects too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜