PDA

View Full Version : Check files without double loading



Miguelele
January 30th, 2008, 04:06 PM
Hi: when I try to acces and load an external image (or video) using URLRequest, if the file does not exists I get an error that ignores the "Try-Catch".

I have found some solutions to check the file, but it is said that the process, in fact, loads the file, and if it really exists, then it is loaded again!!!!

Can somebody enlighten me? I think it is important enough to have a dedicated command, like in most languages.

Regards:
Miguel

devonair
January 30th, 2008, 05:16 PM
What solutions have you found and tried? Have you listened for an IOErrorEvent.IO_ERROR? Both the Netstream and LoaderInfo object will dispatch this when there is no file to load or no connection to reach that file.

Miguelele
January 30th, 2008, 07:00 PM
Thank you. I'm not at the dev machine and I can't paste my code, but I remember perfectly using that IO error catchers, and the error message were something like "unhandled error", and the Try-Catch became unusable. The error were fired just before the alternate code.

I'm not english native, but I understand "unhandled error" as an error that can't be managed by the runtime. A nonsense, because it recognizes the situation like an error!!

Regards:
Miguel

Miguelele
January 31st, 2008, 03:01 PM
Have you listened for an IOErrorEvent.IO_ERROR? Both the Netstream and LoaderInfo object will dispatch this when there is no file to load or no connection to reach that file.

Hello again. Here is my code. If the file does not exists, it never reaches the trace, so I can't load a placeholder instead of the missing jpg.

How can I receive the error?



public function displayPicture(xLoc:int,yLoc:int):void
{
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,loadBitmap);
loader.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
loader.load(new URLRequest(SERVERPATH + "assets/thumbs/" + itemNode.alias+".jpg"));
}

private function handleIOError(e:IOErrorEvent):void
{
trace("Error text: " +IOErrorEvent(e).text);
}


Regards:
Miguel

devonair
January 31st, 2008, 06:38 PM
The loader's LoaderInfo instance should be what is listening for the IOErrorEvent (just as it listens for the Event.COMPLETE).

loader.contentLoaderInfo.addEventListener(IOErrorE vent.IO_ERROR, handleIOError);

Miguelele
January 31st, 2008, 07:23 PM
Oh!, great, it works!! Serious matter, the loaders…

Thank you:
Miguel

Miguelele
February 4th, 2008, 07:13 PM
One more thing!!!!

I can't find the way with the video component. I am not using a loader object, but the loader inside the component…

var $url:String = $urlbase+itemNode.alias+".flv";
player.load($url);
player.addEventListener(VideoEvent.COMPLETE, completeHandler);
(…)


How can I manage it? I cant see error handlers to add a listener…

Regards: Miguel

devonair
February 4th, 2008, 07:44 PM
It's kind of a pain.. The easiest way I could figure was to listen for state changes and if you see a connection error, you know things have gone awry..

something like:
import fl.video.VideoEvent;

player.addEventListener(VideoEvent.STATE_CHANGE, onChange);
player.play("nonexistent.flv");

function onChange(ve:VideoEvent):void {
if (player.state == "connectionError") {
trace ("could not load video.");
}
}

Miguelele
February 5th, 2008, 07:51 AM
It's kind of a pain.. The easiest way I could figure was to listen for state changes and if you see a connection error, you know things have gone awry..



Thank you again, but no luck here. The error (VideoError: 1000: Unable to make connection to server or to find FLV on server) jumps before being catched, as happened in my initial problem with the images.

I learned the video implementation using the video component, but I wonder if something similar can be done with a loader object, and "plug" data from that object in the video component. Maybe AS3 fan-fiction, but it sounds good…

Regards: Miguel