Howdy,
Flash CS3 - AS3
Windows XP
I’m creating some rectangles dynamically and I’d like to rotate them each 180 degrees. The problem is, when I throw the rotation on them, it seems like they are rotating around the something else’s registration point. There has to be a simple explanation but this is driving me crazy.
Desired result: 10 rectangles are created and spaced out along one y value. They are also to be rotated 180 degrees each.
Unwanted Current Result: 10 rectangles are created and spaced out but they are rotated incorrectly
This chunk of code recreates the problem perfectly.
import flash.display.Sprite;
import flash.display.Graphics;
var barHolder:Array = new Array();
var barStage:Sprite = new Sprite();
addChild(barStage);
graph();
function graph() {
for (var i:uint = 0; i<10; i++) {
drawBox(10, 230, 5, 50, 5, i);
}
for (i=0; i<barStage.numChildren; i++) {
barStage.getChildAt(i).rotation = 45;
}
}
function drawBox(xval:int, yval:int, w:int, h:int, space:int, count:int):void {
var myBar = new Shape();
myBar.graphics.beginFill(0x000000);
myBar.graphics.drawRect((xval*count) * space, yval, w, h);
myBar.graphics.endFill();
myBar.name = "bar"+count;
//barHolder[count].rotation = 45;
barStage.addChild(myBar);
}