How Do I Draw with Code?: Chapter 12 - ActionScript 3.0 Quick Reference Guide
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
The last line of the following code block sets any lines
subsequently drawn into the display object sp to be of 1-pixel thickness and blue in
color. The line settings for the Graphics object g remain in effect until changed or
reset.
var sp:Sprite = new Sprite(); addChild(sp); var g:Graphics = sp.graphics; g.lineStyle(1, 0x0000FF);
The first parameter is thickness, a pixel value, with 0 being a
hairline. The second parameter is the color of the line.
You also have additional optional parameters that closely mimic
the Property inspector settings. These parameters include alpha, pixelHinting (also called stroke hinting, a
Boolean to determine if the lines are drawn on the whole pixel),
scaleMode (to determine if and how
lines are scaled when the parent container is scaled), caps (specifying type of line end cap used),
joints (specifying type of joint type
used), and miterLimit (determining
how sharp corners appear).
If you want to clear everything previously drawn into the display
object, you can use the clear()
method of the Graphics class.
However, because a line isn’t drawn when a pixel thickness isn’t
specified, you can also clear just the line attributes by passing no
parameters to the lineStyle()
method.
g.lineStyle();
the section called “12.6 Defining a Fill Style” for a demonstration of
using multiple lineTo() commands to
create a triangle.
