A simple class using the drawRect method to draw a rectangle. By default this will render a blue 10×10 (yeah, I know it is a square) and place it at position 0,0 of the stage.
package
{
import flash.display.Sprite;
public class DrawRectangle extends Sprite
{
private var xPos:Number;
private var yPos:Number;
private var rWidth:Number;
private var rHeight:Number;
private var color:uint;
public function DrawRectangle(xPos:Number=0,yPos:Number=0,rWidth:Number=10,rHeight:Number=10,color:uint=0x336699)
{
this.graphics.beginFill(color);
this.graphics.drawRect(xPos,yPos,rWidth,rHeight);
this.graphics.endFill();
}
}
}
Quick, concise, and exactly what I was looking for. Thanks.
very useful, thank you manewc.
Hmm.. how do you use this to draw the rectangle…
simply instantiating doesen’t seem to work in flash CS4, AS3
Dizzy: Add your rectangle to the display list, with addChild or AddChildAt