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."
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
No, but you can do the following to get them all on one line:
Thank you Danny and David!! Both ways much better than how I was trying to do it!
Don't see what you're looking for? Try a search.
|