Horizontal Object Placement & Alignment Formula
Posted on 31. Mar, 2009 by thornyeternity in ActionScript 3 Snippets
Space objects and place beside each other:
for(var j:Number = 1; j< containerSprite.numChildren ; j++){ //leave first where it is so start at 1
var currSprite:DisplayObject = containerSprite.getChildAt(j);
var prevSprite:DisplayObject = containerSprite.getChildAt(j-1);
currSprite.x = prevSprite.x + prevSprite.width;
}
—————————————–
Space objects equally across an area:
stage.stageWidth*(i /questionArray.length);
Notes:
- stageWidth is area to fit into
- array is amount of objects
- first would be at 0 pixels across
- last would be at stageWidth value across
- others would be ‘percentage’ thereof due to division of incrementer
This would obviously be in a loop of some sort.


