Flash TextField HTML - How to prevent error dialog for missing images? (Error # 2044: Unhandled IOErrorEvent :. text = Error # 2035: URL not found)

I am 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 dialog is displayed with an error message

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

      

I am trying to avoid this dialog appearing. the solution for loading content via the loader class is to catch it IOErrorEvent.IO_ERROR

, but I tried listening to it on the TextField, in the Main and loaderInfo stage to no avail. I've tried wrapping the whole thing in try-catch and that doesn't work either.

Here is the simplified code I use 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 all the working code.

For dynamic content, etc., of course you 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);
        }
    }
}

      

+1


source to share


7 replies


You can add id to images

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

      



And then set up an IOErrorEvent handler for each image in HTML

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

      

+5


source


This is a cool problem.

I have two suggestions.

1) Don't use TextField. I am assuming you developed Flash before Flex, as I did. You may already know this, but it took me a while to find out: the TextField object is not intended for regular use in Flex. Check it out in Flex3 language:

The TextField class is used to create display objects for displaying text and input. All dynamic and intro 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 usually use shortcut, text, TextArea and TextInput for process text.



Obviously, there is nothing wrong with using TextField, but I have found that when I am trying to understand complex problems, it is very helpful to do this "by book" how I can remove unknowns (as many as possible, at least).

2) I think I'll try to either extend the Text component or create a new Text based component. In this component, I would add logic to load and insert images into the TextField object. This way, you can easily create and validate a string to be inserted into a TextField object before it is inserted into a TextField.

If you do, email me - I could use it myself. :)

+2


source


If you have the ability to use the new FTE / TLF components, do so. Adobe has largely turned its back on the old TextField API, and this same error is the reason I have 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 works in my opinion.

TLF solves these problems and is much easier to work with. What takes days of experimenting with the old API will only take a few hours. I have created some rich text editors in the new API and it is very enjoyable to use. You will be glad you did :)

+1


source


I was able to detect when the image loaded, but I think I'll follow TLF's advice. anyway, if you need to know, you need to implement an enter_frame event listener on the uploader and check the Length value for contentInfo in the bytes property, if the image is not loaded, the length is 0xffffffff, if the image is loaded, the length is the file size, and if there is an error, then the bytes properties are NULL.

+1


source


 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..

      

+1


source


This is the problem I am dealing with: this is a real annoyance. I would really like 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 pointed out.

Maybe you can check that the kiosk flash player is not a debug version. I don't think the release version is throwing dialogs (might be wrong).

-1


source


Can not be! Same problem if you are using Loader to load images that don't exist! Flex is a framework and the Image class uses this Flash Loader object, but with a lot of lines of code (check the SwfLoader source ...).

You can check the url of the image before setting the htmlText property, or create your own component to display text and images.

I can't believe this simple and stupid error hasn't been fixed by Adobe yet!

-1


source







All Articles