# How to use for loop to set the visible property of many movieclips

**URL:** https://forum.kirupa.com/t/how-to-use-for-loop-to-set-the-visible-property-of-many-movieclips/262376
**Category:** flash
**Created:** [June 5, 2008, 2:33pm UTC](https://forum.kirupa.com/t/how-to-use-for-loop-to-set-the-visible-property-of-many-movieclips/262376 "2008-06-05T14:33:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![alex298](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@alex298](https://forum.kirupa.com/u/alex298)
#### Post date: [June 5, 2008, 2:33pm UTC](https://forum.kirupa.com/t/how-to-use-for-loop-to-set-the-visible-property-of-many-movieclips/262376/1 "2008-06-05T14:33:00Z")

</div>

Hello,

I have many photo MovieClips that need to set visible to false, for example:

mphoto0.visible = false;  
mPhoto1.visible = false;  
mPhoto2.visible = false;  
mPhoto3.visible = false;  
mPhoto4.visible = false;  
mPhoto5.visible = false;  
…  
…  
mPhoto 50.visible = false;

How can I use the for loop to accomplish the same result with AS 3? For example:

> 

var i:Number;

for (i=0:i\<50:i++){  
xxxxxxxxxxxxx(i).visible = false;  
}

Thanks and best regards

---

<div class="post-metadata">

### Author: ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)
#### Post date: [June 5, 2008, 2:38pm UTC](https://forum.kirupa.com/t/how-to-use-for-loop-to-set-the-visible-property-of-many-movieclips/262376/2 "2008-06-05T14:38:38Z")

</div>

you could put the movieclips in an array, and loop through that array…

---

<div class="post-metadata">

### Author: ![Blouze](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@Blouze](https://forum.kirupa.com/u/Blouze)
#### Post date: [June 5, 2008, 2:42pm UTC](https://forum.kirupa.com/t/how-to-use-for-loop-to-set-the-visible-property-of-many-movieclips/262376/3 "2008-06-05T14:42:41Z")

</div>

If the container mc contains only your photo-mcs, you can simply make all of them invisible like this :

```auto
for (var i:Number = 0; i < numChildren; i++) {
    getChildAt(i).visible = false;
}

```

Cheers.

---

<div class="post-metadata">

### Author: ![unformatt](https://avatars.discourse-cdn.com/v4/letter/u/58956e/32.png) [@unformatt](https://forum.kirupa.com/u/unformatt)
#### Post date: [June 5, 2008, 5:41pm UTC](https://forum.kirupa.com/t/how-to-use-for-loop-to-set-the-visible-property-of-many-movieclips/262376/4 "2008-06-05T17:41:29Z")

</div>

You can still use the old school way:

```auto

var i:Number;
for (i=0:i<50:i++){
this['mPhoto'+i].visible = false;
}

```

However, you should store all the MovieClips in an Array when you create them, then loop through that Array.

---

<div class="post-metadata">

### Author: ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)
#### Post date: [June 6, 2008, 1:28am UTC](https://forum.kirupa.com/t/how-to-use-for-loop-to-set-the-visible-property-of-many-movieclips/262376/5 "2008-06-06T01:28:00Z")

</div>

^wait, you could still do that? cool… but yeah, storing them in an array is probably good practice.

---

<div class="post-metadata">

### Author: ![alex298](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@alex298](https://forum.kirupa.com/u/alex298)
#### Post date: [June 6, 2008, 3:47am UTC](https://forum.kirupa.com/t/how-to-use-for-loop-to-set-the-visible-property-of-many-movieclips/262376/6 "2008-06-06T03:47:50Z")

</div>

Hello all,

Thanks for your help. It is working now.

I am an old programmer, I used to use the following method(-:

> 

var i:Number;  
for(i=0;i\<50;i++){  
this[‘mPhoto’+i].visible = false;  
}

Thanks and best regards

Alex
