/** * 图片拖拽 */ public function dragHandler(event:MouseEvent):void{ //CurrentTarget指定要实现拖拽事件的初始化目标 var dragInitiator:Image=event.currentTarget as Image; // 定义拖拽挂载数据源 var dragSource:DragSource = new DragSource(); //向对象添加数据 dragSource.addData(dragInitiator.source,"img"); //创建一个拖拽对象的代理作为拷贝 var dragProxy:Image=new Image(); dragProxy.source=event.currentTarget.source; //使用DragManager静态方法doDrag开始拖拽 DragManager.doDrag(dragInitiator,dragSource,event,dragProxy); } private function dragEnterHandler(event:DragEvent):void{ var dropTarget:Image=event.currentTarget as Image; DragManager.acceptDragDrop(dropTarget); } private function dragDropHandler(event:DragEvent):void{ img_main.source=event.dragSource.dataForFormat("img"); } <!-- 拖拽 --> < s:Panel x ="10" y ="285" width ="250" height ="204" baseColor ="#EF5D5D" > < mx:Image x ="55" y ="13" width ="131" height ="132" id ="img_main" source ="image/mt.jpg" dragDrop ="dragDropHandler(event)" dragEnter ="dragEnterHandler(event)" /> </ s:Panel > < s:Group x ="268" y ="289" width ="200" height ="200" > < mx:Image x ="28" y ="36" width ="60" height ="78" id ="img_1" source ="image/java.jpg" mouseMove ="dragHandler(event)" /> < mx:Image x ="111" y ="39" width ="73" height ="75" id ="img_2" source ="image/mt.jpg" mouseMove ="dragHandler(event)" /> </ s:Group >
本文出自 “” 博客,请务必保留此出处