Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何处理AS3中支持HTML的文本字段中的IOErrors_Actionscript 3_Error Handling_Textfield_Htmltext_Ioerror - Fatal编程技术网

Actionscript 3 如何处理AS3中支持HTML的文本字段中的IOErrors

Actionscript 3 如何处理AS3中支持HTML的文本字段中的IOErrors,actionscript-3,error-handling,textfield,htmltext,ioerror,Actionscript 3,Error Handling,Textfield,Htmltext,Ioerror,如果我通过加载图像,然后再加载一些”; addEventListener(IOErrorEvent.IOError,函数(e:Event):void{trace(“错误捕获”)}); 没有用 建议?您必须使用try-catch块: var textField:TextField = new TextField(); textField.htmlText = "here is some text <img src='image.jpg'> and then some more"; t

如果我通过加载图像,然后再加载一些”; addEventListener(IOErrorEvent.IOError,函数(e:Event):void{trace(“错误捕获”)}); 没有用


建议?

您必须使用try-catch块:

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") });
试试看
{
var textField:textField=new textField();
textField.htmlText=“这里是一些文本,然后是更多”;
}
捕获(错误:IOError)
{
//处理IOError
}

您必须将
id
设置为
img
,然后在
文本字段中使用它来获取
加载程序,您可以在其中添加所需的所有内容:

try
{
  var textField:TextField = new TextField();
  textField.htmlText = "here is some text <img src='image.jpg'> and then some more";
}
catch( error:IOError )
{
    //handle IOError
}
导入flash.display.Loader;
导入flash.events.IOErrorEvent;
导入flash.text.TextField;
//...
var tfd:TextField=new TextField();
tfd.htmlText=
“这里有一些文字,然后还有一些”;
var ldr:Loader=tfd.getImageReference(“myImg”)作为加载器;
如果(ldr!=null){
ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
}
//...
私有函数错误(e:IOErrorEvent):无效{
//...
}
如果您想要另一个示例,我为您提供了解决方案:

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{
 //...
}

这将防止flashplayer在图像链接中断时抛出错误和崩溃

重复:我实际上没有测试我接受的解决方案(当时没有时间),所以请让我知道它是否对您有效。(编辑:好的,我没有那么懒,我正在尝试……)看起来你答应在去年5月测试它!这实际上不起作用,因此这个问题(和它重复的问题)有效,在我看来是一个更好的解决方案,因为你不必知道id。。
tField.addEventListener( Event.ADDED, addedObjectToFieldHandler, true );

function addedObjectToFieldHandler( event:Event ):void
{
   if ( event.target is Loader )
   {
       ( event.target as Loader ).contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, function( e:IOErrorEvent ):void{} );
   }
}