A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Trap a Loader error and handle it with default

  1. #1
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110

    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.

  2. #2
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110
    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?

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    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.

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Oh wait I see, the issue is more about knowing which loader failed....

  5. #5
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110
    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.

  6. #6
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    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);
    }

  7. #7
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110
    cs:
    e.currentTarget.loader.name does not work due to the fact the the e.currentTarget.loader does not reference anything.

  8. #8
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    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'));

  9. #9
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center