2012-03-29 53 views
2

我想寫一些代碼來捕獲所有的錯誤和ErrorEvents,但我似乎無法得到它拋出的錯誤,只有ErrorEvents。UncaughtErrorEvent捕獲ErrorEvents但不拋出錯誤

下工作正常

package 
{ 
    import flash.display.Sprite; 
    import flash.events.ErrorEvent; 
    import flash.events.UncaughtErrorEvent; 
    public class Main extends Sprite 
    { 
     public function Main():void 
     { 
      loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError); 
      dispatchEvent(new ErrorEvent(ErrorEvent.ERROR)); 
     } 
     private function onUncaughtError(e:UncaughtErrorEvent):void 
     { 
      trace("Main.onUncaughtError > e : " + e); 
      e.preventDefault(); 

     } 
    } 
} 

但這並不捕獲錯誤,並導致詮釋標準調試播放器錯誤彈出。

package 
{ 
    import flash.display.Sprite; 
    import flash.events.UncaughtErrorEvent; 
    public class Main extends Sprite 
    { 
     public function Main():void 
     { 
      loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError); 
      throw new Error(); 
     } 
     private function onUncaughtError(e:UncaughtErrorEvent):void 
     { 
      trace("Main.onUncaughtError > e : " + e); 
      e.preventDefault(); 

     } 
    } 
} 

這發生在所有支持的玩家10.1和以上。

回答

5

好的解決了它。該代碼確實有效,但它仍然會觸發IDE中的調試器。

點擊continue將會執行處理程序代碼,並且如果您從swf單獨運行swf就沒問題。

+0

男人,這一直讓我瘋狂的這一整天,直到我找到你的帖子! )) – pokrishka 2013-11-08 12:11:53

相關問題