我正在建立一个网站,我有一个页面,用户可以在屏幕上绘图。一切正常,除了当我从绘图页面更改为另一个页面时,我收到此错误:
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;
}
如何清除舞台?
答案 0 :(得分:2)
stage.removeEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.removeEventListener(MouseEvent.MOUSE_UP, stopDrawing);
当您退出绘图模式时,每次打开它时都必须将它们添加回来