DashLine

<?xml version="1.0" encoding="utf-8"?>
<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>

你可能感兴趣的:(xml)