Array of movie clips ActionScript 3

iDomo picture iDomo · Jan 7, 2012 · Viewed 14.2k times · Source

How would I go about making an array of movie clips?

If you could include an example with the setting of one part of the array, that would be great :)

Answer

ToddBFisher picture ToddBFisher · Jan 7, 2012

(untested code)

//Create array of movie clips
var someArray:Array = new Array(mc1,mc2,mc3,mc4);

//Access certain movie clip, in this case mc3
someArray[2].visible = false;

Also consider using a vector, it is generally faster.

//Declare a vector
var someVector:Vector.<MovieClip> = new Vector.<MovieClip>();
//Add movie clips
someVector.push(mc1);
someVector.push(mc2);
someVector.push(mc3);
someVector.push(mc4);

To access them I would do it like this:

var tempMC:MovieClip = someArray[1]; // or = someVector[1];
tempMC.x = 30;
tempMC.width = 300;

or you can just say:

MovieClip(someArray[1]).x = 30;

or the lazy way as shown on the 2nd line of code above.