欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Flex拖拽控件效果 博客分类: Flex flex 

程序员文章站 2024-02-18 23:49:22
...
这里主要的是事件监听
<?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>
相关标签: flex