Flex虚线

项目中涉及到用Flex画虚线,网上参考一些,稍加改动记录下来。
 1<?xml version="1.0" encoding="utf-8"?> 
 2<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
 3    backgroundGradientColors="[0xFFFFFF, 0xd5f3fa]" creationComplete="myInit()"> 
 4    
 5    <mx:Script>
 6        <![CDATA[
 7            import mx.controls.*;
 8            import mx.core.*;
 9            
10            private var lines : Sprite =  new Sprite ();
11            private var component: UIComponent = new UIComponent();
12            
13            private function drawDashed(graphics:Graphics,p1:Point,p2:Point,length:Number=5,gap:Number=5):void {
14                graphics.lineStyle(2,0xc4a00a,1);
15                var max:Number = Point.distance(p1,p2);
16                var l:Number = 0;
17                var p3:Point;
18                var p4:Point;
19                while(l<max) {
20                    p3 = Point.interpolate(p2,p1,l/max);
21                    l+=length;
22                    if(l>max)
23                        l=max;
24                    p4 = Point.interpolate(p2,p1,l/max);
25                    lines.graphics.moveTo(p3.x,p3.y);
26                    lines.graphics.lineTo(p4.x,p4.y);
27                    l+=gap;
28                }
29                component.addChild(lines);
30                this.addChild(component);
31            }
32            
33            private function myInit() : void {
34                var first : Point = new Point(100,100);
35                var second : Point = new Point(300,300);
36                
37                drawDashed(lines.graphics,first,second);
38            }
39        ]]>
40    </mx:Script>
41    
42</mx:Application>

posted on 2009-06-10 11:05 非凡DZ 阅读(1573) 评论(0)  编辑  收藏 所属分类: FLEX


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(2)

随笔分类(19)

随笔档案(19)

友情链接

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜