using variables in instance names

I am trying to create movie clips and text fields dynamically with actions script. That part is fine. But I need to know how to refer to these newly created clips.

For example if I use a loop to create 10 movie clip instances such as:

for(var i=0; i<10; i++) {
  duplicateMovieClip(_root.bar,"mc"+i,i);
}

That works fine.  Now lets say I want to change all of thier positions. How do I refer to each clip? I would assume you would do it like this but it does not work.

for(var i=0; i<10; i++) {
   setProperty (_root."mc"+i, _x, 10);
}

also, this doesn't work either:

for(var i=0; i<10; i++) {
  _root.setProperty ("mc"+i, _x, 10);
}

Basically, I need to use a variable in the object identifier like X to refer to my movie, but I have no way of saying that X is a variable. Such as; instead of mc1, mc2, mc3 ect. I could just use mcX.

Anyone know how to do this?
Thanks.


 
LVL 8
section25Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BillystyxCommented:
YOU could try:
for(var i=0; i<10; i++) {
   _root["mc"+i]. _x= 10;
}

Billystyx
0
BillystyxCommented:
or
for(var i=0; i<10; i++) {
   setProperty (_root["mc"+i], _x, 10);
}


Billystyx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BillystyxCommented:
Because its the "mc"+i that needs changing, not the whole mc. (Make sure you leave off the . after _root when doing this - that is intentional :)

Billystyx
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

section25Author Commented:
ok, thanks. I'll try that as soon as I can.
0
BillystyxCommented:
how did it go, section 25? Did you get it sorted?

Billystyx
0
section25Author Commented:
Yes, It ended up working.

Thanks.
0
BillystyxCommented:
no worries - glad to help:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.