Drawing with ActionScript
543
For detailed information on these methods, see their entries in
MovieClip
in the
ActionScript 2.0 Language Reference
.
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.
Drawing specific shapes
This section shows you how to create some more flexible methods that you can use to draw
more advanced shapes, such as rounded rectangles and circles.
To create a rectangle:
1.
Create a new Flash document and save it as
rect.fla
.
2.
Add the following ActionScript code to Frame 1 of the Timeline:
this.createEmptyMovieClip("rectangle_mc", 10);
rectangle_mc._x = 100;
rectangle_mc._y = 100;
drawRectangle(rectangle_mc, 240, 180, 0x99FF00, 100);
function drawRectangle(target_mc:MovieClip, boxWidth:Number,
boxHeight:Number, fillColor:Number, fillAlpha:Number):Void {
with (target_mc) {
beginFill(fillColor, fillAlpha);
moveTo(0, 0);
lineTo(boxWidth, 0);
lineTo(boxWidth, boxHeight);
lineTo(0, boxHeight);
lineTo(0, 0);
endFill();
}
}
3.
Save your Flash document and select Control > Test Movie to test the Flash document.
Flash draws a simple green rectangle on the Stage and positions it at 100,100. To change
the dimensions of the rectangle, or its fill color or transparency, you can change those
values within the call to the
drawRectangle()
method instead of having to modify the
contents of the
MovieClip.beginFill()
method.
You can also create a rectangle with rounded corners using the Drawing API, as the following
procedure shows.
Содержание 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...