flex中简单的拖曳

下面是源码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init();">
<mx:Script>
   <![CDATA[
    private function init(){
     this.gic.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
    }
   
    private function onMouseDown(event:MouseEvent):void{
//     (event.currentTarget as Sprite).startDrag();
     gic.startDrag();
     gic.removeEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
     stage.addEventListener(Event.ENTER_FRAME,onEnterFrames);
     stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
    }
   
    private function onMouseUp(event:MouseEvent):void{
//     (event.target as Sprite).stopDrag();
     gic.stopDrag();
     stage.removeEventListener(Event.ENTER_FRAME,onEnterFrames);
     stage.removeEventListener(MouseEvent.MOUSE_UP,onMouseUp);
     gic.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
    }
   
    private function onEnterFrames(event:Event):void{
     txt.x=gic.x+gic.contentWidth;
     txt.y=gic.y;
    }
   ]]>
</mx:Script>

<mx:HBox>
   <mx:Image source="img/test.gif" id="gic"/>
   <mx:TextInput id="txt" />
</mx:HBox>
</mx:Application>

posted on 2010-05-04 17:53  画一个圆圈  阅读(117)  评论(0编辑  收藏  举报

导航