2013-02-28 111 views
-2

我想在按住鼠标的同时在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

你可能要小心你的代码,已经有一个叫做'Rectangle'在包'flash.geom'类。 – Marty 2013-02-28 03:49:09

回答

0

所有我需要改变的是代码为ActionScript值

我改变了这个:

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

这样:

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