4.1. Drawing a Line
Problem
You want to draw a line using ActionScript.
Solution
Use the lineStyle( ) method to
specify
the thickness, color, and transparency
of the line. Then use the lineTo( ) method to
draw a line from the current pen
position to a destination point.
Discussion
Before you can draw anything using ActionScript, you need to tell
Flash what kind of line style to use. The line style
consists of the
line’s thickness, color, and alpha value (opacity),
and you can set these values using the lineStyle(
) method on the movie clip in which you wish to draw. The
line’s thickness should be specified in pixels, but
any value less than 1 draws lines with hairline thickness. Color
values should be specified as numbers, as explained in the Introduction
to ???. The alpha
value should be anywhere from 0 (completely transparent) to 100
(completely opaque).
// Set a 1-pixel, blue, completely opaque line style. myMovieClip_mc.lineStyle(1, 0x0000FF, 100);
The most basic type of drawing that you can do with ActionScript is
drawing a straight line. Flash uses the current pen
position
as the starting point, so you need to provide only the coordinates of
the destination point. Use
the MovieClip.lineTo( )
method to create a line from the current pen position to the
specified destination point:
// Draws a line from the current pen position to (100,100) within the coordinate
// system of myMovieClip_mc.
myMovieClip_mc.lineTo(100, 100);When you use ActionScript methods to draw, all the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access