Drawing with ActionScript
541
For more information on drawing with ActionScript, see the following topics:
■
“Using drawing methods to draw lines, curves, and shapes” on page 541
■
“Drawing specific shapes” on page 543
■
“Using complex gradient fills” on page 547
■
“Using line styles” on page 548
■
“Using Drawing API methods and scripting animation” on page 554
You can find a sample source file, drawingapi.fla, in the Samples folder on your hard disk,
which shows you how to use the Drawing API in a Flash application.
■
In Windows, browse to
boot drive
\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\DrawingAPI.
■
On the Macintosh, browse to
Macintosh HD
/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/DrawingAPI.
Using drawing methods to draw lines, curves, and
shapes
You can use the Flash Drawing API to dynamically create shapes on the Stage at runtime. You
can use these shapes to dynamically mask content, apply filters to them, or animate them
around the Stage. You can also use the Drawing API to create various drawing tools, which let
users use the mouse or keyboard to draw shapes on the SWF file.
To draw a line:
1.
Create a new Flash document and save it as
line.fla
.
2.
Add the following ActionScript to Frame 1 of the Timeline:
this.createEmptyMovieClip("line_mc", 10);
line_mc.lineStyle(1, 0x000000, 100);
line_mc.moveTo(0, 0);
line_mc.lineTo(200, 100);
line_mc._x = 100;
line_mc._y = 100;
This code draws a line from 0,0 on the Stage to 200,100. The line’s
_x
and
_y
coordinates
are then modified to reposition the line to 100,100 on the Stage.
3.
Save your Flash document and select Control > Test Movie to test the SWF file.
To draw a more complex shape, continue calling the
MovieClip.lineTo()
method and draw
a rectangle, square, or oval, as the following procedures show.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...