PeopleSoft Adoption Made Smooth & Simple!
On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool. Claim Your Free WalkMe Account Now
Become a Premium Member and unlock a new, free course in leading technologies each month.
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
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
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
Join the community of 500,000 technology professionals and ask your questions.