I have an array. I create a loop to animate each item in that array in a random direction. Then I create an event listener so that when key is pressed, each item in array tweens from it's current position to a specific position.

Problems are:

1) I don't know the original location of each item to set up the tween (since the movement is random). Also, I would have to set up a separate tween for each item, meaning I would need to know the current position for each once they become animated through the loop. Thinking there would be a way to tell the tween to find the object's current x,y positions (by telling the loop to record the location of each object ... or to create an additional function that will collect/ track each object's position?? but not sure how to do it).

2) While my "animateShapes" function works on all the items in the array because I'm looping through them when I call this function, the tween functions (only have one in the code so far while I test) only seems to interact with the last (or first) item in the loop (it is working, just taking it to the 0,0 x position moving slowly and then going back to moving around randomly - rather than stopping at the specific position)

Here's the code:

var myShapes:Array = new Array(tl, tr, bl, br);

for each(var shape in myShapes){

var colorInfo:ColorTransform = shape.transform.colorTransform;
colorInfo.color = 0xffffff * Math.random();
shape.transform.colorTransform = colorInfo;

shape.minX = 0;
shape.minY = 0;
shape.maxX = 1024;
shape.maxY = 738;

shape.x = Math.random() * shape.maxX - shape.minX;
shape.y = Math.random() * shape.maxY - shape.minY;
shape.vel = 3;
shape.vx = Math.random() * 15 + 5;
shape.vy = Math.random() * 15 + 5;

addChild(shape);
shape.addEventListener(Event.ENTER_FRAME, animateShapes);
}

function animateShapes(evt:Event):void {
var shape:MovieClip = MovieClip(evt.currentTarget);
shape.posX += shape.velX;
shape.posY += shape.velY;

shape.x += shape.vx;
shape.y += shape.vy;

if ((shape.x + shape.width/2) >= shape.maxX) {
shape.x = shape.maxX - shape.width/2;
shape.vx *= -1;
}
else if ((shape.x - shape.width/2) <= shape.minX) {
shape.x = shape.minX + shape.width/2;
shape.vx *= -1;
}
if ((shape.y + shape.height/2) >= shape.maxY) {
shape.y = shape.maxY - shape.height/2;
shape.vy *= -1;
}
else if ((shape.y - shape.height/2) <= shape.minY) {
shape.y = shape.minY + shape.height/2;
shape.vy *= -1;
}
shape.parent.removeEventListener(Event.ENTER_FRAME , animateShapes);
stage.addEventListener(KeyboardEvent.KEY_UP, makeShapes);
}


function makeShapes(e:KeyboardEvent):void
{
shape.x = shape.vx;
shape.y = shape.vy;
var xMove:Tween = new Tween(shape, "x", Regular.easeIn, shape.vx, 450, 3, true);
var yMove:Tween = new Tween(shape, "y", Regular.easeIn, shape.vy, 450, 3, true);
stage.removeEventListener(KeyboardEvent.KEY_UP, makeShapes);
}