# Restraining drawing api to a certain area

**URL:** <https://forum.kirupa.com/t/restraining-drawing-api-to-a-certain-area/288313>\
**Category:** flash\
**Created:** [May 14, 2009, 1:20am UTC](https://forum.kirupa.com/t/restraining-drawing-api-to-a-certain-area/288313 "2009-05-14T01:20:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hano](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@Hano](https://forum.kirupa.com/u/Hano)\
**Post date:** [May 14, 2009, 1:20am UTC](https://forum.kirupa.com/t/restraining-drawing-api-to-a-certain-area/288313/1 "2009-05-14T01:20:27Z")

</div>

I’m trying to create a drawing application in flash CS4, but I need the viewers to draw in a certain area only, and I want the cursor to change into a brush when I am hovering over that certain area.  
I tried adding an if statement to check if the cursor is in that certain area, but now it doesn’t draw at all. Please help.

stop();

var drawIt:Boolean = false;  
var startX:Number;  
var startY:Number;

var strokeWidth = 3;  
var strokeColor = 0x000000

var canvas:MovieClip = new MovieClip();  
addChild(canvas);  
var myLine:Graphics = canvas.graphics;  
myLine.lineStyle(strokeWidth, strokeColor, 1);

stage.addEventListener(MouseEvent.MOUSE\_DOWN, startDraw);  
stage.addEventListener(MouseEvent.MOUSE\_UP, stopDraw);  
stage.addEventListener(Event.ENTER\_FRAME, drawLine);

function startDraw(e:MouseEvent){  
[COLOR=“Red”]if (( x \> 500 && x \< 900) && (y \> 200 && y \< 450))[/COLOR]  
{drawIt = true;

```
startX = mouseX;
startY = mouseY;
myLine.moveTo(startX, startY);}

```

}

function stopDraw(e:MouseEvent){  
drawIt = false;  
}

function drawLine(e:Event){  
if (drawIt) {  
var newX = mouseX;  
var newY = mouseY;  
// see if location has changed  
if ((newX != startX) || (newY != startY)) {  
// draw line to new location  
myLine.lineTo(newX, newY);  
// reset location for new time  
startX = newX;  
startY = newY;  
}  
}  
}
