7Nov/090
Convert a Xml to an ArrayCollection in AS3
Here is a quick method to convert a xml to an array collection. Because you pass the XML url (Eg: './assets/data.xml') to the first argument you will receive the array asynchronous using the callback function. If you have already the xml content in a variable use only the code in the anonymous function at the event.COMPLETE dispatch.
static public function convertXmlToArrayCollection( xmlUrl:String, rootTag:String, repeatedElement:String, callback:Function ):void
{
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, function(e:Event):void
{
var xml:XMLDocument = new XMLDocument( e.target.data );
xml.ignoreWhite = true;
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder();
var data:Object = decoder.decodeXML( xml );
var array:Array= ArrayUtil.toArray(data[rootTag][repeatedElement]);
callback(new ArrayCollection( array ));
});
xmlLoader.load(new URLRequest(xmlUrl));
}