-
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.
-
You have no call to load there, nor an addEventListener to tell you that it is loaded. That should never work.
-
Copy and paste fail. I just edited my original post to include it.
-
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.
-
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"); } }
-
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()
}
-
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.
-
rabid_Delineator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|