[英]flex: Ability to drag+drop a movieclip
In order to improve user experience we want the ability to have an animated movieclip of a turning wheel- and have the ability to drag and drop it anywhere on a defined area为了改善用户体验,我们希望能够拥有一个转动轮子的动画影片剪辑,并且能够将其拖放到定义区域的任何位置
We have built the rotating wheel as a swc file.我们已将旋转轮构建为 swc 文件。
How do we do the drag+drop.我们如何进行拖放。 Examples that I have seen, cater to only dropping of images.我见过的示例仅适用于丢弃图像。 Thanks again再次感谢
You should specify the dragProxy
for the movieClip
to hold an instance of it instead of a fixed image.您应该为movieClip
指定dragProxy
以保存它的实例而不是固定图像。
To use the Flex classes for drag and drop you'll need to wrap that movieClip in an a UIComponent ;要使用 Flex 类进行拖放,您需要将该 movieClip 包装在UIComponent中; which has all the events related to drag and drop.其中包含与拖放相关的所有事件。
Here are some good instructions .这里有一些很好的说明。 To copy the relevant pieces:复制相关部分:
Make a Component Draggable使组件可拖动
- Add listener for MouseEvent.MOUSE_DOWN为 MouseEvent.MOUSE_DOWN 添加监听器
- Determine drag initiator and hand-off to DragManager确定拖动启动器并移交给 DragManager
To kick off a drag-n-drop, you'll need a MouseEvent for the component to be dragged.要启动拖放操作,您需要一个 MouseEvent 来拖动组件。
public function makeDraggable( component:IUIComponent ):void
{
// a mouseDown event will start the drag
component.addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );
}
public function beginDrag( mouseEvent:MouseEvent ):void
{
// the drag initiator is the object being dragged (target of the mouse event)
var dragInitiator:IUIComponent = mouseEvent.currentTarget as IUIComponent;
// the drag source contains data about what's being dragged
var dragSource:DragSource = new DragSource();
// ask the DragManger to begin the drag
DragManager.doDrag( dragInitiator, dragSource, mouseEvent, null );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.