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