# Looping all movieclips

**URL:** <https://forum.kirupa.com/t/looping-all-movieclips/62652>\
**Category:** flash\
**Created:** [August 30, 2004, 8:31am UTC](https://forum.kirupa.com/t/looping-all-movieclips/62652 "2004-08-30T08:31:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![roady](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@roady](https://forum.kirupa.com/u/roady)\
**Post date:** [August 30, 2004, 8:31am UTC](https://forum.kirupa.com/t/looping-all-movieclips/62652/1 "2004-08-30T08:31:02Z")

</div>

Hi, I found this script on [kirupa.com](http://kirupa.com)

```auto

MovieClip.prototype.searchClip = function() {
     var j;
     for (j in this){
          if (this[j] instanceof MovieClip) {
               trace (j);
               this[j].searchClip();
          }
     }
}
_root.searchClip();

```

The problem is that it only goes into the first movieclip and then inside that goes into the first one it finds again. I need to loop thru all movieclips that lies on my scene, and if it’s posible I need to loop thru all frames as well.

Is it posible to loop thru the library instead ? and no, I can’t do it with jsfl becouse I need to do it when the site is live!

anyone that have an idea ?  
kind regards  
// me 😉

---

<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:** [August 30, 2004, 8:43am UTC](https://forum.kirupa.com/t/looping-all-movieclips/62652/2 "2004-08-30T08:43:35Z")

</div>

> [@roady](#):
>
> Hi, I found this script on [kirupa.com](http://kirupa.com)
> 
> ```auto
> 
> MovieClip.prototype.searchClip = function() {
> var j;
> for (j in this){
> if (this[j] instanceof MovieClip) {
> trace (j);
> this[j].searchClip();
> }
> }
> }
> _root.searchClip();
> 
> ```
> 
> The problem is that it only goes into the first movieclip and then inside that goes into the first one it finds again. I need to loop thru all movieclips that lies on my scene, and if it’s posible I need to loop thru all frames as well.
> 
> Is it posible to loop thru the library instead ? and no, I can’t do it with jsfl becouse I need to do it when the site is live!
> 
> anyone that have an idea ?  
> kind regards  
> // me 😉

I used this to control stuff in loaded movies, maybe it can work for you

function DoAll(container, func) {  
containerfunc;  
for (var obj in container) {  
if (typeof (container[obj]) == “movieclip”) {  
container[obj]func;  
for (var mob in container[obj]) {  
if (typeof (container[obj][mob]) == “movieclip”) {  
container[obj][mob]func;  
}  
for (var dab in container[obj][mob]) {  
if (typeof (container[obj][mob][dab]) == “movieclip”) {  
container[obj][mob][dab]func;  
}  
}  
}  
}  
}  
}  
//example of use  
DoAll(\_root, “stop”);

---

<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:** [August 30, 2004, 8:59am UTC](https://forum.kirupa.com/t/looping-all-movieclips/62652/3 "2004-08-30T08:59:04Z")

</div>

hmm, when I run it and makes some traces inside it have the same problem as the first script, it doesnt run thru all movieclips, just the firstone inline all the time, skipps the rest.

I think it’s becouse the for loop is replaced when going into another clip!!!

---

<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:** [August 30, 2004, 9:07am UTC](https://forum.kirupa.com/t/looping-all-movieclips/62652/4 "2004-08-30T09:07:21Z")

</div>

> [@roady](#):
>
> hmm, when I run it and makes some traces inside it have the same problem as the first script, it doesnt run thru all movieclips, just the firstone inline all the time, skipps the rest.
> 
> I think it’s becouse the for loop is replaced when going into another clip!!!

works for me

---

<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:** [August 30, 2004, 9:19am UTC](https://forum.kirupa.com/t/looping-all-movieclips/62652/5 "2004-08-30T09:19:18Z")

</div>

hmm, very strange, but don’t you just get down in 3 levels as well ???

the thing that I schould do is to change textfields so they don’t have anything embedded. is it posible somehow to change this in prototype or something ???

---

<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:** [August 30, 2004, 10:14am UTC](https://forum.kirupa.com/t/looping-all-movieclips/62652/6 "2004-08-30T10:14:24Z")

</div>

> [@roady](#):
>
> hmm, very strange, but don’t you just get down in 3 levels as well ???
> 
> the thing that I schould do is to change textfields so they don’t have anything embedded. is it posible somehow to change this in prototype or something ???

yes, for more levels add more loops.  
maybe something like this would work but not sure  
function DoAll(container, func) {  
for (var obj in container) {  
if (container[obj] instanceof Textfield) {  
container[obj]func;  
}  
for (var mob in container[obj]) {  
if (container[obj][mob] instanceof Textfield) {  
container[obj][mob]func;  
}  
}  
}  
}  
TextField.prototype.nofonts = function() {  
this.embedFonts = false;  
};  
DoAll(\_root, “nofonts”);

again you would have to add more loops.(Doesn`t seem such an efficient way)
