我该如何清理我的舞台?
我正在建立一个网站,其中有一个页面,用户可以在屏幕上绘图。一切正常,除了当我从绘图页面更改到另一个页面时出现此错误:
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;
}
如何清除舞台?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您离开绘图模式时,但每次打开它时都必须将它们添加回来
when you leave drawing mode, but you'll have to add them back every time you switch it on