# XML, Looping & Duplicating MovieClips - a tale of terror and intrique

**URL:** <https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239>\
**Category:** Uncategorized\
**Created:** [June 24, 2008, 10:23am UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239 "2008-06-24T10:23:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![thedaveyb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thedaveyb](https://forum.kirupa.com/u/thedaveyb)\
**Post date:** [June 24, 2008, 10:23am UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/1 "2008-06-24T10:23:25Z")

</div>

well not really… i am trying to populate an MC/text field via XML and the duplicate this underneath itself (in a loop) for how ever many lines of the xml there are… Ive got quite far _in my humble opnion_ but seem to have come unstuck on the looping and duplicating…

My code only duplicates the movieclip once - and the second movieclip is not populated (ie pulling data from the xml) only the first one is!..

```auto

function loadXML(loaded) {
 if (loaded) {
  xmlNode = this.firstChild;
  clname = [];
  image = [];
  total = xmlNode.childNodes.length;
  for (i=0; i<total; i++) {
   clname* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
   image* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
  }
  loadceleb();
  //trace(clname[2]);
 } else {
  content = "file not loaded!";
 }
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("celebs.xml");

function loadceleb() {
  for (i=0; i<total; i++) {
  duplicateMovieClip("chold", "chold"+*, *);     
  setProperty ( "chold"+*, _y, "55");
  _root.chold.text_hold = clname*;
 } 
}

```

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 24, 2008, 10:45am UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/2 "2008-06-24T10:45:26Z")

</div>

most non-silly people **attachMovie()** within the for loop

also they don’t use root, and increment the instance name

\_root.chold.text\_hold = clname\*; **\<\< wrong**

\*_[“chold”+i].textField.text = \_root.clname_; \*\*

see the way I do it \_root is ok lol

---

<div class="post-metadata">

**Author:** ![thedaveyb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thedaveyb](https://forum.kirupa.com/u/thedaveyb)\
**Post date:** [June 24, 2008, 10:57am UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/3 "2008-06-24T10:57:58Z")

</div>

thanks - i get half of that - still only loops twice though when there are four entries in the XML?.

I tried your way of setting the text and that just gave me ‘Unexpected ‘.’ encountered’

Also tried attachMovie() out of curiosity to see how that worked out and that didnt loop at all…

‘a little more knowledgeable / a little more confused’

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 24, 2008, 11:09am UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/4 "2008-06-24T11:09:18Z")

</div>

\*\*check total!! trace statements \*\*

(yup you need to specify the full path, starting with [] mucks it up)

here’s an example from a file, your setProperty might be mucking things up

you have enabled AS linkages for the file your duplicating?

```auto
 
 
home.testing.gah.attachMovie("test", "but"+i, home.testing.gah.getNextHighestDepth());
  home.testing.gah["but"+i]._x = 0;
  //trace(home.testing.gah["but"+i]._height);
  vheight = home.testing.gah["but"+i]._height;
  home.testing.gah["but"+i]._y = (vheight+2.6)*i;
  home.testing.gah["but"+i].itemBut.dynt.text = "Part "+(i+1);
  home.testing.gah["but"+i].itemBut.desc.text = videos*.attributes.desc;
  _level0.testing.gah["but"+i].itemBut.clicked._visible = false;

```

---

<div class="post-metadata">

**Author:** ![thedaveyb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thedaveyb](https://forum.kirupa.com/u/thedaveyb)\
**Post date:** [June 24, 2008, 11:30am UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/5 "2008-06-24T11:30:00Z")

</div>

ok we have progress!. (as linkage is on and named, total is traced at 4 and the text field is populated with the first item of my array… woot)…

although its still not looping/duplicating…

```auto

function loadceleb() {
		for (i=0; i<total; i++) {			 
			attachMovie("chold", "chold"+i,i);		
			setProperty ( "chold"+i, _y, "5"); 	
			_level0["chold"+i].text_hold= _root.clname*; 
	}
}

```

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 24, 2008, 11:41am UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/6 "2008-06-24T11:41:07Z")

</div>

post the flipping fla 😛

---

<div class="post-metadata">

**Author:** ![thedaveyb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thedaveyb](https://forum.kirupa.com/u/thedaveyb)\
**Post date:** [June 24, 2008, 11:43am UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/7 "2008-06-24T11:43:40Z")

</div>

attached - this is the part where you say it was something simple and label me a numpty hey?

_hides under desk_

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 24, 2008, 12:09pm UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/8 "2008-06-24T12:09:07Z")

</div>

_ponders how to put this…_

**Key fault 1** : **READ MY POSTS:m:,** you are english right? setProperty doesn’t work in this situation or at least the way you have coded it

**Key Fault 2:** where you’ve mucked up is you are trying to apply fancy animation to text, hence you have placed it as a graphic instead of an MC and wound up with tweens

the way I can think of is having two textfields the same, one black-one white, and fading each other out

**HOWEVER** not on the timeline, you will have to use **tween class** , else you are going to loose your variables everytime you tween something manually.

**[SIZE=7]NB[/SIZE]**  
I don’t see why I should help someone get paid for work they are not doing… I am doing

---

<div class="post-metadata">

**Author:** ![thedaveyb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thedaveyb](https://forum.kirupa.com/u/thedaveyb)\
**Post date:** [June 24, 2008, 12:16pm UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/9 "2008-06-24T12:16:06Z")

</div>

apologies, i had added setProperty in and out a few times during trial and error testing!.

Note taken on the animation - i had been trying to break everything down to as simple as possible to have the best possible chance of understanding/learning what i was doing.

will see what i can do.

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 24, 2008, 12:18pm UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/10 "2008-06-24T12:18:00Z")

</div>

there are examples up and down kirupa

[gotoandlearn.com](http://gotoandlearn.com) etc

on this issue I just don’t see why you haven’t looked

---

<div class="post-metadata">

**Author:** ![thedaveyb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thedaveyb](https://forum.kirupa.com/u/thedaveyb)\
**Post date:** [June 24, 2008, 12:23pm UTC](https://forum.kirupa.com/t/xml-looping-duplicating-movieclips-a-tale-of-terror-and-intrique/264239/11 "2008-06-24T12:23:34Z")

</div>

thanks for your help.
