I need to parse an XML like this:
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<pictures>
<pic>
<name>clouds1</name>
<file>clouds1.jpg</file>
<date>20/12/09</date>
</pic>
<pic>..........</pic>
....
</pictures>
using ActionScript.
I have this:
constructor{
var loader = new URLLoader(new URLRequest("data.xml"));
loader.addEventListener(Event.COMPLETE, loadedCompleteHandler);
//code that need the arrays created on the function below. This code cannot be in the function below
}
private function loadedCompleteHandler(e:Event):void
{
e.target.removeEventListener(Event.COMPLETE, loadedCompleteHandler);
_xml = XML(e.target.data);
for( var i:int = 0 ; i <= _xml.object.length() ; i++ ){
var object:XML = _xml.object[i];
nameArray[i] = object.name;
fileArray[i] = object.file;
dateArray[i] = object.date;
}
}
but I want to wait until the xml is fully loaded. It seems that when I call it in the constructor, the program makes a “thread” and continues the execution with the arrays to null because it needs more time to load.
I need to run all in the constructor.
Thank you very much
If you’re working in an Adobe AIR environment with local xml files, you can use the FileStream class to make your xml-file loading synchronous.