我正在使用Flash TextField控件在Flash演示文稿中顯示一些HTML內容,以便在大型觸摸屏上顯示。不幸的是,如果在顯示HTML內容指向一個不存在的圖像的任何圖像標籤,將會顯示一個對話框並顯示錯誤消息Flash TextField HTML - 如何防止丟失圖像的錯誤對話框? (錯誤#2044:未處理的IOErrorEvent :. text =錯誤#2035:找不到URL)
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
我試圖避免這種對話彈出。用於通過加載器類加載內容的solution是爲了趕上IOErrorEvent.IO_ERROR
,但我試着在TextField上,在舞臺上,Main和loaderInfo上聽到這一點無濟於事。我嘗試在試穿中包裹整個事物,但這也行不通。
下面是簡單的代碼,我使用的是找到解決辦法:
package {
import flash.display.Sprite;
import flash.errors.IOError;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
public class Main extends Sprite {
public function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
var html:TextField = new TextField();
html.type = TextFieldType.DYNAMIC;
html.multiline = true;
html.htmlText = "Bogus image: <img src=\"foo.jpg\" />";
addChild(html);
}
}
}
編輯:這裏是整個工作的代碼。
對於動態內容等等,當然,你需要的圖像列表,並生成一個處理功能等
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.errors.IOError;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
public class Main extends Sprite {
public function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
var html:TextField = new TextField();
html.type = TextFieldType.DYNAMIC;
html.multiline = true;
html.htmlText = "Bogus image: <img id=\"image\" src=\"foo.jpg\" />";
var loader:Loader = html.getImageReference("image") as Loader;
if(loader){
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(e:Event):void {
trace("Error loading foo.jpg!");
});
}
addChild(html);
}
}
}
哦...我現在沒有時間去測試這個,但我會解決它。 – 2009-05-27 21:24:41