如果我通过动态文本字段中的 标签加载图像并抛出 IOError,我还要附加什么事件监听器?文本字段? 我试过这个...
var textField:TextField = new TextField();
textField.htmlText = "here is some text <img src='image.jpg'> and then some more";
textField.addEventListener(IOErrorEvent.IOError, function (e:Event):void { trace("error caught") });
没用...
建议?
最佳答案
您必须将 id
设置为 img
,然后在 getImageReference 中使用它在您的 TextField
上获取 Loader
,您可以在其中添加所有 Event你想要:
import flash.display.Loader;
import flash.events.IOErrorEvent;
import flash.text.TextField;
//...
var tfd:TextField = new TextField();
tfd.htmlText =
"here is some text <img id='myImg' src='image.jpg' /> and then some more";
var ldr:Loader = tfd.getImageReference("myImg") as Loader;
if (ldr != null) {
ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
}
//...
private function onIOError(e:IOErrorEvent):void{
//...
}
另一个例子here如果你愿意
关于actionscript-3 - 如何处理 AS3 中启用 HTML 的文本字段的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2308516/