我该如何清理我的舞台?

发布于 2024-10-16 08:06:28 字数 996 浏览 3 评论 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;
}

如何清除舞台?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸩远一方 2024-10-23 08:06:28
stage.removeEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.removeEventListener(MouseEvent.MOUSE_UP, stopDrawing);

当您离开绘图模式时,但每次打开它时都必须将它们添加回来

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文