MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 545

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To create a circle:
1.
Create a new Flash document and save as circle2.fla.
2.
Add the following ActionScript code to Frame 1 of the Timeline:
this.createEmptyMovieClip("circle_mc", 10);
circle_mc._x = 100;
circle_mc._y = 100;
drawCircle(circle_mc, 100, 0x99FF00, 100);
function drawCircle(target_mc:MovieClip, radius:Number,
fillColor:Number, fillAlpha:Number):Void {
var x:Number = radius;
var y:Number = radius;
with (target_mc) {
beginFill(fillColor, fillAlpha);
moveTo(x + radius, y);
curveTo(radius + x, Math.tan(Math.PI / 8) * radius + y,
Math.sin(Math.PI / 4) * radius + x, Math.sin(Math.PI / 4) * radius +
y);
curveTo(Math.tan(Math.PI / 8) * radius + x, radius + y, x, radius +
y);
curveTo(-Math.tan(Math.PI / 8) * radius + x, radius+ y, -
Math.sin(Math.PI / 4) * radius + x, Math.sin(Math.PI / 4) * radius +
y);
curveTo(-radius + x, Math.tan(Math.PI / 8) * radius + y, -radius +
x, y);
curveTo(-radius + x, -Math.tan(Math.PI / 8) * radius + y, -
Math.sin(Math.PI / 4) * radius + x, -Math.sin(Math.PI / 4) * radius +
y);
curveTo(-Math.tan(Math.PI / 8) * radius + x, -radius + y, x, -radius
+ y);
curveTo(Math.tan(Math.PI / 8) * radius + x, -radius + y,
Math.sin(Math.PI / 4) * radius + x, -Math.sin(Math.PI / 4) * radius +
y);
curveTo(radius + x, -Math.tan(Math.PI / 8) * radius + y, radius + x,
y);
endFill();
}
}
3.
Save your Flash document and select Control > Test Movie to test the SWF file.
This code creates a more complex, and realistic, circle than the previous circle example.
Instead of only using four calls to the
method, which gives the shape a much rounder appearance.
curveTo()
You can use the Drawing API to create a triangle, as the following procedure shows.
method, this example uses eight calls to the
curveTo()
Drawing with ActionScript
545

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents