all groups > flash actionscript > april 2004 >
You're in the

flash actionscript

group:

targetting _mc using a variable name


targetting _mc using a variable name MaureenM
4/27/2004 8:38:03 PM
flash actionscript:
Hi There,
Here's my problem...
I have a movie clip on my main timeline with the instance name movieclip_mc.
Within movieclip_mc I have another bunch of movie clips with instance names
1_mc, 2_mc, 3_mc etc etc.
Also on my main timeline, I have an array which cycles through some data and
which sets "myvariable" equal to 1 or 2 or 3 and so on. I know this works fine.
My problem is - when my variable "_root.myvariable" equals 3, I want to get
the _x property of 3_mc.
Seems simple but I can't get it right...

I've tried variations of:
trace(_root.movieclip_mc._root.myvariable_mc._x);
I've even taken out the "_mc" from my instance and the above script to
simplify things but it hasn't worked.

Is this a problem with targetting, quotations or something more complicated?
Many thanks,
Maureen
Re: targetting _mc using a variable name stwingy
4/27/2004 10:20:33 PM
not sure these are the best choice of instance names but try this.
myVariable = 3;
Re: targetting _mc using a variable name Clukey
4/27/2004 11:23:48 PM
Hey, since flash has a problem with number being first in actionscript, you may
need to rename you mcs, and instead of the variables being 1, 2, 3, try a, b,
c. here's the code I used to get it to work:

_root.onEnterFrame = function() {
myArray = new Array(a, b, c);
wMC = myArray[random(myArray.length)];
a = _root.movieclip_mc.mc_1._x;
b = _root.movieclip_mc.mc_2._x;
c = _root.movieclip_mc.mc_3._x;
trace(wMC);
};

Hope this helps.
AddThis Social Bookmark Button