In the section called “12.3 Defining a Line Style”, you learned how to
define a line style, but even a closed line has no fill without
specifying a fill style. The
beginFill() method specifies a color and
opacity to fill any shapes drawn until you call the
When you use a fill, if drawn shapes aren’t closed (meaning the
line does not end at its starting point), the shapes are closed for you.
To demonstrate this effect, the following code draws a complete triangle
even though the instruction that draws the last side of the triangle is
commented out (to prevent it from drawing). If you remove the
endFill() instructions from this code, then
you see only the two lines specified, because the fill process is no
longer auto-closing the shape.
var sp:Sprite = new Sprite(); addChild(sp); sp.x = sp.y = 100; var g:Graphics = sp.graphics; g.lineStyle(2, 0xFF0000); g.beginFill(0x0000FF, 1); g.moveTo(0, -50); g.lineTo(50, 50); g.lineTo(-50, 50); //g.lineTo(0, -50); g.endFill();