Apache flex 其他人在被另一个swf加载时无法侦听uncaughtErrorEvent吗?
当我尝试在直接加载时访问Apache flex 其他人在被另一个swf加载时无法侦听uncaughtErrorEvent吗?,apache-flex,flash,actionscript-3,loaderinfo,Apache Flex,Flash,Actionscript 3,Loaderinfo,当我尝试在直接加载时访问uncaughtErrorEventsdispatcher时,一切正常。但是当我在另一个swf加载时尝试相同的代码时,我得到了一个引用错误 protected function onAddedToStage(e:Event):void { trace("Flash version: " + Capabilities.version); try { loaderInfo.uncaughtErrorEvents.addEventListener("
uncaughtErrorEvents
dispatcher时,一切正常。但是当我在另一个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);
}
}
直接加载时的输出(在浏览器中):
由另一个“加载器”SWF加载时的输出:
如果其他人能复制这一点,我将不胜感激
编辑:也尝试过使用
stage.loaderInfo
,而不仅仅是loaderInfo
。相同的问题…已加载对象的loaderInfo与初始化对象的loaderInfo不同,并且通过Loader类的内容以不同的方式进行delt。文档中说明必须将侦听器添加到加载程序上的uncaughtErrorEvents,而不是与之关联的加载程序信息:
检测发生的未捕获错误
在加载的SWF中,使用
Loader.uncaughtErrorEvents属性,
不是
Loader.contentLoaderInfo.uncaughtErrorEvents
财产
因此,您可能需要将其添加到加载器而不是已加载,或者检测是否已加载,然后将其添加到父级或其他内容。我知道不雅,但我能想到的就是绕开它。我将事件侦听器附加到“根”上,这对我很有用:
sprite.root.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
在调试Flash Player中,这仍然会出错,但在非调试版本中,错误将出现在Flash Player的对话框中,然后处理程序将作出响应。要停止显示对话框,请添加:
event.preventDefault();
因此:
我在空中使用过这个,但我认为它也适用于标准AS3项目。请参见以下链接:
Flash Player中存在影响处理程序的错误
模块上的uncaughtErrorEvents
如果你在Adobe的JIRA中注册并投票,该漏洞将很快被修复
sprite.root.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
event.preventDefault();
private function onUncaughtError(event:UncaughtErrorEvent):void
{
event.preventDefault();
// do something with this error
}