# Can't create multiple movieclips with an for loop

**URL:** <https://forum.kirupa.com/t/cant-create-multiple-movieclips-with-an-for-loop/35305>\
**Category:** Uncategorized\
**Created:** [November 12, 2003, 4:05pm UTC](https://forum.kirupa.com/t/cant-create-multiple-movieclips-with-an-for-loop/35305 "2003-11-12T16:05:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![excidium](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@excidium](https://forum.kirupa.com/u/excidium)\
**Post date:** [November 12, 2003, 4:05pm UTC](https://forum.kirupa.com/t/cant-create-multiple-movieclips-with-an-for-loop/35305/1 "2003-11-12T16:05:43Z")

</div>

Hi,  
i’m having a problem with a for loop. The problem is that it doesn’t create multiple movieclips with an unique instance, i think it copies over itself…  
I hope someone knows how to solve this!!

thnx,  
excidium

for( var i = 1, x = -20; i \< 4; i++){

```
	if(this['plaatje' +i] != undefined){
	_root.again.createEmptyMovieClip("image", i);
	this._root.again.image += _root.again["image" +i];
	
	this.plaatje = this["plaatje"+i];
	trace(this['plaatje'+ i]);
	
	plaatjeText.text += this['plaatje'+i] + newline;
	_root.again.image.loadMovie(this.plaatje +".jpg", i);
	_root.again.image._x += 50;
	trace(_root.again.image3._x);
	
	
}}
```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 12, 2003, 4:13pm UTC](https://forum.kirupa.com/t/cant-create-multiple-movieclips-with-an-for-loop/35305/2 "2003-11-12T16:13:59Z")

</div>

Hoi excidium,

from what I see you forgot to put ‘+i’ in your createEmptyMovieclip line:

[AS]  
\_root.createEmptyMovieClip(“image” **+i** , i);  
[/AS]

en welkom op het forum 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2003, 9:45am UTC](https://forum.kirupa.com/t/cant-create-multiple-movieclips-with-an-for-loop/35305/3 "2003-11-13T09:45:20Z")

</div>

Ja dank je wel!

But… it doesn’t work, I tried that already. When I insert  
’ \_root.createEmptyMovieClip(“image”+i, i);’ it doesn’t show any image anymore. Then I thought, because I use the +i in the createEmptyMovie, maybe I must delete the ’ this.\_root.again.image += \_root.again[“image” +i];’, but that doesn’t work either.  
I keep having problems with the loadmovie() when loading a php variable (it’s an url to an picture). I was really happy when it worked with createEmptyMovieClip()…but now I’m still having problems with the ‘for’ loop for creating multiple movieClips with each having another picture.

Does someone has another solution?

thnx,  
Excidium

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2003, 11:49am UTC](https://forum.kirupa.com/t/cant-create-multiple-movieclips-with-an-for-loop/35305/4 "2003-11-13T11:49:46Z")

</div>

I found out it makes the movieclips, cause when I check them seperatly like:

\_root.again.image2.loadMovie(x2 +".jpg", i);  
-\> that works.

but not when i’m trying to show them with this code:

\_root.again[image +i].loadMovie(x2 + “.jpg”, i);  
y = 150;  
\_root.again[“image” + i].\_y += -350 + y;  
-\> it shows only one image…

I have no idear how to solve this… Think I tried everything! ☹  
plz help!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 8:31am UTC](https://forum.kirupa.com/t/cant-create-multiple-movieclips-with-an-for-loop/35305/5 "2003-11-14T08:31:55Z")

</div>

the right code:

for( var i = 0, x = -20; i \<7; i++){

```
	if(this['plaatje' +i] != undefined){
	
	_root.again.createEmptyMovieClip("image"+i, i);
	
	trace(i)
	this.plaatje = this["plaatje"+i];
	trace(this['plaatje'+ i]);
	
	plaatjeText.text += this['plaatje'+i] + newline;
	x = 50;
	y = 150;
	
	_root.again["image"+i].loadMovie(this["plaatje" + i] +".jpg", i);
	
	_root.again["image" +i]._xscale = 50;
	_root.again["image" +i]._yscale = 50;
	_root.again["image" +i]._x += 100*i;
	_root.again["image" +i]._y += 100*i;

	
}}

```

thnx for replying,  
excidium
