0

我正在建立一个网站,我有一个用户可以在屏幕上绘制的页面。一切正常,除了当我从绘图页面更改到另一个页面时,我收到此错误:

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()

这是我的代码:

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;
}

如何清除舞台?

4

1 回答 1

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

离开绘图模式时,但每次打开时都必须重新添加它们

于 2011-02-05T07:41:16.937 回答