# Draw and hitTest

**URL:** https://forum.kirupa.com/t/draw-and-hittest/271221
**Category:** flash
**Created:** [September 19, 2008, 8:50pm UTC](https://forum.kirupa.com/t/draw-and-hittest/271221 "2008-09-19T20:50:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Charlotte17](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@Charlotte17](https://forum.kirupa.com/u/Charlotte17)
#### Post date: [September 19, 2008, 8:50pm UTC](https://forum.kirupa.com/t/draw-and-hittest/271221/1 "2008-09-19T20:50:48Z")

</div>

Hi guys, I’ve an importan question for you!  
I’m working on a flash sketchpad, an interface for the users that want to draw on internet.  
This is my simple script to draw in a rectangle that I’ve called rectangle\_mc.

```auto

package
{
	import flash.display.MovieClip;
	import flash.events.*;

	public class pencil extends MovieClip
	{
		private var clip:MovieClip; 
		private var s_Color:Number=0x000000;
		private var s_Line:Number=1;

		public function pencil()
		{
			stage.frameRate=31;

			clip=new MovieClip();
			addChild(clip);
			
			addListeners();
		}
		
		private function addListeners():void
		{
			rectangle_mc.addEventListener(MouseEvent.MOUSE_DOWN,startDraw);
			stage.addEventListener(MouseEvent.MOUSE_UP,stopDraw);
		}
		
		private function startDraw(evt:MouseEvent):void
		{
			clip.graphics.lineStyle(s_Line,s_Color); 
			clip.graphics.moveTo(mouseX,mouseY);
			clip.addEventListener(Event.ENTER_FRAME,drawing);
		}
		
		private function stopDraw(evt:MouseEvent):void
		{
			clip.removeEventListener(Event.ENTER_FRAME,drawing);
		}
		
		private function drawing(evt:Event):void
		{
			clip.graphics.lineTo(mouseX,mouseY);
		}
	}
}

```

Ok, in this way I can’t start to draw outside of this rectangle. But, while I’m drawing, I can go outside it so I have to do a test to control this problem. I’ve tried to use “hitTest” but… nothing ☹ any suggestions?  
My second problem it’s almost the same: in my rectangle I’ve a panel that the user can drag in the stage and I don’t want that he can draw on it. How can I stop him? I have to use also this time the “hitTest”?

Thank you in advance 🙂
