flex 实现鼠标画线

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            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 var count:int;
           
           
           
            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);
                  
                   count=0;
                   addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
                   addEventListener(MouseEvent.MOUSE_UP,mouseUp);
                  
            }
           
            public function mouseDown(event:MouseEvent):void
            {   
               
                 lines.graphics.moveTo( event.localX,event.localY);
               
            }
           
             public function mouseUp(event:MouseEvent):void
            {    var comp: UIComponent = new UIComponent();
               
             
                  lines.graphics.lineTo(event.localX,event.localY);
                
                  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>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值