What a difference a word makes – especially when converting a String to XML in ActionScript!
OK – this isn’t a biggie but maybe it’ll help some other poor soul. Basically I’m loading XML into my swf. It’s in ActionScript 2………… lots of reasons why, but no matter. I’ve shaken the dust off my OOP AS2 muscles and got started.
I was happily loading and parseing the XML when suddenly I was told that we wouldn’t neccessarily be getting the XML from a flat file but also from a webservice. No probs, thought I gaily, all I need to do is point at the webservice and call the XML. It’s formatted exactly the same – should be fine.
Nope. Basically when I’d been loading the static XML I was casting the type to XML like this
var loadedXML:XML = XML(loadedFile);
This works fine for a flat file. However if you are loading from a webservice it ignores the xml structure of the recieved data and treats it as a single string. To fix this all you need is to amend the above to : -
var loadedXML:XML = new XML(loadedFile);