flex 抓图
我想用Flex做一个抓图效果,就是图片放在面板上,用鼠标点击后不放图片会跟着鼠标移动的效果。
利用mouseDown记录移动前的坐标,用mouseMove实现鼠标跟随效果。可是只要我的鼠标在图片上移动图片就会动,我想当鼠标按下不动的时候移动鼠标才调用mouseMove。这样能实现吗?或者应该通过别的方法实现?
[解决办法]
- XML code
<?xml version="1.0"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="700" height="410"> <mx:Script> <![CDATA[ import mx.managers.PopUpManager; import flash.display.Bitmap; import flash.events.MouseEvent; [Bindable] private var oldX:Number, oldY:Number; protected function image_2_mouseDownHandler(event:MouseEvent):void { oldX=event.stageX; oldY=event.stageY; } protected function image_2_mouseMoveHandler(event:MouseEvent):void { if (event.buttonDown) { var x:Number=event.stageX - oldX; var y:Number=event.stageY - oldY; oldX=event.stageX; oldY=event.stageY; image_2.move(image_2.x + x, image_2.y + y); } } ]]> </mx:Script> <mx:Canvas id="canvas_2" width="100%" height="100%"> <mx:Image id="image_2" source="img/car.jpg" mouseDown="image_2_mouseDownHandler(event)" mouseMove="image_2_mouseMoveHandler(event)"> </mx:Image> </mx:Canvas></mx:Application>