Catching an unhandled IOErrorEvent in Flash AS3
Solution 1
if you are using a loader; try adding the eventListener to the contentLoaderInfo of the loader, e.g.
myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
Solution 2
You must listen for the IOErrorEvent.IO_ERROR of your URLLoader object.
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
function loaderIOErrorHandler(errorEvent:IOErrorEvent):void{
trace("ioErrorHandler: " + errorEvent);
}
If you trace the event object, then it should give you some information about what is going on.
Solution 3
Have you tried
loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandlerIOErrorEvent);
[EDIT]
Also include contentLoaderInfo events?
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler );
Solution 4
It looks like IOErrorEvent.IO_ERROR
should work. Also make sure you're using a URLLoader
to retrieve the image.
Based on the example from the comments:
package {
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;
import flash.geom.Rectangle;
import flash.events.Event;
public class Main extends Sprite {
private var urlLoader:URLLoader = new URLLoader();
public function Main() {
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load(new URLRequest("http://www.java2s.com/image2.jpg"));
urlLoader.addEventListener(Event.COMPLETE, completeHandler);
urlloader.addEventListener(IOErrorEvent.IO_ERROR, imageNotFound);
}
private function completeHandler(event:Event):void {
var loader:Loader = new Loader();
loader.loadBytes(urlLoader.data);
addChild(loader);
}
private function imageNotFound(ev:Event):void{
trace("File not found.");
}
}
}
Yevgeny Simkin
I fled Soviet Russia as a child and have spent my life bouncing from music to comedy to software engineering. You can follow my comedy Twitter feed here. I'm also the founder and CEO of The Russian Mob™—an agency specializing in developing SAAS, Mobile, AR, VR, and Web applications. (No: we won’t help you hack a foreign election so don’t bother asking.) On occasion, things that I think are published over at The Bulwark, which you should be reading, even if my ideas weren't being published there. If you would like to connect with me, the easiest way is through LinkedIn.
Updated on July 09, 2022Comments
-
Yevgeny Simkin almost 2 years
Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed.
That's what I see every time I try to load an image that doesn't exist using a Loader. I'm getting a list of URLs and can't validate if they're pointing to anything useful. Whenever it encounters a 404 it gives me that error.
I have tried to catch the error with every available
IOErrorEvent
there is (there are 7 of them),but none of them seem to capture the 404. Is there some other network event that I can be looking for to catch this condition?! I feel like I'm missing something obvious.What I'd really like is to be able to catch the event regardless of its description and just deal with it... sort of like
myLoader.addEventListener(IOErrorEvent.*, dealWithError);
But that's illegal. I even tried catching
HTTPStatusEvent.HTTP_STATUS
but that never calls back because, I guess, it gets the HTTP status after it deals with the error events, so, as it fails on the "unhandled" error event, it just gets lost. Are there events that aren't in the IDE that I'm overlooking?
All help appreciated.
-
Yevgeny Simkin about 13 yearsyes, along with the 6 other IOErrorEvents. NONE of them are the culprits, and I can't figure out how to actually find out WHAT error it's seeing.
-
Jason Towne about 13 years@Dr.Dredel, Make sure you're using a
URLLoader
like in the example above. -
Yevgeny Simkin about 13 yearsI wasn't using URLLoader (though that turned out to be an alternative solution... reading the bytestream and loading THAT into a loader), it's the Loader object that I was using directly and it is not catching the IO_ERROR
-
Yevgeny Simkin about 13 yearsagreed, but please add the code to actually draw the image, otherwise this is pointless! :) Here's an example...java2s.com/Code/Flash-Flex-ActionScript/Network/…
-
Yevgeny Simkin about 13 yearsoh, I see... sorry, I was overlooking you loading it into the Loader... ok... well... if anyone looks at this answer, please note that there is one missing line here whereby you have to set the format to BINARY or you'll get an exception trying to load the data into the Loader... otherwise, the above works.
-
Yevgeny Simkin about 13 yearsah crap... the answer from Michiel Standaert is the "correct" answer to my actual question, but I upvoted yours as it's also a great solution.
-
The_asMan about 13 yearscan you post all related code to you myLoader object. Without your code at this point we are just guessing. My gut is telling me you are not scoping something correctly. Also editing my post with more info.
-
Yevgeny Simkin about 13 yearsa HA! that's where they hid it... very clever! (too clever by half, in fact).
-
Michiel Standaert about 13 yearsi knew the event.complete was fired there, so it was only logical the ioError was fired there too ;)
-
surfer01 over 10 yearsYeah even after being a flash developer for 2+ years, I still occasionally make this mistake. SUPER irritating.