Multiple tweens using actionscript

Hi,

I’m relatively new at actionscript 3 and having problems creating multiple movieClips and applying tweens to them.

I want to have 40 squares animate from random starting points into set locations.

Here is my code:

import fl.transitions.Tween;
import fl.transitions.easing.*;
 
createAndAnimateSquare(0xCCCCCC,3,3);
createAndAnimateSquare(0xCCCCCC,3,28);
createAndAnimateSquare(0xCCCCCC,3,53);
createAndAnimateSquare(0xCCCCCC,3,78);
//createAndAnimateSquare(0xCCCCCC,28,3);
//createAndAnimateSquare(0xCCCCCC,28,28);
//createAndAnimateSquare(0xCCCCCC,28,53);
//createAndAnimateSquare(0xCCCCCC,28,78);
 
function createAndAnimateSquare(colour:uint,xPos:int,yPos:int):void {
 var randomX:int = Math.round(Math.random()*200); // random start x
 var randomY:int = Math.round(Math.random()*200); // random start y
 var square:Shape = new Shape();
 var square_mc:MovieClip = new MovieClip();
 
 square.graphics.beginFill(colour); 
 square.graphics.drawRect(0, 0, 1, 1);   //initial size is 1x1 changing to 22x22
 
 square_mc.addChild(square);
 this.addChild(square_mc);
 
 var myTweenX:Tween = new Tween(square_mc, "x", Strong.easeIn, randomX, xPos, 1, true);
 var myTweenY:Tween = new Tween(square_mc, "y", Strong.easeIn, randomY, yPos, 1, true);
 var myTweenWidth:Tween = new Tween(square_mc, "width", Strong.easeOut, 0, 22, 1, true);
 var myTweenHeight:Tween = new Tween(square_mc, "height", Strong.easeOut, 0, 22, 1, true);
}

Four squares animate perfectly, but any more and it seems to stop working.

Can anyone help? Don’t worry about explaining what I’ve done wrong in too much depth. Just a finger in the right direction will do.

Thanks.