在flash动作中绘制矩形

时间:2013-02-28 03:29:03

标签: actionscript-3 flash

当我按住鼠标时,我正试图在Flash中绘制一个矩形。

以下是我在flash文件中的代码:

import flash.events.MouseEvent;

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 rectangle:Rectangle = new Rectangle(10,10,color);
    addChild(rectangle);
    rectangle.x = mouseX;
    rectangle.y = mouseY;
}

以下是我在actionscript 3.0课程中的内容:

package  {

    import flash.display.MovieClip; 

    public class Rectangle extends MovieClip {

        public function Rectangle(w:Number=40,h:Number=40,color:Number=0xff0000) {
            graphics.beginFill(color);
            graphics.drawRectangle(0,0,w,h);
            graphics.endFill();
        }

    }

}

1 个答案:

答案 0 :(得分:0)

我需要改变的是动作脚本值的代码

我改变了这个:

graphics.drawRectangle(0,0,w,h);

到此:

graphics.drawRect(10,10,10,10);