闪存文本字段的HTML - 如何prevent丢失图像的错误对话呢? (错误#2044:未处理IOErrorEvent :.文本=错误#2035:找不到网址)错误、文本、找不到、字段

2023-09-08 11:36:49 作者:女人如花花似梦 /*

我使用的Flash文本字段控件来显示内部闪存presentation一些HTML内容在一个大的触摸屏售货亭中显示。不幸的是,如果在所显示的HTML内容指向一个不存在的图像中的任何图像标记,一个对话被示出具有错误消息

 错误#2044:未处理IOErrorEvent :.文本=错误#2035:找不到网址。
 

我试图避免这种对话弹出。该解决方案通过加载器类加载的内容是赶上IOErrorEvent.IO_ERROR ,但我试过监听,关于文本字段,在舞台上,主要和的LoaderInfo无济于事。我已经试过包装整个事情在一个try-catch,而且也不能正常工作。

下面是简化的code我使用的是找到解决办法:

 包{
    进口flash.display.Sprite;
    进口flash.errors.IOError;
    进口对象类型:flash.events.Event;
    进口flash.events.IOErrorEvent在;
    进口API元素flash.text.TextField;
    进口flash.text.TextFieldType;

    公共类主要扩展Sprite {

        公共函数main():无效{
            如果(阶段)的init();
            其他的addEventListener(Event.ADDED_TO_STAGE,INIT);
        }

        私有函数初始化(E:事件= NULL):无效{
            removeEventListener(Event.ADDED_TO_STAGE,INIT);

            VAR HTML:文本字段=新的TextField();
            html.type = TextFieldType.DYNAMIC;
            html.multiline = TRUE;
            html.htmlText =伪造的图像:其中,IMG SRC = \foo.jpg \/>中;

            的addChild(HTML);
        }
    }
}
 
我U盘怎么回事

编辑:这里是整个工作code

。 当然

有关动态内容等等,则需要图像的列表和一个函数生成处理程序等。

 包{
    进口flash.display.Loader;
    进口flash.display.Sprite;
    进口flash.errors.IOError;
    进口对象类型:flash.events.Event;
    进口flash.events.IOErrorEvent在;
    进口API元素flash.text.TextField;
    进口flash.text.TextFieldType;

    公共类主要扩展Sprite {

        公共函数main():无效{
                如果(阶段)的init();
                其他的addEventListener(Event.ADDED_TO_STAGE,INIT);
        }

        私有函数初始化(E:事件= NULL):无效{
                removeEventListener(Event.ADDED_TO_STAGE,INIT);

                VAR HTML:文本字段=新的TextField();
                html.type = TextFieldType.DYNAMIC;
                html.multiline = TRUE;
                html.htmlText =伪造的图像:其中,IMG ID = \图像\SRC = \foo.jpg \/>中;

                VAR装载机:装载机= html.getImageReference(图像)作为加载程序;
                如果(装载机){
                    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,功能(五:事件):无效{
                            跟踪(错误加载foo.jpg!);
                        });
                }

                的addChild(HTML);
        }
    }
}
 

解决方案

您可以添加的ID将图像

  html.htmlText =伪造的图像:其中,IMG SRC = \foo.jpg \ID =形象/>中;
 

然后设置IOErrorEvent处理程序,在HTML中每个图像

  VAR装载机:装载机= html.getImageReference(图像)作为加载程序;
如果(装载机){
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,功能(五:事件):无效{});
}
 

I'm using a Flash TextField control to display some HTML content inside a Flash presentation to be shown on a large touch-screen kiosk. Unfortunately, if any image tag in the displayed HTML content points to a non-existent image, a dialogue is shown with the error message

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

I am trying to avoid having that dialogue pop up. The solution for loading content through a loader class is to catch IOErrorEvent.IO_ERROR, but I've tried listening for that on the TextField, on stage, Main and loaderInfo to no avail. I've tried wrapping the whole thing in a try-catch, and that also doesn't work.

Here's the simplified code I'm using to find solutions:

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);
        }
    }
}

Edit: And here's the entire working code.

For dynamic content and so forth, of course, you would need a list of images and a function to generate handlers, etc.

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);
        }
    }
}

解决方案

You can add ID's to images

html.htmlText = "Bogus image: <img src=\"foo.jpg\" id="image" />";

And then setup IOErrorEvent handler to each image in HTML

var loader:Loader = html.getImageReference("image") as Loader;
if(loader){
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(e:Event):void{});
}