XML and AS2.0

Hey all,

I have this method within a class. It loads in an XML file, then attempts to call another function. For some reason however, the loadXML() does not execute. If I put a trace right before it, the trace executes. If I take that function out of the onload, it executes.

private function openXML (URL:String) {
var xmlData:XML = new XML();
xmlData.ignoreWhite = true;
xmlData.load(URL);
xmlData.onLoad = function () {
loadXML();
}
}

My overall problem is that I am trying to setup two methods, one to load in the XML, the other to populate an array with its contents. But I am unable to keep the next action from happening before the XML is done loading.

I’ve also tried doing the array loading procedures in the onload, then passing the loaded array out, but the return statement executes before the contents of the onload success function.

I’ve even tried having the loadXML function set a flag, and have the constructor sit in a while loop until it saw the flag go up, but it produces an infinite loop.

class XMLLoader {

private var loadFinished:Boolean = false; 

// The constructor funtion
public function XMLLoader (URL:String)  {
    
    openXML(URL);
    while (loadFinished == false) {
        checkLoaded();
    }
    if (loadFinished == true) {
        loadXML();
    }
    
}

private function openXML (URL:String) {
    var xmlData:XML = new XML();
    xmlData.ignoreWhite = true;
    xmlData.load(URL);
    xmlData.onLoad = function () {
        loadFinished = true;
    }
}

private function checkLoaded ():Boolean {
    if (loadFinished == false) {
        return false;
    } else {
        return true;
    }
}

private function loadXML (URL:String) {
    trace("Did it");
}

}

I’ve been at this for 12 hours straight, any suggestions? I feel like I’ve tried everything. Could a listener work in this situation, if so how?

orange_01