i know it has to be something simple but i’ve been staring at it too long now to see what it is. can someone tell me why my array is empty when i trace it at the end of the script? it’s really simple code. should work fine but when i trace out my array at the end it’s empty. if i trace it inside the “textLoaded” function it’s there. any help would be greatly appreciated. pay no attention to the xmlLoader and such. it is for future functionality and to provide the length for the loop.
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("media.xml"));
var i:int;
var numbersArray:Array = new Array();
function LoadXML(e:Event):void {
xmlData = new XML(xmlLoader.data);
for (i = 0; i < xmlData.item.length(); i++) {
var countFile:String = "../song" + i + "play.txt";
var countloader:URLLoader = new URLLoader();
countloader.addEventListener(Event.COMPLETE, textLoaded);
countloader.load(new URLRequest(countFile));
function textLoaded(event:Event):void {
numbersArray.push(event.target.data);
}
}
}
trace(numbersArray);