EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 544

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
544 Animation, Filters, and Drawings
To create a rounded rectangle:
1. Create a new Flash document and save it as roundrect.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;
drawRoundedRectangle(rectangle_mc, 240, 180, 20, 0x99FF00, 100);
function drawRoundedRectangle(target_mc:MovieClip, boxWidth:Number,
boxHeight:Number, cornerRadius:Number, fillColor:Number,
fillAlpha:Number):Void {
with (target_mc) {
beginFill(fillColor, fillAlpha);
moveTo(cornerRadius, 0);
lineTo(boxWidth - cornerRadius, 0);
curveTo(boxWidth, 0, boxWidth, cornerRadius);
lineTo(boxWidth, cornerRadius);
lineTo(boxWidth, boxHeight - cornerRadius);
curveTo(boxWidth, boxHeight, boxWidth - cornerRadius, boxHeight);
lineTo(boxWidth - cornerRadius, boxHeight);
lineTo(cornerRadius, boxHeight);
curveTo(0, boxHeight, 0, boxHeight - cornerRadius);
lineTo(0, boxHeight - cornerRadius);
lineTo(0, cornerRadius);
curveTo(0, 0, cornerRadius, 0);
lineTo(cornerRadius, 0);
endFill();
}
}
3.
Save the Flash document and select Control > Test Movie to test the document.
A green rectangle appears on the Stage that is 240 pixels wide and 180 pixels high with
20-pixel rounded corners. You can create multiple instances of rounded rectangles by
creating new movie clips using
MovieClip.createEmptyMovieClip() and calling your
custom
drawRoundedRectangle() function.
You can create a perfect circle using the Drawing API, as the following procedure shows.

Table of Contents

Related product manuals