public static const NONE:String = "none"
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Used to specify no caps in the caps
parameter of the
flash.display.Graphics.lineStyle()
method.
public static const ROUND:String = "round"
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Used to specify round caps in the caps
parameter of the
flash.display.Graphics.lineStyle()
method.
public static const SQUARE:String = "square"
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Used to specify square caps in the caps
parameter of the
flash.display.Graphics.lineStyle()
method.
The following example uses the
CapsStyleExample
class to draw three
parallel lines, each with a different line cap style.
- The properties of each line are set as follows:
- The line length is set to 80 pixels.
- The border color is set to orange.
- The border size is set to 30 pixels.
- The highlight color is set to gray.
- The highlight size is set to 0 pixels.
- The alpha is set to 1, making it solid.
- The pixel hinting is set to false (strokes not hinted to full pixels).
- The line scale mode is set to normal, which scales the thickness.
- The joint style of the border caps are set to
MITER
. - The miter limit is set to 1, indicating that the miter is cut off close to the line.
- The class constructor creates three vertical lines, starting at x = 0, y = 0 by calling
the
drawLine()
method three times using the three different line cap styles (none,
round, and square). Each of the three calls to the drawLine()
method uses the cap style and
properties listed previously to draw a vertical line and associated line highlight. The calls
first create a new child
Shape object and then use methods of the Graphics
class to set the line style and draw the lines and highlights. Each instance of child
is added to the display list and drawn on the stage. - The connected line segments are redrawn by using the
refreshLayout()
method at y = 80
pixels and starting at x = 80 pixels, with a 25-pixel separation between the line segments.
package {
import flash.display.CapsStyle;
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.JointStyle;
import flash.display.LineScaleMode;
import flash.display.Shape;
import flash.display.Sprite;
public class CapsStyleExample extends Sprite {
private var lineLength:uint = 80;
private var borderColor:uint = 0xFFCC00;
private var borderSize:uint = 30;
private var highlightColor:uint = 0x666666;
private var highlightSize:uint = 0;
private var gutter:uint = 25;
private var borderAlpha:uint = 1;
private var borderPixelHinting:Boolean = false;
private var borderScaleMode:String = LineScaleMode.NORMAL;
private var borderJointStyle:String = JointStyle.MITER;
private var borderMiterLimit:uint = 1;
public function CapsStyleExample() {
drawLine(CapsStyle.NONE);
drawLine(CapsStyle.ROUND);
drawLine(CapsStyle.SQUARE);
refreshLayout();
}
private function drawLine(capsStyle:String):void {
var child:Shape = new Shape();
child.graphics.lineStyle(borderSize,
borderColor,
borderAlpha,
borderPixelHinting,
borderScaleMode,
capsStyle,
borderJointStyle,
borderMiterLimit);
child.graphics.lineTo(0, 0);
child.graphics.lineTo(0, lineLength);
child.graphics.endFill();
child.graphics.moveTo(0, 0);
child.graphics.lineStyle(highlightSize, highlightColor);
child.graphics.lineTo(0, 0);
child.graphics.lineTo(0, lineLength);
addChild(child);
}
private function refreshLayout():void {
var ln:uint = numChildren;
var child:DisplayObject;
var lastChild:DisplayObject = getChildAt(0);
lastChild.x = lineLength;
lastChild.y = lineLength;
for (var i:uint = 1; i < ln; i++) {
child = getChildAt(i);
child.x = gutter + lastChild.x + lastChild.width;
child.y = lineLength;
lastChild = child;
}
}
}
}