Flash TextField HTML - 如何防止出现丢失图像的错误对话框? (错误#2044:未处理的 IOErrorEvent:。text=错误#2035:未找到 URL)

发布于 2024-07-08 14:29:46 字数 2623 浏览 8 评论 0原文

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

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

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

这是我用来寻找解决方案的简化代码:

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

编辑:这是整个工作代码。

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

我喜欢麦丽素 2024-07-15 14:29:46

您可以向图像添加 ID

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

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

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

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{});
}
恰似旧人归 2024-07-15 14:29:46

这是一个很酷的问题。

我有两个建议。

1) 不要使用文本字段。 我猜你和我一样,先是用 Flash 开发,然后再用 Flex 开发。 您可能已经知道这一点,但我花了一段时间才发现:TextField 对象并不适合在 Flex 中常规使用。 从 Flex3 语言参考中查看这一点:

TextField类用于创建
用于文本显示的显示对象和
输入。 所有动态和输入文本
SWF 文件中的字段是以下实例
TextField 类。 您可以使用
TextField 类执行低级操作
文本渲染。 然而,在 Flex 中,您
通常使用标签、文本、
TextArea 和 TextInput 控件
处理文本。

显然,使用 TextField 没有任何问题,但我发现,当我试图解决棘手的问题时,尽可能多地“按照书本”做,以消除未知数(尽可能多,至少)。

2)我想我会尝试扩展文本组件,或者基于文本创建一个新组件。 在此组件中,我将添加逻辑以加载图像并将其插入到 TextField 对象中。 这样,您可以在将字符串插入 TextField 之前轻松构建并验证要插入 TextField 对象的字符串。

如果你能成功,请发帖 - 我自己可以使用它。 :)

This is a cool problem.

I have two suggestions.

1) Don't use TextField. I'm guessing that you developed in Flash before Flex, like me. You may already know this, but it took me awhile to find out: The TextField object isn't meant to be used for regular use in Flex. Check this out from the Flex3 language ref:

The TextField class is used to create
display objects for text display and
input. All dynamic and input text
fields in a SWF file are instances of
the TextField class. You can use the
TextField class to perform low-level
text rendering. However, in Flex, you
typically use the Label, Text,
TextArea, and TextInput controls to
process text.

Obviously, there's nothing wrong with using TextField, but I've found that when I'm trying to figure out tricky problems, it's really helpful to do as much 'by the book' as I can to remove unknowns (as much as possible, at least).

2) I think I'd try either extending the Text component, or else creating a new component based on Text. In this component I'd add logic to load and insert images into the TextField object. That way, you could easily build and validate the string to insert into the TextField object prior to inserting it into the TextField.

If you get this working, please post - I could use it myself. :)

风尘浪孓 2024-07-15 14:29:46

如果您有办法使用新的 FTE/TLF 组件,请这样做。 Adobe 基本上放弃了旧的 TextField API,同样的错误也是我过去不得不放弃许多项目和组件的原因。 这个错误抛出来,基本无法捕获。 我认为 Flash 工作中最糟糕的方面之一。

TLF 解决了这些问题并且更容易使用。 在旧 API 中需要花费数天时间进行实验的工作现在只需要几个小时。 我在新的 API 上构建了一些富文本编辑器,它非常好用。 你会很高兴你这么做了:)

If there's a way for you to use the new FTE/TLF components, do so. Adobe is basically turning its back on the old TextField API, and this same error is a reason that I had to abandon many projects and components in the past. This error is thrown and basically cannot be caught. One of the worst aspects of Flash work in my opinion.

TLF addresses these problems and is SO much easier to work with. What would take days of experimentation in the old API now takes only a few hours. I've built a few rich text editors on the new API and it is SO very nice to use. You'll be glad you did :)

非要怀念 2024-07-15 14:29:46

我能够检测到图像何时加载,但我想我会遵循 TLF 建议。 无论如何,如果您需要知道,您必须在加载器上实现 Enter_frame 事件侦听器并检查 bytes 属性上的 contentInfo 长度,如果图像尚未加载,则长度为 0xffffffff,如果图像已加载,则长度为文件的大小,如果出现错误,则字节属性为 NULL。

I was able to detect when an image has loaded, but I think I'll follow the TLF advice. anyways if you need to know, you have to implement an enter_frame event listener on the Loader and check for the contentInfo on the bytes property the Lenght, if the image hasn't load the length is 0xffffffff, if the image has loaded the length is the size of the file, and if there is an error the bytes properties es NULL.

水溶 2024-07-15 14:29:46
 var html:TextField = new TextField();
   html.width=388.95;
   html.height=400;
   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;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHan);
function completeHan(e:Event){
    addChild(html);
}

This will work..
 var html:TextField = new TextField();
   html.width=388.95;
   html.height=400;
   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;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHan);
function completeHan(e:Event){
    addChild(html);
}

This will work..
稚气少女 2024-07-15 14:29:46

这也是我正在处理的一个问题:这真是一个烦恼。 我真的希望能够捕获所有错误。 我以为你可以说......

stage.addEventListener(IOError.IO_ERROR, myErrorHandler);

但这似乎不起作用,正如你所指出的。

也许您可以检查以确保信息亭的 Flash 播放器不是调试版本。 我不认为发布版本会抛出对话框(可能是错误的)。

This is a problem I'm also dealing with: it's a real annoyance. I'd really like to be able to catch all the errors. I assumed you could say...

stage.addEventListener(IOError.IO_ERROR, myErrorHandler);

...but that doesn't seem to work, as you've pointed out.

Perhaps you can check to make sure the kiosk's flash player isn't the debug version. I don't think that the release version throws the dialogs (could be wrong).

季末如歌 2024-07-15 14:29:46

不可能的! 如果您使用加载器加载不存在的图像,也会出现同样的问题! Flex 是一个框架,Image 类使用这个 flash Loader 对象,但有大量代码行(查看 SwfLoader 的源代码...)。

您可以在设置 htmlText 属性之前检查您的图像 URL,或者您可以创建自己的组件来显示文本和图像。

我不敢相信这个简单的& Adobe 尚未修复愚蠢的错误!

Impossible! Same problem if you use the Loader to load images that doesnt exists! Flex is a framework and the Image class uses this flash Loader object but with plenty of lines of code (check out the source of SwfLoader...).

You can check your image URL before set the htmlText property or you can create your own component to display Text and Images..

I can't believe this simple & stupid bug is not still fixed by Adobe!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文