Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : Dynamically generating variable names


asiabackpacker
5/5/2004 9:48:57 PM
I am duplicating a movie clip,

I then want to check the position of all the duplicate movie clips, and store
each value in its own variable.

For example, the original clip is called box0, the duplicates are then called
box1,box2,box3, etc... Let's say it duplicates ten times. Then I want to have a
script that checks the y position of all ten clips, and stores each in its own
variable.

The problem is that the variable needs to be dynamically generated since I do
not know how many duplicates there will be.

If this makes sense, my initial thought was something like this:

eval("box" add thisBox add "newYpos") = eval("box" add lastBox)._y;

I was trying to dynamically generate a variable name (on the left side of that
statement), and give it a value, however, my discovery was that you cannot do
it this way.

I guess my question is how do you dynamically generate variable names? I hope
I have explained this clearly.

Also, am I using the correct syntax? A friend told me that eval() is Flash 5
syntax. Is there a better way to dynamically target a property?

Thanks in advance for any help--I know you guys always come through!
Jack.
5/5/2004 11:20:54 PM
[quoted text, click to view]

store your variables in arrays, and use a loop incrementer (ii) to
create your instance names, make a reference to each new clip (rClip).

inside movieclip box0, i have a dynamic textfield, instance name - txt,

arr1 = [];
arr2 = [];

function dup(num){
for (var ii = 1; ii <= num; ii++){
box0.duplicateMovieClip("box"+ii,ii+100);
rClip = this["box"+ii];
arr1[ii] = rClip;
rClip._y = ii*30+40;
arr2[ii] = rClip._y;
rClip.txt.text=arr1[ii]+" at "+arr2[ii];
}
};

dup(10);

hth





AddThis Social Bookmark Button