0

我是新的 Flash 和动作脚本。这就是问题所在。我创建了一个简单的应用程序。并且只在舞台上添加了两个项目。一个影片剪辑对象和一个按钮对象。影片剪辑对象设置了鼠标事件侦听器以在其上绘制。但是当我绘制时,线条被绘制在影片剪辑对象后面(在舞台上),我想在对象上绘制它。这是我的代码

var write: Boolean;

write = false;
board.addEventListener(MouseEvent.MOUSE_DOWN, startWriting);
board.addEventListener(MouseEvent.MOUSE_MOVE, continueWriting);
board.addEventListener(MouseEvent.MOUSE_UP, stopWriting);
board.addEventListener(MouseEvent.MOUSE_OUT, stopWriting);
btnHide.addEventListener(MouseEvent.MOUSE_DOWN, hideBoard);

var g:Graphics = graphics;
g.lineStyle(1, 0x0000ff);   

function startWriting(e:MouseEvent):void {
    g.moveTo(mouseX, mouseY);
    write = true;
}

function continueWriting(e:MouseEvent):void {
    if(write) {
        g.lineTo(mouseX, mouseY);
    }
}

function stopWriting(e:MouseEvent):void {
    write = false;
}

function hideBoard(e:MouseEvent):void {
    if (board.visible){
        board.visible = false;
    }
    else {
        board.visible = true;
    }
}

所以问题是我如何在影片剪辑对象上绘图

4

1 回答 1

0

每个影片剪辑都有自己的图形属性。您添加的内容始终位于当前影片剪辑图形的前面。

解决方案是添加一个 Shape 作为 MovieClip 的子项:

var shape : Shape = new Shape;
addChild( shape );
var g:Graphics = shape .graphics;
g.lineStyle(1, 0x0000ff);   

function startWriting(e:MouseEvent):void {
    g.moveTo(mouseX, mouseY);
    write = true;
}

function continueWriting(e:MouseEvent):void {
    if(write) {
        g.lineTo(mouseX, mouseY);
    }
}
于 2013-09-26T14:21:20.627 回答