To draw an arbitrary shape (i.e., to paint a color into the geometric area between three or more points), follow these steps:
Choose the starting point of the shape (either the default (0,0) or a point specified via moveTo( )).
Start the shape with the beginBitmapFill( ), beginFill( ), or beginGradientFill( ) method.
Draw the shape's outline with a series of lineTo( ) and/or curveTo( ) calls, the last of which should end at the starting point specified in Step 1.
Close the shape with endFill( ).
The beginFill( ) method fills the shape with a solid color; the beginGradientFill( ) method fills the shape with a gradient (a blend between two or more colors); and the beginBitmapFill( ) method fills a shape with the specified bitmap (tiled if desired).
For example, the following code draws a red triangle with a five pixel-thick black outline. Notice that the default start point (0, 0) matches the endpoint:
var triangle:Shape = new Shape(); triangle.graphics.beginFill(0xFF0000, 1); triangle.graphics.lineStyle(20); triangle.graphics.lineTo(125, 125); // Draw a line down and right triangle.graphics.lineTo(250, 0); // Draw a line up and right triangle.graphics.lineTo(0, 0); // Draw a line left triangle.graphics.endFill(); addChild(triangle);
Figure 25-4 shows the result of the preceding code.
Figure 25-4. A triangle
Notice that the corners of the triangle in Figure 25-4 are rounded. To ...