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