flash.display

# CapsStyle - AS3

Package | flash.display
Class | public final class CapsStyle
Inheritance | CapsStyle Object

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9

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:

View the examples

Related API Elements

flash.display.Graphics.lineStyle()

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Public Constants

| Constant | Defined 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: | AIR 1.0, Flash Player 9

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: | AIR 1.0, Flash Player 9

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: | AIR 1.0, Flash Player 9

Used to specify square caps in the `caps` parameter of the `flash.display.Graphics.lineStyle()` method.

Examples How to use this example
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.

Copy

    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;
                }
            }
        }
    }

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00