Flash TextField HTML - 如何防止出现丢失图像的错误对话框?(错误 #2044:未处理的 IOErrorEvent:.text=错误 #2035:未找到 URL) [英] Flash TextField HTML - How do I prevent the error dialogue for missing images? (Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found)

查看:31
本文介绍了Flash TextField HTML - 如何防止出现丢失图像的错误对话框?(错误 #2044:未处理的 IOErrorEvent:.text=错误 #2035:未找到 URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Flash TextField 控件在 Flash 演示文稿中显示一些 HTML 内容,以便在大型触摸屏信息亭上显示.不幸的是,如果显示的 HTML 内容中的任何图像标记指向不存在的图像,则会显示一个带有错误消息的对话框

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.

我试图避免弹出该对话.通过加载器类加载内容的解决方案是捕获IOErrorEvent.IO_ERROR,但我试过在 TextField、舞台上、Main 和 loaderInfo 上监听,但无济于事.我试过用 try-catch 来包装整个事情,但这也不起作用.

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

这里是完整的工作代码.

当然,对于动态内容等,您需要一个图像列表和一个函数来生成处理程序等.

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

推荐答案

您可以为图像添加 ID

You can add ID's to images

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

然后为 HTML 中的每个图像设置 IOErrorEvent 处理程序

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

这篇关于Flash TextField HTML - 如何防止出现丢失图像的错误对话框?(错误 #2044:未处理的 IOErrorEvent:.text=错误 #2035:未找到 URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆