actionscript-3 - 如何处理 AS3 中启用 HTML 的文本字段的错误

标签 actionscript-3 error-handling textfield htmltext ioerror

如果我通过动态文本字段中的 标签加载图像并抛出 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/

相关文章:

apache-flex - flex, AdvancedDataGrid, 自定义 itemrenderer

php - IIS 7.5中的致命PHP错误

reactjs - 可编辑的 React-MaterialUI TextField 组件

带有 htmlText 的 Flash CS4 <b> 标签

actionscript-3 - AS3 - 垃圾收集器何时运行?

sockets - 如何找到已经在使用的地址?

python - MySQL 上 Django 中列的数据太长

flutter - 未处理的异常 : PlatformException(error, 无效选择开始 : 24, null,java.lang.IndexOutOfBoundsException:无效选择开始:24

ios - 为什么 iPad Retina 上的图形像素化?

c - 限制运行的线程