浏览 5804 次
锁定老帖子 主题:Flex拖拽-Canvas容器里拖动Box
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-02-18
最后修改:2009-02-18
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import mx.core.IUIComponent; import mx.containers.Box; import mx.containers.Canvas; import mx.events.DragEvent; import mx.managers.DragManager; import mx.core.DragSource; import mx.core.UIComponent; private static const FORMAT:String = "box"; private function boxMouseDownHandler(evt:MouseEvent):void{ var iu:IUIComponent = evt.currentTarget as IUIComponent; var dragSource:DragSource = new DragSource(); dragSource.addData( iu, FORMAT ); DragManager.doDrag( iu, dragSource, evt ); } private function canvasDragEnterHandler(evt:DragEvent):void{ if(evt.dragSource.hasFormat(FORMAT)){ DragManager.acceptDragDrop(Canvas(evt.currentTarget)); } } private function canvasDragHandler(evt:DragEvent):void{ var box:Box = Box(evt.dragInitiator); box.x = evt.localX; box.y = evt.localY; } ]]> </mx:Script> <mx:Canvas backgroundColor="0xEEEEEE" width="500" height="200" horizontalCenter="0" verticalCenter="0" dragEnter="canvasDragEnterHandler(event)" dragDrop="canvasDragHandler(event)"> <mx:Box width="20" height="20" backgroundColor="0x00FFCC" x="137" y="66" mouseDown="boxMouseDownHandler(event);"></mx:Box> </mx:Canvas> </mx:WindowedApplication>
当<mx:Box>发出mouseDown事件时,boxMouseDownHandler 方法被调用并且拖拽源数据被增加到DragManager。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |