all groups > flash actionscript > january 2005 >
You're in the

flash actionscript

group:

Is it possible to pass multiple identifier/variable names into [ ] square brackets.


Re: Is it possible to pass multiple identifier/variable names into [ ] square brackets. David Stiller
1/12/2005 3:42:29 PM
flash actionscript: var mcs = ["carNameA", "carNameB", "carNameC", "carNameD"];
for (var n = 0; n < mcs.length; n++) {
_root[mcs[n]].speed = 8;
}


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Is it possible to pass multiple identifier/variable names into [ ] square brackets. B
1/12/2005 8:10:10 PM
Let's say you have some code where you're duplicating several movie clips and
you want to be able to pass the new name of each movie clip into one line of
code that will determine the 'speed' of the duplicated clips. So here's what
the code looks like: for (i=0; i<15; i++) { carNameA = 'carA' + i; carNameB
= 'carB' + i; carNameC = 'carC' + i; carNameD = 'carD' + i; ***there are
more cars than the four below but I didn't want to put the entire code
here...*** redCar.duplicateMovieClip(carNameA, i);
blueCar.duplicateMovieClip(carNameB, i + 20);
blackCar.duplicateMovieClip(carNameC, i + 40);
greenCar.duplicateMovieClip(carNameD, i + 60); _root[carNameA].speed = 8;
_root[carNameB].speed = 8; _root[carNameC].speed = 8; _root[carNameD].speed =
8; } I'd like to combine the last four lines into one statement and I tried
doing it like the line you see below but it didn't work. _root[carNameA,
carNameB, carNameC, carNameD].speed = 8; So my question is, is there some
other way to combine the new name variables inside the bracket so that there
are fewer lines of code? Brenda
Re: Is it possible to pass multiple identifier/variable names into [ ] square brackets. dpatters8
1/12/2005 8:21:28 PM
No, but you can do the following to get them all on one line:



Re: Is it possible to pass multiple identifier/variable names into [ ] square brackets. B
1/13/2005 2:24:01 AM
Thank you Danny and David!! Both ways much better than how I was trying to do it!

AddThis Social Bookmark Button