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.
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