画虚线,关键是确定好实线和虚线的分界点。计算出分界点后就简单了,直接循环调用moveTo,lineTo方法画线就可以了。画线方法如下: /** * @inheritDoc * */ public function freeDraw(fP:Point,tP:Point):void { var g:Graphics=this.graphics; g.clear(); if(!fP){ fP=new Point(0,0); } if(!tP){ tP=new Point(0,0); } //applyLineStyle(vedge); var solidLength:Number=10; var brokenLength:Number=3; var lineAngle:Number; lineAngle = Math.atan2(tP.y - fP.y,tP.x - fP.x); var xSolidLength:Number=solidLength*Math.cos(lineAngle); var ySolidLength:Number=solidLength*Math.sin(lineAngle); var xBrokenLength:Number=brokenLength*Math.cos(lineAngle); var yBrokenLength:Number=brokenLength*Math.sin(lineAngle); var forwardFlag:Boolean=true; if(tP.x<fP.x){ forwardFlag=false; } var tempP:Point=new Point(fP.x,fP.y); var tempToP:Point=new Point(tP.x,tP.y); var lineType:String="solid"; g.lineStyle(1); while(checkIn(tempP.x,tP.x,forwardFlag)){ g.beginFill(0x555555); if(lineType=="solid"){ tempToP.x=tempP.x+xSolidLength; tempToP.y=tempP.y+ySolidLength; g.moveTo(tempP.x, tempP.y); g.lineTo(tempToP.x, tempToP.y); lineType="space"; }else{ tempToP.x=tempP.x+xBrokenLength; tempToP.y=tempP.y+yBrokenLength; g.moveTo(tempToP.x, tempToP.y); lineType="solid"; } tempP.x=tempToP.x; tempP.y=tempToP.y; g.endFill(); } } /** * 判断是否还在开始点和结束点之间 * */ private function checkIn(x:Number,toX:Number,forwardFlag:Boolean):Boolean{ var result:Boolean=true; if(forwardFlag){//向前 if(x<toX){ }else{ result=false; } }else{ if(x>toX){ }else{ result=false; } } return result; }