section25
asked on
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.b ar,"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.
For example if I use a loop to create 10 movie clip instances such as:
for(var i=0; i<10; i++) {
duplicateMovieClip(_root.b
}
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Billystyx
ASKER
ok, thanks. I'll try that as soon as I can.
how did it go, section 25? Did you get it sorted?
Billystyx
Billystyx
ASKER
Yes, It ended up working.
Thanks.
Thanks.
no worries - glad to help:)
for(var i=0; i<10; i++) {
_root["mc"+i]. _x= 10;
}
Billystyx