tags:

views:

306

answers:

1

I am using Flash CS4, and it has a feature of drawing solid/dashed/dotted/ragged/stippled lines. But, I can't find API for drawing a line of these styles. Graphics.lineStyle() doesn't support it. How can I draw styled lines progammatically?

EDIT: Included ragged/stipple style

+1  A: 

Manual solution, found here. Works well under AS2, but might require some tweakign to make it work under AS3.

var dotWidth:Number = 4;
var spaceBetweenDots:Number = 1;
var totalLineWidth:Number = 250;
var dotsPerLine:Number = totalLineWidth / (dotWidth + spaceBetweenDots);
for (var i:Number = 0; i < dotsPerLine; i++)
{
    var dottedLine:MovieClip = _root.createEmptyMovieClip("topLine_" + i, this.getNextHighestDepth());
    dottedLine.lineStyle(0, 0x000000, 100);
    dottedLine.lineTo(dotWidth, 0);
    dottedLine._x = i * (dotWidth + spaceBetweenDots);
    dottedLine._y = 50;
}

You could add a bit random in there to get ragged lines:

var dotWidth:Number = 4;
var spaceBetweenDots:Number = 0;
var totalLineWidth:Number = 250;
var dotsPerLine:Number = totalLineWidth / (dotWidth + spaceBetweenDots);
var ragVariance: Number = 2;
for (var i:Number = 0; i < dotsPerLine; i++)
{   
    var raggedLine:MovieClip = _root.createEmptyMovieClip("topLine_" + i, this.getNextHighestDepth());
    raggedLine.lineStyle(0, 0x000000, 100);
    raggedLine.lineTo(dotWidth-random(ragVariance), random(ragVariance));
    raggedLine._x = i * (dotWidth + random(spaceBetweenDots));
    raggedLine._y = 100+random(ragVariance);
}
sthg
Thank you, it can surely draw dotted and dashed. But how about ragged/stippled?
grayger
...gave ragged a try. You can specify the amount with the ragVariance variable.
sthg
Thank you, again. I expected APIs for this job, but your approach is also good.
grayger