这里主要的是事件监听
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.events.SandboxMouseEvent;
protected function button1_mouseDownHandler(event:MouseEvent):void
{
event.target.startDrag(false,new Rectangle(this.x,this.y,this.width,this.height));
systemManager.getSandboxRoot().addEventListener(MouseEvent.MOUSE_UP, StopDrag);
systemManager.getSandboxRoot().addEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE,StopDrag);
}
private function StopDrag(e:Event):void
{
e.currentTarget.stopDrag();
systemManager.getSandboxRoot().removeEventListener(MouseEvent.MOUSE_UP,StopDrag);
systemManager.getSandboxRoot().removeEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE,StopDrag);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Button label="Drag" mouseDown="button1_mouseDownHandler(event)" x="65" y="28"/>
<s:Button label="Drag" mouseDown="button1_mouseDownHandler(event)" x="65" y="115"/>
<s:Button label="Drag" mouseDown="button1_mouseDownHandler(event)" x="65" y="86"/>
<s:Button label="Drag" mouseDown="button1_mouseDownHandler(event)" x="65" y="57"/>
</s:Application>
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.events.SandboxMouseEvent;
protected function button1_mouseDownHandler(event:MouseEvent):void
{
event.target.startDrag(false,new Rectangle(this.x,this.y,this.width,this.height));
systemManager.getSandboxRoot().addEventListener(MouseEvent.MOUSE_UP, StopDrag);
systemManager.getSandboxRoot().addEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE,StopDrag);
}
private function StopDrag(e:Event):void
{
e.currentTarget.stopDrag();
systemManager.getSandboxRoot().removeEventListener(MouseEvent.MOUSE_UP,StopDrag);
systemManager.getSandboxRoot().removeEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE,StopDrag);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Button label="Drag" mouseDown="button1_mouseDownHandler(event)" x="65" y="28"/>
<s:Button label="Drag" mouseDown="button1_mouseDownHandler(event)" x="65" y="115"/>
<s:Button label="Drag" mouseDown="button1_mouseDownHandler(event)" x="65" y="86"/>
<s:Button label="Drag" mouseDown="button1_mouseDownHandler(event)" x="65" y="57"/>
</s:Application>