2010-02-09 28 views

回答

2

以下是一些可能有所幫助的基礎知識。總之,你不能在這裏使用try/catch。

在try..catch..finally語句中無法捕獲加載外部內容時的錯誤。相反,您必須創建事件處理程序來處理和「捕捉」錯誤事件。如果您沒有將事件偵聽器分配給錯誤事件並且發生錯誤,則Flash播放器會通知您未處理的錯誤事件。

// creating listeners for error events handles 
// asynchronous errors 
target.addEventListener(ErrorEvent.TYPE, handler); 
function handler(event:ErrorEvent):void { 
// handle error 
} 

如果你想調用自己的異步錯誤,所有你需要做的是分派事件中使用dispatchEvent是類型的ErrorEvent的。當在Flash中創作時,未處理的ErrorEvent到達Flash播放器時,輸出窗口將顯示錯誤。

target.dispatchEvent(new ErrorEvent(」type」)); 
1

從Flash 10.1開始,現在可以捕獲主swf和其中加載的所有swf引發的所有錯誤。

要做到這一點,你需要監聽的UncaughtErrorEvent從loaderInfo.uncaughtErrorEvents對象調度,就像這樣:

loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, handleUncaughtErrors); 

function handleUncaughtErrors(e:UncaughtErrorEvent):void 
{ 
    e.preventDefault(); 
} 

,請謹慎使用,因爲這會抑制由的調試版本所顯示的所有錯誤播放器和flashlog.txt。

+0

這根本不適用於加載的swfs – Randalfien 2013-11-12 14:13:09

相關問題