PDA

View Full Version : XML load times and such


GreyEskimo
07-22-2005, 12:04 AM
This is somewhat similar to a thread not 10 posts down (http://www.actionscript.org/forums/showthread.php3?t=79265), but I think the difference is large enough to warrent its own thread:

So, heres the dealy-o. I am building a package in which one of the classes loads in an xml file and does things with the info. My problem is with the loading of the actual document. The constuctor for the class is quite simple, it takes in a string that points to the wanted xml file location, and then the information is to be parsed and used. Something much like this:


class exampleClass {

var xmldoc:XML;
//Default constructor, and such
public function exampleClass(xmlFile:String) {
this.xmldoc = new XML();
this.xmldoc.ignoreWhite = true;
this.xmldoc.load(xmlFile);

//I'd like to check for if the xmldoc has been loaded
//and start to work on it now

}

}


Now, that code snipet works just fine for loading, but I need to operate on the document right after it finishes. I understand that the XML.load() dosn't halt the system, but launches a new thread, so i need a way to have the system halt at that load line in that class until the .load() is done.

I first tried a while loop:

while(!this.xmldoc.loaded){
//nothing
}


but that failed right out. I then tried a the same sort of thing with the .getBytesLoaded/.getsBytesTotal function to, also, no avail.

So thats whats going on. So I pose this question to you:

How can I force the system to wait for the .load function to finish so that I can have code operate on it right away?

Thanks very much in advance,

deadbeat
07-22-2005, 12:08 AM
Use the XML.onLoad event handler to trigger a function in the class which will operate on the XML...

K.

GreyEskimo
07-22-2005, 12:16 AM
Ah yes, i did investigate that. That works fine, but the function that one makes is called out of context of the class, different scope or something.

If I were to use that method, i'd need the function i'd create to call a function back in the class.

Any ideas?

deadbeat
07-22-2005, 12:18 AM
This link does a good job of explaining the scope issue of using XML in classes:

http://www.kirupa.com/web/xml/XMLspecificIssues3.htm

K.

GreyEskimo
07-22-2005, 02:17 AM
Brilliant! Thanks

madgett
07-22-2005, 02:46 AM
Use the Delegate option from deadbeat's link at the bottom of the page. It is the best in terms of maintaining scope across classes in a package.

I also posted an explanation on as[org] http://www.actionscript.org/forums/showthread.php3?t=75259&highlight=delegate