View comments | RSS feed

lineStyle (MovieClip.lineStyle method)

public lineStyle(thickness:Number, rgb:Number, alpha:Number, pixelHinting:Boolean, noScale:String, capsStyle:String, jointStyle:String, miterLimit:Number) : Void

Specifies a line style that Flash uses for subsequent calls to the lineTo() and curveTo() methods until you call the lineStyle() method with different parameters. You can call lineStyle() in the middle of drawing a path to specify different styles for different line segments within a path.

Note: Calls to the clear() method set the value of line style back to undefined.

You can extend the methods and event handlers of the MovieClip class by creating a subclass.

Availability: ActionScript 1.0; Flash Player 6 - Additional parameters pixelHinting, noScale, capsStyle, jointStyle, and miterLimit are available in Flash Player 8.

Parameters

thickness:Number - An integer that indicates the thickness of the line in points; valid values are 0 to 255. If a number is not specified, or if the parameter is undefined, a line is not drawn. If a value of less than 0 is passed, Flash Player uses 0. The value 0 indicates hairline thickness; the maximum thickness is 255. If a value greater than 255 is passed, the Flash interpreter uses 255.

rgb:Number - A hexadecimal color value of the line; for example, red is 0xFF0000, blue is 0x0000FF, and so on. If a value isn't indicated, Flash uses 0x000000 (black).

alpha:Number - An integer that indicates the alpha value of the line's color; valid values are 0 to 100. If a value isn't indicated, Flash uses 100 (solid). If the value is less than 0, Flash uses 0; if the value is greater than 100, Flash uses 100.

pixelHinting:Boolean - Added in Flash Player 8. A Boolean value that specifies whether to hint strokes to full pixels. This value affects both the position of anchors of a curve and the line stroke size itself. If a value is not indicated, Flash Player does not use pixel hinting.

noScale:String - Added in Flash Player 8. A string that specifies how to scale a stroke. Valid values are as follows:

capsStyle:String - Added in Flash Player 8. A string that specifies the type of caps at the end of lines. Valid values are: "round", "square", and "none". If a value is not indicated, Flash uses round caps.

For example, the following illustrations show the different capsStyle settings. For each setting, the illustration shows a blue line with a thickness of 30 (for which the capsStyle applies), and a superimposed black line with a thickness of 1 (for which no capsStyle applies):



jointStyle:String - Added in Flash Player 8. A string that specifies the type of joint appearance used at angles. Valid values are: "round", "miter", and "bevel". If a value is not indicated, Flash uses round joints.

For example, the following illustrations show the different capsStyle settings. For each setting, the illustration shows an angled blue line with a thickness of 30 (for which the jointStyle applies), and a superimposed angled black line with a thickness of 1 (for which no jointStyle applies):



Notice that for jointStyle set to "miter", you can limit the length of the miter point by using the miterLimit parameter.

miterLimit:Number - Added in Flash Player 8. A number that indicates the limit at which a miter is cut off. Valid values range from 1 to 255 (and values outside of that range are rounded to 1 or 255). This value is only used if the jointStyle is set to "miter". If a value is not indicated, Flash uses 3. The miterLimit value represents the length that a miter can extend beyond the point at which the lines meet to form a joint. The value expresses a factor of the line thickness. For example, with a miterLimit factor of 2.5 and a thickness of 10 pixels, the miter is cut off at 25 pixels.

For example, consider the following angled lines, each drawn with a thickness of 20, but with miterLimit set to 1, 2, and 4. Superimposed are black reference lines showing the meeting points of the joints:



Notice that for a given miterLimit value, there is a specific maximum angle for which the miter is cut off. The following table lists some examples:

Value of miterLimit value:

Angles smaller than this are cut off:

1.414

90 degrees

2

60 degrees

4

30 degrees

8

15 degrees

Example

The following code draws a triangle with a 5-pixel, solid magenta line with no fill, with pixel hinting, no stroke scaling, no caps, and miter joints with miterLimit set to 1:

this.createEmptyMovieClip("triangle_mc", this.getNextHighestDepth());
triangle_mc.lineStyle(5, 0xff00ff, 100, true, "none", "round", "miter", 1);
triangle_mc.moveTo(200, 200);
triangle_mc.lineTo(300, 300);
triangle_mc.lineTo(100, 300);
triangle_mc.lineTo(200, 200);

If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

beginFill (MovieClip.beginFill method), beginGradientFill (MovieClip.beginGradientFill method), clear (MovieClip.clear method), curveTo (MovieClip.curveTo method), lineTo (MovieClip.lineTo method), moveTo (MovieClip.moveTo method)


Version 8

Comments


No screen name said on Sep 24, 2005 at 9:24 AM :
I found the capsStyle very usefull, but I have noticed one thing.

If i set the capsStyle to "none" it's like the line there is transparent becouse the size remains the same
for example:
lineStyle(10,0x000000,100,true,"normal","none");
moveTo(0,0); lineTo(0,100);

will draw me a 100 pixels line (becouse the capsStyle is set to none) STILL the _height of the MC where I drew the line is 110 (100+the caps).
You can easyly notice that by enabling the "Shaw redraw region" feature of the Flash Player 8 an you'll se the red rectangle 5 pixels above the MC and 5 pixels below.

So I suggest drawing with "square" capsStyle but with smaller height if you want the same effect and maintaining the MC _height
Paul I said on Aug 5, 2006 at 2:20 PM :
Nothing mentioned about line "styles" - i.e. dotted, dashed, hatched etc. Are these possible (or WILL they be) through A.S.?
No screen name said on Oct 27, 2006 at 2:34 AM :
How to I create dotted line while using this function?
Is it possible via script at all?
JoeFarro said on Jun 21, 2007 at 2:00 PM :
To clear the line style call MovieClip.lineStyle(), without any arguments. After this you can continue to draw a fill bit it will not have a stroke. Here is an example:

var mc:MovieClip = this.createEmptyMovieClip("a", 1);
mc.lineStyle(3, 0x000000, 100);
mc.beginFill(0xDDDDDD, 100);
mc.moveTo(100, 100);
mc.lineTo(100, 200);
mc.lineTo(200, 200);
mc.lineStyle();
mc.lineTo(200, 100);
mc.endFill();

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002477.html