# 4 x 4px grid on stage

**URL:** <https://forum.kirupa.com/t/4-x-4px-grid-on-stage/318273>\
**Category:** flash\
**Created:** [January 15, 2011, 2:23am UTC](https://forum.kirupa.com/t/4-x-4px-grid-on-stage/318273 "2011-01-15T02:23:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unboggle](https://avatars.discourse-cdn.com/v4/letter/u/dbc845/32.png) [@unboggle](https://forum.kirupa.com/u/unboggle)\
**Post date:** [January 15, 2011, 2:23am UTC](https://forum.kirupa.com/t/4-x-4px-grid-on-stage/318273/1 "2011-01-15T02:23:11Z")

</div>

Hey everybody.

I’m new to flash and at the risk of sounding like an idiot, here goes.

My question is:

How can I divide the stage up into a grid of 4 by 4px spaces?

I’m trying to make an app that will let the user pick any one of those spaces and fill it with a color of their choice. This is so no 4 x 4px dots overlap.

So far I have some code that lets you draw a 4 by 4px dot but the dots can overlap because there is no grid:

dot.addEventListener(Event.ENTER\_FRAME, do\_stuff);  
/_dot is a movie clip of a 4x4 black dot_/  
function do\_stuff(event:Event):void  
{  
var yChange:Number = Math.round(mouseY-dot.y);  
var xChange:Number = Math.round(mouseX-dot.x);  
var yMove:Number = Math.round(yChange);  
var xMove:Number = Math.round(xChange);  
dot.y += yMove;  
dot.x += xMove;  
} // since the movie clip follows the mouse, this function lets the user see exactly where their dot will be placed

stage.addEventListener(MouseEvent.CLICK, dotcoords);  
function dotcoords (e:MouseEvent):void  
{  
var mouseXpos:Number = e.target.stage.mouseX;  
var mouseYpos:Number = e.target.stage.mouseY;  
graphics.lineStyle(1,0x000000,0);  
graphics.beginFill(0x666699)  
graphics.moveTo(mouseXpos,mouseYpos);  
graphics.lineTo(mouseXpos,mouseYpos+4);  
graphics.lineTo(mouseXpos+4,mouseYpos+4);  
graphics.lineTo(mouseXpos+4,mouseYpos);  
mouseX\_txt.text = String(mouseXpos);  
mouseY\_txt.text = String(mouseYpos);  
} // this function draws the 4x4px wherever the mouse is

Any sort of help is greatly appreciated,

Best,

Mike
