Hey all
I’m very new to AS3, slowly crawling my way over from AS2. Starting from a central square Sprite, I want to randomly add squares to any of the available sides, as per this handy diagram:

The basic code I’ve scratched up is below, which just tweens out three squares from the central square. I’d like each newly-created square to potentially spit out up to two squares at a time, if two free sides are available.
package {
import flash.display.StageScaleMode;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import caurina.transitions.Tweener;
public class Square extends Sprite {
public function Square() {
stage.scaleMode = StageScaleMode.NO_SCALE;
var scene:Sprite = new Sprite();
scene.x = 450;
scene.y = 300;
addChild(scene);
var squareHolder:Sprite = new Sprite;
scene.addChild(squareHolder);
var center:Sprite = new Sprite();
center.graphics.beginFill(0xFF9900);
center.graphics.drawRoundRect(0, 0, 80, 80, 5, 5);
center.graphics.endFill();
center.x = 0;
center.y = 0;
squareHolder.addChild(center);
var i:Number = 0;
function addSquare():void {
if (i > 2) {
return;
}
var extra:Sprite = new Sprite;
extra.graphics.beginFill(0xFF9900);
extra.graphics.drawRoundRect(0, 0, 80, 80, 5, 5);
extra.graphics.endFill();
extra.x = 0;
extra.y = 0;
extra.rotation = (i * 90);
trace(extra.rotation);
squareHolder.addChild(extra);
i++;
Tweener.addTween(extra, {rotation:i * 90, time:2, transition:"easeinout", onComplete:addSquare});
}
addSquare();
}
}
}
Any advice would be very helpful, since I’m not entirely sure where to start on this problem.