Adobe® Flex® 4 Language Reference
Hide Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
flash.display 
CapsStyle 
Packageflash.display
Classpublic final class CapsStyle
InheritanceCapsStyle Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

The CapsStyle class is an enumeration of constant values that specify the caps style to use in drawing lines. The constants are provided for use as values in the caps parameter of the flash.display.Graphics.lineStyle() method. You can specify the following three types of caps:

The three types of caps: NONE, ROUND, and SQUARE.

View the examples

See also



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined By
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Public Constants
 ConstantDefined By
  NONE : String = "none"
[static] Used to specify no caps in the caps parameter of the flash.display.Graphics.lineStyle() method.
CapsStyle
  ROUND : String = "round"
[static] Used to specify round caps in the caps parameter of the flash.display.Graphics.lineStyle() method.
CapsStyle
  SQUARE : String = "square"
[static] Used to specify square caps in the caps parameter of the flash.display.Graphics.lineStyle() method.
CapsStyle
Constant Detail

NONE

Constant
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.

ROUND

Constant 
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.

SQUARE

Constant 
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.

CapsStyleExample.as

The following example uses the CapsStyleExample class to draw three parallel lines, each with a different line cap style.
  1. 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.
  2. 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.
  3. 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;
            }
        }
    }
}