# Display List Mask

**URL:** https://forum.kirupa.com/t/display-list-mask/267812
**Category:** flash
**Created:** [August 6, 2008, 1:41am UTC](https://forum.kirupa.com/t/display-list-mask/267812 "2008-08-06T01:41:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![BlooBoi](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@BlooBoi](https://forum.kirupa.com/u/BlooBoi)
#### Post date: [August 6, 2008, 1:41am UTC](https://forum.kirupa.com/t/display-list-mask/267812/1 "2008-08-06T01:41:40Z")

</div>

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?
