Draw Colored Rectangle : Rectangle « Graphics « Flash / Flex / ActionScript






Draw Colored Rectangle

 
package {
  import flash.display.Sprite;
  import flash.display.Shape;
  import flash.display.Graphics;
  
  public class Rectangles extends Sprite {
    
    public function Rectangles() {
      
      drawColoredRectIn(graphics, 0xFF0000);
      
      var rect:Shape = new Shape();
      drawColoredRectIn(rect.graphics, 0xFFFF00);
      rect.x = 50;
      rect.y = 50;
      addChild(rect);
    }
    
    private function drawColoredRectIn(target:Graphics, color:int):void {
      target.lineStyle(1, 0x000000);
      target.beginFill(color);
      target.drawRect(0, 0, 100, 100);
    }
  }
}

        








Related examples in the same category

1.Draw a rectangle
2.Fill a rectangle
3.Rotating Rectangles
4.rotateChildren( ), applies the generalized code from Example 20-4. It randomly rotates all the descendants of a specified container (not just the children).
5.A rectangle in a Sprite is nested within another Sprite. Both Sprite instances are rotated 45 degrees.
6.Square