Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic movieclip variables

Status
Not open for further replies.

Fion

Vendor
Sep 25, 2003
50
US
Hi all, I have come with another question for your Flash...all...knowingness...
I have a loop that reads some data from an XML file, and uses that to create a group of movieclips. Below is my code.


function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {


tempclip = attachMovie("Gallery_mc", "Index.gallery"+i, 100,{_x:292, _y:(143+(i*103)), captxt:xmlNode.childNodes.childNodes[1].firstChild.nodeValue});

createEmptyMovieClip([tempclip].image, 150);
loadMovie (xmlNode.childNodes.childNodes[0].firstChild.nodeValue, Index_mc.gallery1.image)
setProperty ([tempclip].image, _x, 25)
setProperty ([tempclip].image, _y, (50+(i*103)))


}
} else {
trace ("file not loaded!");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("photogallery.xml");



Now you can probably see my problem... when I run this loop, the tempclip variable overwrites the previous tempclip.
The purpose of my clip is to dynamically create a group of movieclips, each one below the one before it.

My question is, how can I change the name of the tempclip variable? You know, so that the first time it runs it is like tempclip0, the second time is tempclip1, etc. Or should I use an array of clips? (By the way, how would I declare an array like that?)
If you can see a better way for me to do this, please, let me know.
Thanks for your help!
 
just from a quick look i think that you prob might be the dept that the movie is created at(all the same so only the last one will show) increase the depth each time by using this
this.getNextHighestDepth()
 
Here's what I don't get. You are defining tempclip as an attachMovie command, but then are using that to define the createEmptyMovieClip instance name. This is working?

I can't really test this but it seems to me that you will need to seperate things a bit more.

Code:
function loadXML(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		image = [];
		description = [];
		total = xmlNode.childNodes.length;
		for (i=0; i<total; i++) {
			[highlight]tempclip = "Index.gallery"+i;[/highlight]
			attachMovie("Gallery_mc", [tempclip], 100, {_x:292, _y:(143+(i*103)), captxt:xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue});
			createEmptyMovieClip([tempclip].image, 150);
			loadMovie(xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue, Index_mc.gallery1.image);
			setProperty([tempclip].image, _x, 25);
			setProperty([tempclip].image, _y, (50+(i*103)));
		}
	} else {
		trace("file not loaded!");
	}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("photogallery.xml");

Might be able to help a little more if you can post the .fla and the xml (zipped).

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Womblies- Thank you! That was the problem! I knew it was just something stupid I was forgetting about. I really appreaciate it!

Pixl8r- Yes this works wonderfully. I like it as a way to consolidate my code. I actually found that you could do this in an article on macromedia's website.
 
Argh... I spoke to soon... half of it works... here is my newest code (with the variable depth added). The problem now is that the image (I put the commands that influence it in bold) is only showing the last image. Again, if I run it without the loop each one works... I'm sure it is some other dumb simple thing on my part, but I can't seem to figure it out...


function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
total = xmlNode.childNodes.length;


for (i=0; i<total; i++) {

tempclip = attachMovie("Gallery_mc", "Index.gallery"+i, 100+i,{_x:292, _y:(143+(i*103)), captxt:xmlNode.childNodes.childNodes[1].firstChild.nodeValue});
createEmptyMovieClip([tempclip].image, 10+i);
loadMovie (xmlNode.childNodes.childNodes[0].firstChild.nodeValue, [tempclip].image)
setProperty ([tempclip].image, _x, 27)
setProperty ([tempclip].image, _y,(50+(i*103)))

}
} else {
trace ("file not loaded!");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("photogallery.xml");


Thanks for all your help guys!
 
Doh, nevermind, I fixed it. Thanks for your help though guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top