Retaining Order of Files Loaded Externally from Large XML Files

Hi everyone,
I was messing around with some old examples, and I ran into an unfinished example where several 30k-100k XML files are loaded and stored as a string into an Array. The code looks basically like:

//example input: foo.xml%zeeb.xml%blarg.xml
function loadXML(filePaths:String) {
 filesArray = filePaths.split('%');
 for (var i:Number = 0; i<filesArray.length; i++) {
  var xmlData:XML = new XML();
  xmlData.ignoreWhite = true;
  xmlData.onLoad = function(success) {
   if (success) {
    //order of files loaded is messed up here!
    parseXMLData(this, filesArray.length);
   } else {
    //trace(filesArray[1]+" failed to load!");
   }
  };
  xmlData.load(filesArray*);
 }
}

Basically, when I trace the ‘this’, the order of the files that are loaded is off. Out of about 10 tries, about 3 times the order is perfect. The remaining 7 times, the order is a bit off. Does anybody have a suggestion on how to ensure the files are loaded prior to the next file being loaded?

I tried placing a while loop that basically delays the clock for a few milliseconds, and that didn’t work either. Besides, that is not really a good solution to arbitrarily waste clock cycles. I am guessing some sort of a listener might be needed, but that is where I’ve hit a wall

Thanks!
Kirupa :thumb: