Drawing shapes with ActionScript
131
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
beginFill()
,
beginGradientFill()
,
clear()
,
curveTo()
,
endFill()
,
lineTo()
,
lineStyle()
, and
moveTo()
.
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:
1
Use
createEmptyMovieClip()
to create an empty movie clip on the Stage.
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);
2
Use the empty movie clip to call drawing methods.
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
Chapter 12, “ActionScript
Dictionary,” on page 205
.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...