Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

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.


 
0
section25
Asked:
section25
  • 5
  • 2
1 Solution
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now