PDA

View Full Version : Loader, if image not found, load another


compsci
12-22-2008, 02:04 PM
Hello all,

I load images like this:
var imageLoader = new Loader();
imageLoader.load(new URLRequest(path));
imageLoader.contentLoaderInfo.addEventListener(IOE rrorEvent.IO_ERROR, imageNotFound);When there is an IOErrorEvent, I want to load another image saying image not available, how can I do this?function imageNotFound(ev:Event):void {
trace('Image Not Found, use not available image');
ev.target.loader.load(new URLRequest('../images/image_not_available.gif'));
}

With the above I get the error:
Error: Error #2099: The loading object is not sufficiently loaded
to provide this information.
at flash.display::LoaderInfo/get loader()
at test2_fla::MainTimeline/imageNotFound()
Any work arounds???

moagrius
12-23-2008, 12:16 AM
you could use URLLoader to test if the image is available, and act accordingly:



var firstfile:String = path;
var secondfile:String = '../images/image_not_available.gif';
var firstrequest:URLRequest = new URLRequest(firstfile);
var secondrequest:URLRequest = new URLRequest(secondfile);
var urlloader = new URLLoader();
var loader:Loader = new Loader();

urlloader.load(firstrequest);
urlloader.addEventListener("complete",imageFound);
urlloader.addEventListener(IOErrorEvent.IO_ERROR, imageNotFound);

function imageFound(ev:Event){
loader.load(firstrequest);
}
function imageNotFound(ev:Event):void{
trace("first file not found, using second file");
loader.load(secondrequest);
}

this.addChild(loader);