# Finding the 'free' sides of a square

**URL:** <https://forum.kirupa.com/t/finding-the-free-sides-of-a-square/282456>\
**Category:** flash\
**Created:** [February 22, 2009, 2:39pm UTC](https://forum.kirupa.com/t/finding-the-free-sides-of-a-square/282456 "2009-02-22T14:39:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnymeerkat](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnnymeerkat/32/1254_2.png) [@johnnymeerkat](https://forum.kirupa.com/u/johnnymeerkat)\
**Post date:** [February 22, 2009, 2:39pm UTC](https://forum.kirupa.com/t/finding-the-free-sides-of-a-square/282456/1 "2009-02-22T14:39:26Z")

</div>

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:

![](http://www.indextwo.net/images/diagram.png)

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.

```auto

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.
