Maor Yichyeh
Maor Yichyeh

Reputation: 97

How do I access a movieclip inside a movieclip by it's instance name?

I have several movieclips (with the instance names my_mc0, my_mc1, ... my_mc8) inside another movieclip (instance name: main_mc). I know I can access any of the child movieclips like this: main_mc.my_mc0.whatever but since I have 9 childs there, I'd like to use a loop that goes over them. something like that :

enter code here

for (i=0;i<9;i++)
{
    this["main_mc.my_mc" + i].whatever
}

the code above doesn't work ofcourse. couldn't find the answer anywhere... any ideas?

Upvotes: 1

Views: 3433

Answers (1)

mitim
mitim

Reputation: 3201

Instead of using "this" (which I am guessing refers to the stage/root), try replacing it with whatever the containing movieclip is.

this.main_mc["my_mc" + i]

Or if main_mc is inside another movieclip (anotherClip):

this.anotherClip.main_mc["my_mc" + i]

and so forth. Hopefully you get the idea on what is going on.

Upvotes: 1

Related Questions