【问题标题】:Draw rectangle in flash actionscript [closed]在 Flash 动作脚本中绘制矩形 [关闭]
【发布时间】:2013-02-28 03:29:03
【问题描述】:

我试图在按住鼠标时在 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();
        }

    }

}

【问题讨论】:

  • 您可能要小心您的代码,在包flash.geom 中已经有一个名为Rectangle 的类。

标签: actionscript-3 flash


【解决方案1】:

我只需要更改 actionscript 值的代码

我改变了这个:

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

到这里:

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

【讨论】:

    猜你喜欢
    • 2013-07-25
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 2014-01-13
    • 2010-12-24
    • 1970-01-01
    相关资源
    最近更新 更多