我正在嘗試使用新的(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