AS3 / XML Loading
- Started
- Last post
- 6 Responses
- StratusGD
So, I'm trying to work with the XMLLoader from http://kirupa.com/developer/flas…
Here's the problem: I'd like to return xmlData, so I can call the function like so: var my_xml:XML = XMLLoader("test.xml"); and not have to duplicate the code unnecessarily for each XML file I need to load.
I've got in in the right package and it's accessible in my other classes. I can't just slap the return(xmlData); line at the end because then it returns a null value, since it's not loaded yet (I think). A trace in the same location returns a null value as well. I can trace xmlData in the LoadXML function, and it works fine, but I can't return it from there.
Any ideas? Or do I fail at making sense?
- ondo0
try this (ive not tested it tho)
function LoadXML(e:Event):XML{
xmlData = new XML(e.target.data);
return xmlData;
}
- mikotondria20
ah that returning a null value will kill you.
Why is it null ? So what ? I find myself screaming at it.
Ondo's suggestion looks right, and makes sense when you finally arrive at that after pulling your hair out for the 50th time.
- ondo0
whats exactly the error? is it says that LoadXML does not return anything then it means e.target.data is empty - are you sure the xml file you load is valid?
(you also need to use this with the other code on the kirupa example - but im sure you know this!)
- ondo0
you might want to check this xml to object class
http://mediumrare.za.net/blog/?p…
- StratusGD0
I think I wasn't clear in my first post, so check out this pastebin link: http://pastebin.com/m7b921d5c
If I go with your suggestion, I get an error that the function XMLLoader isn't returning any data.
If I just add code to trace & return xmlData at the end of the XMLLoader function (on the followup post @ pastebin), it returns 'null' because the file isn't actually loaded yet.
Any clearer?