I'm attempting to write a class that loads multiple XML files and
broadcasts (even just to the trace window for now) when all the files
are completely loaded. I'm having some trouble with scope when within
the onLoad event of the XML object. Maybe going about this the wrong
way. See the comments witin the code below:
class com.icfconsulting.xml.XLoad{
public var complete:Boolean = false;
public var xmlObjects:Array = new Array();
private var numFiles:Number;
private var xmlFiles:Array;
private var loadCount:Number;
function XLoad(xmlFiles:Array){
this.xmlFiles = xmlFiles;
this.numFiles = this.xmlFiles.length
for(var i=0; i<this.numFiles; i++){
this.xmlObjects[i] = loadXML(i);
}
};
function loadXML(num:Number):XML{
var xmlObject = new XML();
xmlObject.ignoreWhite = true;
xmlObject.loadCount = 0;
xmlObject.onLoad = function(success:Boolean){
if(success){
//this works fine for the individual XML files,
but...
//the function on the next line never gets called because of scope (?):
checkComplete();
//so instead tried to set a property of the class instance - the problem
with the //next line is "this" is the XML instance, not the class - how
to refer to the class??
this.complete = true;
}
}
xmlObject.load(this.xmlFiles[num])
return xmlObject;
};
function checkComplete():Void{
trace("hello?");
loadCount++;
if(this.loadCount == this.numFiles){
trace("all files loaded!");
}
}
}
So what would be a better approach? Or, if I am going down the right
path, then how do I delegate an event when the xmlObject.onLoad has
success for X number of times?
Thanks for any help.
Jason Merrill | E-Learning Solutions | icfconsulting.com
NOTICE:
This message is for the designated recipient only and may contain privileged or
confidential information. If you have received it in error, please notify the
sender immediately and delete the original. Any other use of this e-mail by you
is prohibited.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com