Developer Guide
298, 0, size, size / 2);, size, size / 2, size);, size, 0, size / 2);, 0, size / 2, 0);
// green circular shape; + size / 2, 0); + size, 0, 200 + size, size / 2); + size, size, 200 + size / 2, size);, size, 200, size / 2);, 0, 200 + size / 2, 0);
Drawing shapes using built-in methods
For convenience when drawing common shapes such as circles, ellipses, rectangles, and rectangles with rounded
corners, ActionScript 3.0 has methods that draw these common shapes for you. These are the
drawEllipse(), drawRect(), drawRoundRect(), and drawRoundRectComplex() methods of the Graphics class.
These methods may be used in place of the
lineTo() and curveTo() methods. Note, however, that you must still
specify line and fill styles before calling these methods.
The following example recreates the example of drawing red, green, and blue squares with width and height of 100
pixels. This code uses the
drawRect() method, and additionally specifies that the fill color has an alpha of 50% (0.5):
var squareSize:uint = 100;
var square:Shape = new Shape();, 0.5);, 0, squareSize, squareSize);, 0.5);, 0, squareSize, squareSize);, 0.5);, 0, squareSize, squareSize);;
In a Sprite or MovieClip object, the drawing content created with the graphics property always appears behind all
child display objects that are contained by the object. Also, the
graphics property content is not a separate display
object so it does not appear in the list of a Sprite or MovieClip objects children. For example, the following Sprite
object has a circle drawn with its
graphics property, and it has a TextField object in its list of child display objects:
var mySprite:Sprite = new Sprite();;, 30, 30);
var label:TextField = new TextField();
label.width = 200;
label.text = "They call me mellow yellow...";
label.x = 20;
label.y = 20;
Note that the TextField appears on top of the circle drawn with the graphics object.

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.