当前位置: 代码迷 >> Web前端 >> DragManager拖沓控制
  详细解决方案

DragManager拖沓控制

热度:260   发布时间:2012-11-12 12:31:56.0
DragManager拖拉控制

讨厌的DragManager

?

在一个容器上覆盖了层,透明png,然后容器里面就接受不到drag的任何事件了。翻看flex框架代码发现是在DragProxy里面做的判断,还是没有对drag忽略的代码。

?

没辙了,只好用MouseMove来做了:

  1. <?xml?version="1.0"?> ??
  2. <!--?Simple?example?to?demonstrate?the?ComboBox?control.?--> ??
  3. <mx:Application?xmlns:mx="http://www.adobe.com/2006/mxml"?xmlns:local="*"? ??
  4. ????applicationComplete="applicationCompleteHandler()"> ??
  5. ????<mx:Canvas?id="ppp"?width="440"?height="267"??backgroundColor="#FFFFFF"??
  6. ????????blendMode="{BlendMode.LAYER}"> ??
  7. ??????<mx:Image??source="Creek.jpg"? ??
  8. ????????maintainAspectRatio="false"??
  9. ?????????mouseEnabled="false"?mouseChildren="false"?width="100%"?height="100%"/> ??
  10. ?????<mx:Canvas?id="c"?width="80%"?height="80%"??
  11. ?????????horizontalCenter="0"?verticalCenter="0"?borderStyle="solid"?borderThickness="20"? ??
  12. ?????????borderColor="#33003E"?backgroundColor="#E8E8E8"/> ??
  13. ?????<local:DragIgnoreImage ??
  14. ?????????mouseEnabled="false"?mouseChildren="false"?width="100%"?height="100%"/>????? ??
  15. ????</mx:Canvas> ??
  16. ????<mx:Image?id="p"?width="100"?height="100"?source="Desert?Landscape.jpg"?mouseDown="imageMouseDownHandler(event)"/> ??
  17. ????????<mx:List?dragEnabled="true">? ??
  18. ????????<mx:dataProvider> ??
  19. ????????????<mx:String>AK</mx:String> ??
  20. ????????????<mx:String>AL</mx:String> ??
  21. ????????????<mx:String>AR</mx:String> ??
  22. ????????</mx:dataProvider> ??
  23. ????</mx:List> ??
  24. ????<mx:Script> ??
  25. ????????<![CDATA[ ??
  26. ????????????import?mx.core.IFlexDisplayObject; ??
  27. ????????????import?mx.core.DragSource; ??
  28. ????????????import?mx.core.UIComponent; ??
  29. ????????????import?mx.events.DragEvent; ??
  30. ????????????import?mx.managers.DragManager; ??
  31. ????????????private?function?applicationCompleteHandler():void?{ ??
  32. ????????????????stage.addEventListener(MouseEvent.MOUSE_DOWN,stageMousedownhandler); ??
  33. ????????????} ??
  34. ???????????? ??
  35. ????????????private?function?stageMousedownhandler(e:MouseEvent):void?{ ??
  36. ????????????????stage.addEventListener(MouseEvent.MOUSE_MOVE,stageMouseMovehandler); ??
  37. ????????????????stage.addEventListener(MouseEvent.MOUSE_UP,stageMouseUpHandler); ??
  38. ????????????} ??
  39. ???????????? ??
  40. ????????????private?function?stageMouseMovehandler(e:MouseEvent):void?{ ??
  41. ????????????????var?p:Point?=?new?Point(e.stageX,e.stageY); ??
  42. ????????????????p?=?c.globalToLocal(p); ??
  43. ???????????????? ??
  44. ????????????????if(DragManager.isDragging)?{ ??
  45. ????????????????????if(c.getBounds(c).containsPoint(p))?{ ??
  46. ????????????????????????c.setStyle("backgroundColor",0xFFFFF000); ??
  47. ????????????????????} ??
  48. ????????????????????else?{ ??
  49. ?????????????????????????c.setStyle("backgroundColor",0xFF00F000); ??
  50. ????????????????????} ??
  51. ????????????????} ??
  52. ????????????} ??
  53. ???????????? ??
  54. ????????????private?function?stageMouseUpHandler(e:MouseEvent):void?{ ??
  55. ????????????????stage.removeEventListener(MouseEvent.MOUSE_MOVE,stageMouseMovehandler); ??
  56. ????????????????stage.removeEventListener(MouseEvent.MOUSE_UP,stageMouseUpHandler); ??
  57. ????????????} ??
  58. ???????????? ??
  59. ????????????private?function?imageMouseDownHandler(e:MouseEvent):void?{ ??
  60. ????????????????var?dragInitiator:Image=p; ??
  61. ????????????????var?ds:DragSource?=?new?DragSource(); ??
  62. ????????????????ds.addData(dragInitiator,?"img");??????????????? ??
  63. ???????????????? ??
  64. ????????????????var?d:Image?=?new?Image(); ??
  65. ????????????????d.width?=?d.height?=?100; ??
  66. ????????????????d.source?=?p.source; ??
  67. ????????????????DragManager.doDrag(dragInitiator,?ds,?e,d); ??
  68. ????????????} ??
  69. ????????]]> ??
  70. ????</mx:Script> ??

  相关解决方案