?
Solved

using variables in instance names

Posted on 2005-03-24
7
Medium Priority
?
174 Views
Last Modified: 2010-04-03
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
Comment
Question by:section25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 18

Expert Comment

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

Billystyx
0
 
LVL 18

Accepted Solution

by:
Billystyx earned 500 total points
ID: 13622692
or
for(var i=0; i<10; i++) {
   setProperty (_root["mc"+i], _x, 10);
}


Billystyx
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13622710
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Author Comment

by:section25
ID: 13625086
ok, thanks. I'll try that as soon as I can.
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13770398
how did it go, section 25? Did you get it sorted?

Billystyx
0
 
LVL 8

Author Comment

by:section25
ID: 13771165
Yes, It ended up working.

Thanks.
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13771257
no worries - glad to help:)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question