Drawing shapes with ActionScript
You can use methods of the MovieClip class to draw lines and fills on the Stage. This allows you
to create drawing tools for users and to draw shapes in the movie in response to events. The
drawing methods are
,
lineTo()
lineStyle()
You can use the drawing methods with any movie clip. However, if you use the drawing methods
with a movie clip that was created in authoring mode, the drawing methods execute before the
clip is drawn. In other words, content that is created in authoring mode is drawn on top of
content drawn with the drawing methods.
You can use movie clips with drawing methods as masks; however, as with all movie clip masks,
strokes are ignored.
To draw a shape:
Use
1
createEmptyMovieClip()
The new movie clip is a child of an existing movie clip or of the main Timeline, as in the
following example:
_root.createEmptyMovieClip ("triangle", 1);
Use the empty movie clip to call drawing methods.
2
The following example draws a triangle with 5-point magenta lines and no fill:
with (_root.triangle) {
lineStyle (5, 0xff00ff, 100);
moveTo (200, 200);
lineTo (300, 300);
lineTo (100, 300);
lineTo (200, 200);
}
For detailed information on these methods, see their entries in
Dictionary," on page
,
beginFill()
beginGradientFill()
, and
.
moveTo()
to create an empty movie clip on the Stage.
205.
,
,
clear()
curveTo()
Chapter 12, "ActionScript
Drawing shapes with ActionScript
,
,
endFill()
131
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers