Jes*_*kan 1 apache-flex flash actionscript flex3 actionscript-3
我正在使用Flash TextField控件在Flash演示文稿中显示一些HTML内容,以便在大型触摸屏自助服务终端上显示.遗憾的是,如果显示的HTML内容中的任何图像标记指向不存在的图像,则会显示带有错误消息的对话框
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
Run Code Online (Sandbox Code Playgroud)
我试图避免弹出对话.通过loader类加载内容的解决方案是捕获IOErrorEvent.IO_ERROR,但我已经尝试在TextField上监听,在舞台上,Main和loaderInfo都无济于事.我试过用try-catch包装整个东西,但这也行不通.
这是我用来寻找解决方案的简化代码:
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是整个工作代码.
当然,对于动态内容等,您需要一个图像列表和一个生成处理程序的函数等.
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以将ID添加到图像
html.htmlText = "Bogus image: <img src=\"foo.jpg\" id="image" />";
Run Code Online (Sandbox Code Playgroud)
然后为HTML中的每个图像设置IOErrorEvent处理程序
var loader:Loader = html.getImageReference("image") as Loader;
if(loader){
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(e:Event):void{});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4361 次 |
| 最近记录: |