|
-
Trap a Loader error and handle it with default
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.
Code:
var gell:Loader = new Loader();
addChild(gell);
gell.contentLoaderInfo.addEventListener(IOErrorEvent.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.
Last edited by imdumb; 05-28-2009 at 10:23 AM.
-
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?
-
KoolMoves Moderator
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/i...ActionScript-3
which might help.
-
KoolMoves Moderator
Oh wait I see, the issue is more about knowing which loader failed....
-
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.
-
up to my .as in code
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);
}
-
cs:
e.currentTarget.loader.name does not work due to the fact the the e.currentTarget.loader does not reference anything.
-
Will this work ?
Code:
var gell:Loader = new Loader();
addChild(gell);
gell.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorCatcher);
function errorCatcher(e:IOErrorEvent):void{
gell.load(new URLRequest('blank.jpg'));
}
gell.load(new URLRequest('cat.jpg'));
-
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....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|