views:

134

answers:

3

Lets say I have a MC with a x position of 100. And I push it in An array

newArray.push(MC)

how can I access the array and get MC.x?

+1  A: 

Assuming you don't put any other MC in the array afterwards:

newArray[newArray.length-1].x;
Marius
+1  A: 

Assuming you'll be adding other movieclips into the array, save the movieclips position into an variable when pushing it into the array;

var mcPos:uint = newArray.push(MC) - 1;

Then access the movieclip's x with the index later with

newArray[mcPos].x
kkyy
+3  A: 

You can target it directly like Marius suggested.

newArray[ newArray.length - 1 ].x;

But if you need to do a lot of operations on the clip you might want to create a reference variable instead (a.k.a reference aliasing). This will not only speed up your code but it will also make your code more readable:

var mc : MovieClip = newArray[ newArray.length - 1 ];

mc.x = 100;
mc.y = 100;
Luke