Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Animation, Filters, and Drawings > Drawing with ActionScript > Using line styles > Setting stroke and caps styles | |||
Flash 8 includes several improvements to line drawing. New line parameters added in Flash Player 8 are pixelHinting, noScale, capsStyle, jointStyle, and miterLimit.
The following procedure demonstrates the difference between the three new caps styles in Flash Player 8: none, round, and square.
To set caps styles using ActionScript:
// Set up grid movie clip.
this.createEmptyMovieClip("grid_mc", 50);
grid_mc.lineStyle(0, 0x999999, 100);
grid_mc.moveTo(50, 0);
grid_mc.lineTo(50, Stage.height);
grid_mc.moveTo(250, 0);
grid_mc.lineTo(250, Stage.height);
// line 1 (capsStyle: round)
this.createEmptyMovieClip("line1_mc", 10);
with (line1_mc) {
createTextField("label_txt", 1, 5, 10, 100, 20);
label_txt.text = "round";
lineStyle(20, 0x99FF00, 100, true, "none", "round", "miter", 0.8);
moveTo(0, 0);
lineTo(200, 0);
_x = 50;
_y = 50;
}
// line 2 (capsStyle: square)
this.createEmptyMovieClip("line2_mc", 20);
with (line2_mc) {
createTextField("label_txt", 1, 5, 10, 100, 20);
label_txt.text = "square";
lineStyle(20, 0x99FF00, 100, true, "none", "square", "miter", 0.8);
moveTo(0, 0);
lineTo(200, 0);
_x = 50;
_y = 150;
}
// line 3 (capsStyle: none)
this.createEmptyMovieClip("line3_mc", 30);
with (line3_mc) {
createTextField("label_txt", 1, 5, 10, 100, 20);
label_txt.text = "none";
lineStyle(20, 0x99FF00, 100, true, "none", "none", "miter", 0.8);
moveTo(0, 0);
lineTo(200, 0);
_x = 50;
_y = 250;
}
The preceding code dynamically creates four movie clips and uses the Drawing API to create a series of lines on the Stage. The first movie clip contains two vertical lines, one at 50 pixels and the other at 250 pixels on the x-axis. The next three movie clips each draw a green line on the Stage and sets their capsStyle to round, square, or none.
The different caps styles appear on the Stage at runtime.
|
|
|
|