鼠标拖动图片控件
简单的例子
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="427" height="374" backgroundGradientColors="[#ffffff, #ffffff]">
<mx:Script>
<![CDATA[
import mx.events.MoveEvent;
private var oldX,oldY:Number;
private function onMouseMove(event:MouseEvent):void{
lbl.text = "Local (x,y):" + event.localX.toString() + ","+event.localX.toString();
lbl2.text = "Stage (x,y):" + event.stageX.toString() + ","+event.stageY.toString();
if(event.buttonDown){
var x:Number = event.stageX - oldX;
var y:Number = event.stageY - oldY;
oldX = event.stageX;
oldY = event.stageY;
img.move(img.x + x,img.y + y);
}
}
private function onMouseDown(event:MouseEvent):void{
oldX = event.stageX;
oldY = event.stageY;
}
]]>
</mx:Script>
<mx:Label x="10" y="10" text="" id="lbl"/>
<mx:Label x="10" y="27" text="" id="lbl2"/>
<mx:Image id="img" x="147" y="156" source="http://www.cnblogs.com/Images/adminlogo.gif" mouseMove="onMouseMove(event)" mouseDown="onMouseDown(event)"/>
</mx:Application>
////////////////////////////
总结
1.关键处为"怎样一个状态是拖动状态",不用想太多,很简单,mouseMove时判断buttonDown就行了
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
////////////////////////////
总结
1.关键处为"怎样一个状态是拖动状态",不用想太多,很简单,mouseMove时判断buttonDown就行了