# Retaining Order of Files Loaded Externally from Large XML Files

**URL:** <https://forum.kirupa.com/t/retaining-order-of-files-loaded-externally-from-large-xml-files/193739>\
**Category:** flash\
**Created:** [July 18, 2006, 6:23am UTC](https://forum.kirupa.com/t/retaining-order-of-files-loaded-externally-from-large-xml-files/193739 "2006-07-18T06:23:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [July 18, 2006, 6:23am UTC](https://forum.kirupa.com/t/retaining-order-of-files-loaded-externally-from-large-xml-files/193739/1 "2006-07-18T06:23:47Z")

</div>

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:

```auto
//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:
