[swx] How to make flash wait for xml to load before using it

Jake Ketcheson jake at fiveht.com
Sat Mar 8 18:51:15 PST 2008


Hey everybody,

I've been having some problems trying to grab and parse xml coming back 
to me from a custom php script.. I'm relatively new to Flash and Action 
Scripting, so this may just be easily fixable..

So my problem is I send off a request to my class from flash, which is 
suppose to just return to me a simple xml string.. From there I want to 
be able to parse the string out, and loop through the children to create 
elements on the flash file..

My actionscript is as follows:

stop();
import mx.utils.Delegate;
System.security.allowDomain('*');
var checkLoadProgressInterval;
var openStores_xml
function preparexml(){
    dataHolder.serviceClass = "Store";
    dataHolder.method = "GetStoreHours";

   
    dataHolder.debug = true;

       dataHolder.loadMovie("------(removed for confidentiality 
reasons)", "GET");
    checkLoadProgressInterval = setInterval(this, "checkLoadProgress", 250);
   

   
}
function checkLoadProgress()
{
    if (dataHolder.getBytesLoaded() > 24 && (dataHolder.getBytesLoaded() 
== dataHolder.getBytesTotal()))
   {
       clearInterval(checkLoadProgressInterval);
       resultHandler(dataHolder);
   }
}
function resultHandler(event:Object)
{
    // Load is complete.
   
   
    // Display the result.
    openStores_xml = event.result;
    test.text = openStores_xml;
}
function XMLopenStores() {
   
   
    stores = [];
    opens = [];
    openStores = openStores_xml.firstChild.childNodes[0];
    total = openStores.childNodes.length;
    for (i=0; i<total; i++) {
        stores[i] = 
openStores.childNodes[i].childNodes[0].firstChild.nodeValue;

        opens[i] = 
openStores.childNodes[i].childNodes[1].firstChild.nodeValue;

    }
   
}
preparexml();
XMLopenStores();
trace(stores[1]);
trace(opens[1]);

count = 1;

storeBox0.num=0
while (count<total) {
    this.storeBox0.duplicateMovieClip("storeBox"+count, count);
    //this["storeBox"+count]._y = count*45+40
    this["storeBox"+count].num= count
    count += 1;
   

}

Now the problem is I know its returning the right data, since my test 
field gets filled with the xml coming back from the class.. But when it 
comes down to the looping of the children from the xml in 
XMLopenStores() I'm getting undefined errors from the trace().. Now I 
assume this is because its going through the loop before the data is 
actually loaded into the variable.. So how do I make it wait for that 
variable to be full of data before using it? Or am I going about this in 
an entirely incorrect way?

Thanks for any and all help you guys could provide for me!



More information about the swx mailing list