import flash.display.*;
import flash.net.URLRequest;
var rect:Shape = new Shape();
rect.graphics.beginFill(0xFFFFFF);
rect.graphics.drawRect(0, 0, 50, 50);
rect.graphics.endFill();
var columns:int = 2;
var rows:int = 2;
var startX:Number = 0;
var startY:Number = 0;
var boxIndex:int = 0;
for(var j:int = 0; j < columns; ++j){
startX = 0;
for(var i:int = 0; i < rows; ++i){
var box:Sprite = new Sprite();
boxIndex = boxIndex + 1;
box.name = "box"+ boxIndex;
box.x = rect.x = startX;
box.y = rect.y = startY;
box.graphics.lineStyle(4, 0xFF66CC);
box.graphics.beginFill(0x990066);
box.graphics.drawRect(0, 0, 75, 75);
box.graphics.endFill();
startX += box.width + 20;
box.mask = rect;
addChild(box);
}
startY += box.height + 20;
trace(startY);
}
I’ve been playing around with this code displaying squares in rows and columns. As it loops through to add the squares in rows and columns I tried masking the squares. The mask only works on the last square in the grid; I can’t seem to figure out why. The code above can be copied and pasted to a frame in as3 and it will work. Can somebody please help?