Flex 画线的方法

 public var lines1 :flash.display.Sprite = new Sprite (); //

lines1.graphics.lineStyle(2,0x0099ff,1);//设置颜色 粗细

lines1.graphics.moveTo(uFrom.x+uFrom.width/2,uFrom.y+uFrom.height/2); //从某个坐标开始

lines1.graphics.lineTo(uTo.x+uTo.width/2,uTo.y+uTo.height/2); //画到某个坐标

//因为addChild方法 不能识别 非继承mc.core.UIComponent的控件  所以先声明一个组件 把控件放进去然后在放进界面中

var comp: UIComponent = new UIComponent();

comp.addChild(lines);

addChild(comp);

再flex 3 IDE Flex Builder 3 beta 3下编译通过

<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="absolute"  borderColor ="#FFFFFF"   >    
    
< mx:Script >
        
<![CDATA[
            import mx.effects.Move;
            import mx.controls.*;
            import mx.core.*;
            import mx.effects.*;
            public var lines :Sprite =  new Sprite ();
            public var lines1 :flash.display.Sprite =  new Sprite ();
            

            
            public function TestPaint():void
            {
                //Alert.show("Hello World!");
                lines.graphics.lineStyle(2,0x0099ff,1);
                DrawLine(lines,lbl,btn1);
                DrawLine(lines,lbl,btn2);
                DrawLine(lines,lbl,btn3);
                   var comp: UIComponent = new UIComponent();
                   comp.addChild(lines);
                   addChild(comp);
            }
            
            public function DrawLine(lines:Sprite,uFrom:UIComponent,uTo:UIComponent):void
            {
                lines.graphics.moveTo(uFrom.x+uFrom.width/2,uFrom.y+uFrom.height/2);
                lines.graphics.lineTo(uTo.x+uTo.width/2,uTo.y+uTo.height/2);
            }
            
            
            public function btn1_mouseOver(event:Event):void
            {
                lines1.graphics.lineStyle(2,0xd43dd6,1);
                DrawLine(lines1,btn1,btn2);
                DrawLine(lines1,btn1,lbl);
                   var comp: UIComponent = new UIComponent();
                   comp.addChild(lines1);
                   addChild(comp);
            }
            public function btn1_mouseOut(event:Event):void
            {
                lines1.graphics.clear();
                DrawLine(lines,lbl,btn1);
            }
            
            
            public function Testmove():void
            {
                var move:Move = new Move();
                if(btn2.x!=lbl.x)
                {
                    move.target=btn2;
                    move.end();
                    move.xTo=lbl.x;
                    move.yTo=lbl.y;
                    move.play(); 
                }
                else
                {
                    
                    move.target=btn2;
                    move.end();
                    move.xTo=340;
                    move.yTo=104;
                    move.play(); 
                }
            }
        
]]>
    
</ mx:Script >
    
< mx:Button  x ="176"  y ="34"  label ="btn1"  id ="btn1"  mouseOver ="btn1_mouseOver(event)"  mouseOut ="btn1_mouseOut(event)" />
    
< mx:Button  x ="340"  y ="104"  label ="btn4"  id ="btn2" />
    
< mx:Button  x ="53"  y ="167"  label ="btn3"  id ="btn3" />
    
< mx:Button  x ="131"  y ="373"  label ="Paint"  click ="TestPaint()" />
    
< mx:Label  x ="176"  y ="169"  text ="LblMiddle"  width ="71"  height ="20"  id ="lbl" />
    
< mx:Button  x ="303"  y ="324"  label ="Move"  click ="Testmove()" />
    
</ mx:Application >

转载于:https://www.cnblogs.com/wingfay/archive/2008/02/29/1086075.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值