1

当我尝试uncaughtErrorEvents直接加载时访问调度程序时,一切正常。但是,当我在另一个 swf 加载时尝试相同的代码时,我得到一个参考错误。

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

直接加载时的输出(在浏览器中):

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

由另一个“加载器”SWF 加载时的输出:

Flash version: MAC 10,1,53,64
ReferenceError: Error #1069: Property uncaughtErrorEvents not found on flash.display.LoaderInfo and there is no default value.

如果其他人可以复制这一点,我将不胜感激。

编辑:也试过用stage.loaderInfo, 而不是loaderInfo. 同样的问题...

4

3 回答 3

1

加载对象的 loaderInfo 与初始化对象的 loaderInfo 不同,并且通过 Loader 类的内容也不同。在文档中声明您必须将侦听器添加到加载器上的 uncaughtErrorEvents,而不是与其关联的 loaderInfo:

要检测加载的 SWF 中发生的未捕获错误,请使用 Loader.uncaughtErrorEvents 属性,而不是 Loader.contentLoaderInfo.uncaughtErrorEvents 属性。

-livedocs 链接

所以大概你必须将它添加到加载器而不是加载或检测是否加载然后将其添加到父级或其他东西。我知道不优雅,但我能想到的就是绕过它。

于 2010-06-11T08:38:47.837 回答
1

看到这个链接:https ://bugs.adobe.com/jira/browse/FP-4978

Flash Player 中有一个错误会影响模块上的处理程序 uncaughtErrorEvents

如果您在 Adob​​e 的 JIRA 中注册并投票,该错误将很快得到修复...

于 2011-02-24T08:51:25.097 回答
0

我将事件侦听器附加到“根”,这对我有用:

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

在调试 Flash Player 中,这仍然会出错,但在非调试版本中,错误将出现在 Flash Player 的对话框中 - 然后处理程序将做出响应。要停止出现对话框,请添加:

event.preventDefault();

所以:

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

我在 AIR 中使用它,但我认为它也适用于标准 AS3 项目。

于 2011-02-14T16:58:21.987 回答