我正在尝试使用新的(ish)AS3全局错误处理类。我试图在Flex mxml应用程序中使用它。我无法让它工作。以下是显示问题的完整程序。我将其设置为使用Flash Player 10.2并使用Flex 4.5 SDK进行编译。Flex 4.0/4.5全局错误处理
我已经尝试过使用Flex SDK 4.0和4.5,但在任何情况下都会出现错误。我必须在这里忽略一些明显的东西。这是一个普通的Flex SWF文件,将在网页上显示。假设我可以导入UncaughtErrorEvent,然后,我会做这样的事情来设置事件处理程序:
if(systemManager.loaderInfo.hasOwnProperty("uncaughtErrorEvents")) {
IEventDispatcher(
systemManager.loaderInfo["uncaughtErrorEvents"]).addEventListener(
"uncaughtError", uncaughtErrorHandler);
}
这一切似乎可怕的缺憾,但我可以忍受的不同之处在于它不工作!我搜索了网页,找不到任何文档或示例来解释如何在我的上下文中进行此项工作。有什么建议?
完整的程序:从API(我建议你通过下一次看)
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="onApplicationComplete();"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function onApplicationComplete() : void {
systemManager.loaderInfo.uncaughtErrorEvents.addEventListener("uncaughtError", uncaughtErrorHandler);
}
private function uncaughtErrorHandler(event:Event) : void {
trace(event.toString());
}
]]>
</fx:Script>
<s:Button x="153" y="64" label="Trigger Error" id="triggerButton" click="throw new Error('myError')"/>
</s:Application>
尝试使用stage.loaderInfo而不是systemManager? http://stackoverflow.com/questions/3315904/global-error-handler-for-flash-player-10-1-not-working – Satish 2011-05-16 23:17:29
嗯,那个线程只是确认我遇到的问题。无论我使用哪个loaderInfo addEventListener,它都不起作用。 – 2011-05-17 11:22:10