Line Drawing Script on Stage doesn't work in MovieClip?
I have a little snippet of code that allows the user to create a line with the mouse, and clears the line if they end up touching the hitbox with the mouse, while they're drawing the line. It works fine when it's just thrown onto the main timeline. However, when I try to encapsulate it within a movie clip, it suddenly doesn't work. At all. Are there any suggestions as to why this is happening? Here's the code.
var drawing:Boolean;
var my_line:MovieClip = new MovieClip();
this.addChild(my_line);drawing = false;//to start with
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);function startDrawing(event:MouseEvent):void
{
//move to the correct starting position for drawing
my_line.graphics.lineStyle(3,0xFF0000);
my_line.graphics.moveTo( mouseX, mouseY);
if (drawBox.hitTestPoint(mouseX,mouseY,true))
{
drawing = true;
}}
function draw(event:MouseEvent)
{
if (drawing)
{
my_line.graphics.lineTo(mouseX,mouseY);
if (oneHitBox.hitTestPoint(mouseX,mouseY,true))
{
my_line.graphics.clear();//remove line
}
}
}function stopDrawing(event:MouseEvent)
{
drawing = false;
}
Thanks for any help you can offer!