Need help with LoadVars issue

Hi all.
I ve googled for 2 days and still couldnt find a solution to my problem or even an example.
Here s my issue.

I have an XML file which contains a link to a photo file and a link to a text file.
Like this…

<?xml version=“1.0”?>
<news>
<new mythumb=“thumb01.jpg” mytext=“text01.txt” />
<new mythumb=“thumb02.jpg” mytext=“text02.txt” />
.
.
.
</news>

I m using a FOR loop to read the XML file
assigning the photo to a new MOVIECLIP eachtime.

//***************************************************************************
home = this;

var xml:XML = new XML();
xml.ignoreWhite = true;

xml.load (“myXML.xml”);
xml.onLoad = function () {
var nodes = this.firstChild.childNodes;
numOfItems = nodes.length;
for (var i=0;i<numOfItems;i++) {
var news = home.attachMovie(“entry”,“entry”+i,i+1);
news.news_pic.loadMovie(“news/”+nodes*.attributes.mythumb);
}
}
//***************************************************************************

Now the problem occured when i tried to include a LoadVars (for the text file) inside the FOR loop

//***************************************************************************
loadText = new LoadVars();
loadText.load(nodes*.attributes.mytext);

loadText.onLoad = function(success:Boolean) {
if(success) {
news.news_text.htmlText = this.my_news;
}else{
trace(“Error”);
}
}
//***************************************************************************

If I place the code inside the FOR loop as is, it only reads the last text file of XML
and the rest of the textfields are blank.
I tried some other ways but no luck.
i have either the first text correct, or the last or just “undefined”,
but always one of the text blocks. Never all of them.
The photos appear correctly every time.

Any ideas how I should do this ?
Thanks in advance

I believe you’re over-writing your loadVars instance in that for loop… I’d move the load vars into its own function and pass a few arguments - like the mc it needs to target. I didn’t test this, so not sure this will work - this would be a great place to implement the flash mx.utils.Delegate class by the way, but won’t get in to that for now:




function loadTextFile(targ:MovieClip, path:String):Void {

	var loadText:LoadVars = new LoadVars();

	loadText.onLoad = function(success:Boolean) {
		if(success) {
			//this may fail, try tracing targ and see what it shows
			trace(targ);
			trace(this.my_news);
			targ.news_text.htmlText = this.my_news;
		}else{
			trace("Error");
		}
	}
	
	loadText.load(path);	
}

// ---------------------------------------
// then in your loop try calling this:
// ---------------------------------------



for (var i=0;i<numOfItems;i++) {
	var news = home.attachMovie("entry","entry"+i,i+1);
	news.news_pic.loadMovie("news/"+nodes*.attributes.mythumb);	
	loadTextFile(news, nodes*.attributes.mytext);
}

Dear Creatify,
with a tiny adjustment to the path of the textfile it worked just fine.
I really really thank you for your help.
Greetings to San Dieho from Athens (Greece)

ooops, “San Diego” I mean… :slight_smile: