Reputation: 33
I do not need any debugging with my code, i'm looking more for a method.
Here's my issue. I'm developing a company dashboard that will be loading on multiple large screen televisions company wide. Each Screen will load my flash application to display a wide range of information. This brings up my issue... XML.
Right now i run my application locally while I'm developing. Everything works great, and even when I've tested on a single TV it runs fine. However prior to developing this application i made another that was a "band aid fix" for what they had prior to my employment. That application works well but probably once a week it fails to load and all the content goes blank. After 1 day of blank info it reloads and continues working.
In my new app i'm trying to plan around this issue i'm already seeing. What i would like to do is try loading the xml, if it fails to try the same function over again 3 times. If it fails 3 times, then it should be broken. :)
To me that sounds like a try/catch statement, but i can't seem to get it to work the way i want. I feel as if this is something i'm thinking way too much on it.
function loadXML ()
var i:Number = 0;
do {
try{
XMLLoader.load(new URLRequest("myXMLURL"));
} catch (error:Error) {
i++
}
}
while(i < 3)
}
Any Feedback or any other methods of making sure the xml will not fail would be appreciated. Thanks
Upvotes: 1
Views: 277
Reputation: 39466
Rather than a loop like that, you should use the inbuilt events that are dispatched in these situations like IOErrorEvent
.
If you attach a listener to the URLLoader
loading the XML, you'll be able to try again in the IOErrorEvent
handler:
function loadXML():void
{
var ldr:URLLoader = new URLLoader();
ldr.addEventListener(IOErrorEvent.IO_ERROR, error);
ldr.load( new URLRequest("document.xml") );
}
function error(e:IOErrorEvent):void
{
loadXML();
}
Here is a list of other Events that URLLoader
dispatches in similar situations.
Upvotes: 1