# 用ActionScript画虚线

/*-------------------------------------------------------------
mc.dashTo is a method for drawing dashed (and dotted)
lines. I made this to extend the lineTo function because it
doesn?t have the cutom line types that the in program
line tool has. To make a dotted line, specify a dash length
between .5 and 1.
-------------------------------------------------------------*/

MovieClip.prototype.dashTo = function(startx, starty, endx, endy, len, gap) {
// ==============
// mc.dashTo() - by Ric Ewing (ric@formequalsfunction.com) - version 1.2 - 5.3.2002
//
// startx, starty = beginning of dashed line
// endx, endy = end of dashed line
// len = length of dash
// gap = length of gap between dashes
// ==============
//
// if too few arguments, bail
if (arguments.length < 6) {
return false;
}
// init vars
var seglength, deltax, deltay, segs, cx, cy;
// calculate the legnth of a segment
seglength = len + gap;
// calculate the length of the dashed line
deltax = endx - startx;
deltay = endy - starty;
delta = Math.sqrt((deltax * deltax) + (deltay * deltay));
// calculate the number of segments needed
segs = Math.floor(Math.abs(delta / seglength));
// get the angle of the line in radians
// start the line here
cx = startx;
cy = starty;
// add these to cx, cy to get next seg start
// loop through each seg
for (var n = 0; n < segs; n++) {
this.moveTo(cx,cy);
cx += deltax;
cy += deltay;
}
// handle last segment as it is likely to be partial
this.moveTo(cx,cy);
delta = Math.sqrt((endx-cx)*(endx-cx)+(endy-cy)*(endy-cy));
if(delta>len){
// segment ends in the gap, so draw a full dash
} else if(delta>0) {
// segment is shorter than dash so only draw what is needed
}
// move the pen to the end position
this.moveTo(endx,endy);
};

#### flash绘图API：绘制一条虚线

2011-12-18 17:31:20

#### IOS 如何实现画虚线

2015-08-17 16:37:01

#### flash 绘图API：绘制虚线矩形

2011-01-31 14:54:00

#### Android实现画虚线的控件

2010-09-16 11:59:00

#### 用opencv画虚线框矩形

2016-04-08 15:50:30

#### gdi+画虚线

2008-09-27 10:44:00

#### flex 线形图为虚线，绘制图例(1)

2014-02-13 20:03:37

#### PS画虚线的几种方法

2012-03-26 10:15:07

#### iOS画虚线方法

2016-12-19 19:30:16

#### WPF 虚线的画法

2009-03-20 08:53:00