Click to See Complete Forum and Search --> : v7-AS3 Trap a Loader error and handle it with default
imdumb
05-28-2009, 10:53 AM
Hello everyone,
I am trying to trap a Loader error and handle with a default image.
There are multiple loaders so I need to catch and fill the one that errors.
var gell:Loader = new Loader();
addChild(gell);
gell.contentLoaderInfo.addEventListener(IOErrorEve nt.IO_ERROR, errorCatcher);
function errorCatcher(e:IOErrorEvent):void{
// This is not working. Have tried both lines.
//gell = Loader(e.target.loader);
var gell:Loader = LoaderInfo(e.target).loader;
gell.load(new URLRequest('blank.jpg'));
}
gell.load(new URLRequest('cat.jpg'));
Any suggestions on this will be greatly helpful.
imdumb
05-28-2009, 12:40 PM
I setup a trace and the results.
function errorCatcher(e:IOErrorEvent):void{
trace(e.currentTarget); //Object LoaderInfo
trace(e.currentTarget.loaderURL); //http:\\www.xxx.com\cat.jpg
trace(e.currentTarget.loader); // Nothing
}
Can someone verify that the trace lines are correct?
blanius
05-28-2009, 03:27 PM
Uh how are you using trace functions? KM doesn't support this in the GUI.
I usually use a text field named debug to simulate trace
Anyway I had issues with IOError and had come across this
http://www.brucephillips.name/blog/index.cfm/2007/8/29/How-To-Handle-InputOutput-IO-Error-Caused-By-URLLoader-in-Flex-2-or-ActionScript-3
which might help.
blanius
05-28-2009, 04:01 PM
Oh wait I see, the issue is more about knowing which loader failed....
imdumb
05-28-2009, 05:33 PM
I drop a simple function in my script editor.
function trace(v):void{
debug.text+=v+'\n';
}
then I call trace everytime I need to track something.
Chris_Seahorn
05-28-2009, 11:45 PM
try....
function errorCatcher(e:IOErrorEvent):void{
trace(e.currentTarget); //Object LoaderInfo
trace(e.currentTarget.loaderURL); //http:\\www.xxx.com\cat.jpg
trace(e.currentTarget.loader.name);
}
imdumb
05-29-2009, 08:49 AM
cs:
e.currentTarget.loader.name does not work due to the fact the the e.currentTarget.loader does not reference anything.
w.brants
05-29-2009, 11:37 AM
Will this work ?var gell:Loader = new Loader();
addChild(gell);
gell.contentLoaderInfo.addEventListener(IOErrorEve nt.IO_ERROR, errorCatcher);
function errorCatcher(e:IOErrorEvent):void{
gell.load(new URLRequest('blank.jpg'));
}
gell.load(new URLRequest('cat.jpg'));
imdumb
05-29-2009, 12:16 PM
Was going to use that but....
If I have multiple instances of loaders then I need to check which one did not load. I had found other references to this problem in the other forums and there solution was to use the e.currentTarget.loader to determine which one did not load.
Example of usage: An error is generated when the graphic, swf, etc could not load from the server or the reference name being loaded doesn't exist on the server.
This should work....
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.