PDA

View Full Version : Importing XML issues


pj_anf
08-25-2006, 10:21 AM
Alright, so I've changed a recent music player from running static mp3's locally, to using a streaming server. The idea was to import the location of the files on the server, number of files, and other information from an xml file. This lets us keep the same player just update the xml if we need to make changes.

We hit a strange bug, where sometimes the flash file doesn't seem to load the xml. It will either keep trying to transfer data from the server, or just sit there and do nothing. Here's the Actionscript for my xml checking code:


afXML = new XML();
afXML.ignoreWhite = true;
afXML.load("tracks.xml");

afXML.onLoad = startAf;
function startAf(loaded) {
if (loaded == true) {
//xmlOutput.text = "xml loaded successfully!";
gotoAndPlay("XML_done");
} else {
gotoAndPlay("Failed");
//xmlOutput.text = "xml loading erro!";
}
}


Originally if it failed to load I would loop back to frame 1 and let it keep trying to load. The other method I tried was to just let it go on to the XML_done area anyways and just hope for a delayed loading responce.... The current code *above* sends it to a failed area where I've hardcoded the default variables to use in case we can't find the XML.


The weird bug is this works great on my local machine. It works great on our development machine, but when I throw it out into production it seems to crap out half the time. I'm curious if anyone else has had problems with Flash loading an xml file before. The files sitting in the same directory as the flash file and properly configured. If anyone wants to see this streaming radio player more in depth pm me and I can see what I can do about getting you some of the source code.

RysChwith
08-25-2006, 12:15 PM
Try swapping the .load() and .onLoad statements, so that the event handler is set before it starts loading the file. It may be a timing issue.

Rys

pj_anf
08-25-2006, 12:50 PM
Alright I tried it. It'll be a day or so before I can see it on the production server to verify, but good idea by the way. I didn't try swapping those yet. I do use a few redundant checks to make sure I've grabbed the correct data from the xml later on. Such as in a function it re-grabs it just to make sure it has it correctly....

I'll let you know if this fixed it, but it's going into production with my gotoAndPlay('failed) command as well so hopefully I won't know which of the two fixed it in the end...