Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3:实时绘图?_Actionscript 3_Drawing - Fatal编程技术网

Actionscript 3 AS3:实时绘图?

Actionscript 3 AS3:实时绘图?,actionscript-3,drawing,Actionscript 3,Drawing,我有一个奇怪的问题,如果我在移动鼠标(mouse\u MOVE)时使用graphics.lineTo,这些线是实时创建的。但是如果我将其更改为“鼠标向下移动”(MOUSE\u DOWN),则线条是直线的,如果鼠标仍被按下,则线条没有响应 下面是一个例子: stage.addEventListener(MouseEvent.MOUSE_MOVE, follow); stage.addEventListener(MouseEvent.MOUSE_DOWN, draw)

我有一个奇怪的问题,如果我在移动鼠标(mouse\u MOVE)时使用graphics.lineTo,这些线是实时创建的。但是如果我将其更改为“鼠标向下移动”(MOUSE\u DOWN),则线条是直线的,如果鼠标仍被按下,则线条没有响应

下面是一个例子:

        stage.addEventListener(MouseEvent.MOUSE_MOVE, follow);
        stage.addEventListener(MouseEvent.MOUSE_DOWN, draw);


    private function follow(e:MouseEvent){

        trace(e.localY);

        activeChalk.x = e.stageX;
        activeChalk.y = e.stageY;

    }


    private function draw(e:MouseEvent){

        trace(e.localY);

        activeChalk.x = e.stageX;
        activeChalk.y = e.stageY;
        board.graphics.lineTo(e.stageX,e.stageY);
    }
编辑:我使用以下示例成功地使其正常工作:

您的应用程序在许多方面存在根本性缺陷

这里不是详细介绍,而是一个非常简单的绘图实现:

package
{
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.MouseEvent;
    import flash.geom.Point;

    [SWF(percentWidth = 100, percentHeight = 100, backgroundColor = 0xefefef, frameRate = 30)]
    public class Chalk extends Sprite
    {

        protected var lastPoint:Point;

        public function Chalk()
        {
            super();

            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            initializeDrawing();
        }

        protected function initializeDrawing():void
        {
            stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
        }

        protected function mouseDownHandler(event:MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

            // mark mouse down location
            lastPoint = new Point(mouseX, mouseY);

            // listen for movement or up/out
            stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
            stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
            stage.addEventListener(MouseEvent.MOUSE_OUT, mouseUpHandler);
        }

        protected function mouseMoveHandler(event:MouseEvent):void
        {
            var g:Graphics = graphics;
            g.lineStyle(1, 0x0000ff);

            // draw line segment
            g.moveTo(lastPoint.x, lastPoint.y);
            g.lineTo(mouseX, mouseY);

            // mark end of line segment
            lastPoint = new Point(mouseX, mouseY);
        }

        protected function mouseUpHandler(event:MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
            stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
            stage.removeEventListener(MouseEvent.MOUSE_OUT, mouseUpHandler);

            // prepare for next line
            initializeDrawing();
        }

    }
}

这并不奇怪,单击鼠标时会发送一个鼠标按下事件,之后会发送鼠标移动事件


您可以简单地跟踪事件以准确了解发生了什么。

谢谢,非常具有描述性,制作精良!