<?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:Declarations>
<!--
将非可视元素(例如服务、值对象)放在此处
-->
</fx:Declarations>
<mx:Canvas
backgroundColor="#FFFFFF" mouseDown="startMove(event)" mouseUp="stopMove(event)"
width="400" height="300"
>
<fx:Script>
<![CDATA[
import
mx.core.DragSource;
import
mx.managers.DragManager;
/****************************************************************************
*
控件A
* 用于拖动,捕获mouseDown 和
mouseUp事件,触发拖动
****************************************************************************/
/**
*
鼠标按下事件处理方法
*/
private function startMove(event:Event):void
{
//Sprite 类的startDrag方法来触发拖动
Sprite(event.target).startDrag();
//其他控件感知拖动事件,需要用DragManager的doDrag 方法触发
var obj:DragSource=new
DragSource();
//Data 包含,拖动时该控件的x,y 信息
var
location:String=this.x+","+this.y;
obj.addData(location,"LocationFormat");
var
mouseEvent:MouseEvent=new
MouseEvent(MouseEvent.MOUSE_DOWN);
DragManager.doDrag(this,obj,mouseEvent);
}
/**
* 鼠标弹起事件处理方法
*/
private function
stopMove(event:Event):void
{
//Sprite 类的stopDrag
方法来触发停止拖动
Sprite(event.target).stopDrag();
}
]]>
</fx:Script>
<mx:Button x="48.5" y="38"
label="A" width="161" height="89" fontSize="28"/>
<mx:BubbleChart
id="bu"
>
</mx:BubbleChart>
</mx:Canvas>
</s:Application>
原文:http://www.cnblogs.com/wshsdlau/p/3621874.html