http://vulturous.110mb.com/eefiles/DashedLine.as
-V
package diagrammingtool.utils{
import flash.geom.Point;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.Shape;
// START CLASS
public class DashedLine extends Sprite{
// CONSTRUCTOR
private var startPoint:Point = new Point();
private var endPoint:Point = new Point();
public function DashedLine(sPoint:Point, ePoint:Point, len:Number, gap:Number) {
var child:Shape = new Shape();
var seglen:Number = len + gap ;
var deltax = sPoint.x-ePoint.x;
var deltay = sPoint.y-ePoint.y;
var dist:Number = Math.sqrt(deltax*deltax+deltay*deltay);
var noOfSegs:Number = Math.floor(Math.abs(dist/seglen));
var angle:Number = Math.atan2(deltay,deltax);
var cx:Number = sPoint.x;
var cy:Number = sPoint.y;
// add these to cx, cy to get next seg start
deltax = Math.cos(angle)*seglen;
deltay = Math.sin(angle)*seglen;
// loop through each seg
for (var n:Number = 0; n < noOfSegs; n++) {
child.graphics.moveTo(cx,cy);
child.graphics.lineTo(cx+Math.cos(angle)*len,cy+Math.sin(angle)*len);
cx += deltax;
cy += deltay;
trace(cx);
}
// handle last segment as it is likely to be partial
child.graphics.moveTo(cx,cy);
var delta:Number = Math.sqrt((ePoint.x-cx)*(ePoint.x-cx)+(ePoint.y-cy)*(ePoint.y-cy));
if(delta>len){
// segment ends in the gap, so draw a full dash
child.graphics.lineTo(cx+Math.cos(angle)*len,cy+Math.sin(angle)*len);
} else if(delta>0) {
// segment is shorter than dash so only draw what is needed
child.graphics.lineTo(cx+Math.cos(angle)*delta,cy+Math.sin(angle)*delta);
}
// move the pen to the end position
child.graphics.moveTo(ePoint.x,ePoint.y);
addChild(child);
}
}
// END CLASS
}
// END PACKAGE
var dl = new DashedLine(000000,4,90,200,300,400,500,10,5);
stage.addChild(dl);
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
How to disable HTML5 video in chrome | 2 | 1,542 | |
Can't find all of the preferences on Flash Pro | 2 | 483 | |
Adobe flash player memory exhaustion | 6 | 91 | |
Trying to contour a nose in a face portrait in After Effects | 5 | 98 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
25 Experts available now in Live!