HELP dynamically loading LOTS of XML files at one time

A vendor has offered a data stream for elections coverage that is driving me nuts.

It’s a county-by-county data stream for a given state’s races. Each race has upwards of 250 XML files – depending on the state – one for each county’s election returns. Thankfully, the XML files for the counties in a race are numberically ordered alphabetically.

Here’s the problem – I need to dynamically read the each county’s candidate vote count from, say, 90 XML files. On the fly. The vote counts will then be used to color individual county movieclips based on the results (e.g. GOP = red, Dem = blue, etc.).

I have a script that I call when everything in the movie loads – it starts looping to call the XML files (90 or so) and begins to read the data to color the county clips. Problem is, I can’t switch to a different race (restarting the loop) without screwing up the XML calls and getting a bunch of undefined values which determine county clip colors.

Here’s the function I’m using to dynamically color the county clips (imagine 100+ XML files being pulled in using this looping function):

var loadLeadersCount:Number = 1;
var loadLeadersTotal:Number = countyList.length;
var loadLeadersData:Function = function() {
    tempCountyID = loadLeadersCount;
    // prepend zeros and other prefixes for countyIDs
    if (tempCountyID < 100 && tempCountyID >= 10) {
        tempCountyID = "110" + tempCountyID;
    } else if (tempCountyID < 10 && tempCountyID >= 1) {
        tempCountyID = "1100" + tempCountyID;
    } else {
        tempCountyID = "11" + tempCountyID;
    }
    
    xmlInitLeaders = function() {
        var xPathTemp:String = "/Vote/Race/ReportingUnit/Candidate";
        leadersCandidates = new Array();
        leadersCandidates = XPathAPI.selectNodeList(xmlDataLeaders.firstChild, xPathTemp);
        
        tempLeaderXMLNode = leadersCandidates;
        
        tempCandidateArray = new Array();
        for (var i:Number = 0; i < leadersCandidates.length; i++) {
            tempCandidateArray.push({tempParty:leadersCandidates*.attributes.Party,tempVotes:leadersCandidates*.attributes.VoteCount});
        }
        tempCandidateArray.sortOn("tempVotes", Array.DESCENDING | Array.NUMERIC);
        tempLeader = tempCandidateArray[0].tempParty;
        trace(tempLeader);
        switch (tempLeader) {
            case "Dem" :
            tempColor = new Color(this[countyList[(loadLeadersCount - 1)]]);
            tempColor.setRGB(0x0000ff);
            break;
            case "Lib" :            
            tempColor = new Color(this[countyList[(loadLeadersCount - 1)]]);
            tempColor.setRGB(0x00ff00);
            break;
            case "GOP" :            
            tempColor = new Color(this[countyList[(loadLeadersCount - 1)]]);
            tempColor.setRGB(0xff0000);
            break;
            default :
            tempColor = new Color(this[countyList[(loadLeadersCount - 1)]]);
            tempColor.setRGB(0x87676d);
            break;
        }
        loadLeadersCount++
        if (loadLeadersCount <= loadLeadersTotal) {
            loadLeadersData();
        } else {
            trace("No more counties to process!");
        }
    }
    
    xmlDataLeaders = new XML();
    xmlDataLeaders.ignoreWhite = true;
    xmlDataLeaders.onLoad = function(success:Boolean) {
        if(success) {
            xmlInitLeaders();
            trace("XML loaded!");
        } else {
            trace("XML did not load!");
        }
    }
    xmlDataLeaders.load(currentRaceXMLPath + tempCountyID + ".xml");
    trace(currentRaceXMLPath + tempCountyID + ".xml");
}

Here’s the combobox init code that sets up a listener for when someone would switch to a different set of XML files (for a different race):

// function to initialize race selection combobox
var initSelectRaceCombo:Function = function() {
    this.comboSelectRace.dataProvider = raceList;
    comboSelectRaceListener = new Object();
    comboSelectRaceListener.change = function(event_obj:Object) {
        currentRaceXMLPath = event_obj.target.selectedItem.data;
        loadState();
        loadLeadersCount = 1;
        loadLeadersData();
    }
    comboSelectRace.addEventListener("change", comboSelectRaceListener);
    currentRaceXMLPath = this.comboSelectRace.selectedItem.data;
    selectRaceClip._visible = true;
    comboSelectRace._visible = true;
    creditsAltClip._visible = true;
    loadState();
    initCounties();
    loadLeadersData();
}

Any thoughts? There’s gotta be a better way to do this, but I can’t lock down the combo box and prevent someone from switching to another race while they wait 30 - 90 seconds for the XML load loop to finish.

Thanks,
IronChefMorimoto