浏览 2157 次
锁定老帖子 主题:DashLine
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-10-08
<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"> <mx:Script> <![CDATA[ import mx.core.UIComponent; //if flag is true,draw horizon line ,else vertical line. [Bindable] public var flag : Boolean = true; override protected function updateDisplayList(unscaledWidth : Number, unscaledHeight : Number) : void { super.updateDisplayList(unscaledWidth, unscaledHeight); /* var num : Array = [2,3]; dashLineToPattern(this, 10000,50,60,50,num); */ var labelX:Number = this.x; var labelY:Number = this.y; drawDashLineType(flag, labelX, labelY); } public function drawDashLineType(flag : Boolean, labelX : Number, labelY : Number) : void { var ToX:Number; var ToY:Number ; if(flag) { ToX = labelX + this.width; //draw horizon dash line ToY = labelY; } else { ToX = labelX; ToY = labelY + this.height; //draw vertical dash line } var pattern:Array = new Array; pattern.push(2,3); dashLineToPattern(this, labelX, labelY, ToX, ToY, pattern); } public static function dashLineToPattern(target:UIComponent, x1:Number, y1:Number,x2:Number, y2:Number,pattern:Array):void { target.graphics.lineStyle(1,0x000000); var x:Number = x2 - x1; var y:Number = y2 - y1; var hyp:Number = Math.sqrt((x)*(x) + (y)*(y)); var units:Number = hyp/(pattern[0]+pattern[1]); var dashSpaceRatio:Number = pattern[0]/(pattern[0]+pattern[1]); var dashX:Number = (x/units)*dashSpaceRatio; var spaceX:Number = (x/units)-dashX; var dashY:Number = (y/units)*dashSpaceRatio; var spaceY:Number = (y/units)-dashY; target.graphics.moveTo(x1, y1); while (hyp > 0) { x1 += dashX; y1 += dashY; hyp -= pattern[0]; if (hyp < 0) { x1 = x2; y1 = y2; } target.graphics.lineTo(x1, y1); x1 += spaceX; y1 += spaceY; target.graphics.moveTo(x1, y1); hyp -= pattern[1]; } target.graphics.moveTo(x2, y2); } ]]> </mx:Script> </mx:Label> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |