A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: XML Sometimes Not Loading

  1. #1
    Senior Member
    Join Date
    Jun 2001
    Posts
    343

    XML Sometimes Not Loading

    Sometimes my swf can't receive data from an xml and load it. I don't know why sometimes it works and sometimes it doesn't, but I'm trying to have the code respond if it doesn't load. I've looked through the forums but couldn't find an answer. I've tried a few things, but couldn't get it to work. Any help would be most appreciated. Thanks.

    Actionscript Code:
    var globalXMLReq:URLRequest = new URLRequest("http://mysite/global.xml");
    var globalXMLLoader:URLLoader = new URLLoader();
    var globalXML:XML;

    globalXMLLoader.addEventListener(Event.COMPLETE, globalXMLLoaded);
    globalXMLLoader.load(globalXMLReq);

    function globalXMLLoaded(event:Event):void
    {
    trace("this is where my xml code is");
    }
    Last edited by gamist; 02-24-2010 at 01:46 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You have no call to load there, nor an addEventListener to tell you that it is loaded. That should never work.

  3. #3
    Senior Member
    Join Date
    Jun 2001
    Posts
    343
    Copy and paste fail. I just edited my original post to include it.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Add listeners for the other events URLLoader can dispatch, particularly SecurityErrorEvent.SECURITY_ERROR,
    HTTPStatusEvent.HTTP_STATUS,
    IOErrorEvent.IO_ERROR

    Also, try/catch for the errors that load may throw.

  5. #5
    Senior Member
    Join Date
    Jun 2001
    Posts
    343
    I've been trying the try/catch, but can't get it to work. Is this the correct way of doing it?

    Actionscript Code:
    function globalXMLLoaded(event:Event):void
    {
            try
        {
            trace("the external xml data that normally works");
        }
        catch (event:Error)
        {
            trace("the code that should run if the external xml doesn't load");
        }
    }

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    No, not even close.

    You need to surround the line(s) that may throw the errors with the try block.

    Code:
    try{
      globalXMLLoader.load(globalXMLReq);
    }catch(se:SecurityError){
      trace(se);  //or se.message, or se.getStackTrace()
    }

  7. #7
    Senior Member
    Join Date
    Jun 2001
    Posts
    343
    You're right...I wasn't close.

    I made some changes, and now I can't get it to fail, so I guess I either fixed the problem or I have to wait until it fails again to see if the try/catch works. Thanks for the help.

  8. #8
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    Also useful for remoting and or external data management is a http proxy monitor. A good one that i use is charles , however i also use firebug. Both can show you the server request and response code and message. Especially useful when doing loading thing across domains , and what looks like , without a policy file in place.

Tags for this Thread

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