开发者

How do I clear my stage?

I am building a website where I have one page where the user can draw on the screen. Everything works fine except for when I change from the drawing page to another page I get 开发者_StackOverflow社区this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at doodle_fla::MainTimeline/startDrawing()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at doodle_fla::MainTimeline/stopDrawing()

here is my code:

var color:Number;

stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);

function startDrawing(e:MouseEvent):void {
    stage.addEventListener(MouseEvent.MOUSE_MOVE, makeShapes);
    color = Math.random() * 0xFFFFFF;
}

function stopDrawing(e:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, makeShapes)
}

function makeShapes(e:MouseEvent):void {
        var ellipse:Ellipse = new Ellipse(10, 10, color);
        addChild(ellipse);
        ellipse.x = mouseX;
        ellipse.y = mouseY;
}

How do I clear the stage?


stage.removeEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.removeEventListener(MouseEvent.MOUSE_UP, stopDrawing);

when you leave drawing mode, but you'll have to add them back every time you switch it on

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜