拖动 n'在组件之间放置 Spark 列表项渲染
我正在尝试在位于不同组件的 2 个 Spark 列表之间进行一些拖放操作。 因为我的第一次尝试没有成功,所以我决定在 Google 上搜索并阅读更多有关 DragAndDrop 的内容...尝试了我能找到的所有示例,但没有什么对我有用。
那么让我们进入正题吧。
- 组件 A 具有 List1
- 组件 B 具有 List2
组件 A - 列表 1 具有 dragEnabled="true"
和 mouseDown="initiateDrag(event )"
private function initiateDrag(e:MouseEvent):void{
var dragInitiator:IUIComponent = e.target as IUIComponent;
var de:DragSource = new DragSource;
de.addData(dragInitiator, 'artist');
DragManager.doDrag(dragInitiator, de, e);
}
根据我读到的内容,使用 mouseDown
我正在启动一个拖动事件,创建我要拖动的数据类型...这种情况 'artist '
组件 B - 列表 2 有 dropEnabled="true"、dragEnter="dragEnterHandler(event)" 和 DragDrop="dragDropHandler(event)"
private function dragEnterHandler(e:DragEvent):void{
if(e.dragSource.hasFormat('artist')){
DragManager.acceptDragDrop(List(e.currentTarget));
}
}
现在,我期望的是,当我将 itemRender 从组件 A 列表 1 拖到组件 B 列表 2 上时,调用函数 dragEnterHandler(event) ,它确实...但我也期望
DragManager.acceptDragDrop(List(e.currentTarget))
能够将指示器从“红十字”更改为到“绿色加号”,但这种情况没有发生......因此,拖动的 itemRender (proxi) 移回到其原始列表,在这种情况下,它移回组件 A 列表1
我已经花了很多时间调试和测试其他方法,但没有一个对我有用。
这里有熟悉组件之间拖放操作的人可以帮助我吗?
I'm trying to do some drag and drop between 2 spark List located in different components.
Because my first attempt didn't work, I decide to Google it and read some more about DragAndDrop ... tried all the examples I could find but nothing seams to work for me.
So let's go to the point.
- Component A has List1
- Component B has List2
Component A - List 1 has dragEnabled="true"
and mouseDown="initiateDrag(event)"
private function initiateDrag(e:MouseEvent):void{
var dragInitiator:IUIComponent = e.target as IUIComponent;
var de:DragSource = new DragSource;
de.addData(dragInitiator, 'artist');
DragManager.doDrag(dragInitiator, de, e);
}
By what I read, usind the mouseDown
I'm starting a the drag event creating what kind of data I'm going to drag ... this case 'artist'
Component B - List 2 has dropEnabled="true", dragEnter="dragEnterHandler(event)" and dragDrop="dragDropHandler(event)"
private function dragEnterHandler(e:DragEvent):void{
if(e.dragSource.hasFormat('artist')){
DragManager.acceptDragDrop(List(e.currentTarget));
}
}
Now, what I'm expecting was, when I drag the itemRender from Component A List 1 over Component B List 2 is to call the function dragEnterHandler(event)
, and it does ... but I was also expecting that the DragManager.acceptDragDrop(List(e.currentTarget))
whould change indicator from the "red cross" to the "green plus" and that's not happening ... and because of that, the dragged itemRender (proxi) moves back to its original list in this case it moves back to Component A List 1
I already spent hours and hours debugging and testing other approaches and none seams to work for me.
Is there anyone here familiarize with drag and drop between components that may help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,伙计们,看起来 2 天 4 小时后我得到了解决方案:)
我以完全错误的方式寻找这个问题。
当对基于列表的组件使用拖放时,“格式”始终是“itemsByIndex”,我试图接受“艺术家”“格式”。
问题:
您有多个列表通过拖放方法接受数据。
不同的列表必须接受不同类型的数据。
解决方案:
将
包装在
中,然后手动调用dragEnter
事件,然后您就可以使用它调用一个函数,该函数可以通过检查其'format'
来接受或拒绝拖动的数据。接受拖动源后,将调度
dragDrop
事件,您可以调用一个函数来在应用程序中执行您想要的任何操作...例如,将拖动的数据添加到列表中。注意:
请记住,如果您直接在组件上设置
dragEnter
和dragDrop
,则您将能够检查拖动的数据“格式”,因为所有列表控件都使用' format'
'itemsByIndex'
演示:
希望这可以帮助其他遇到同样问题的人! :)
Well guys, looks like after 2 days and 4h later I got the solution :)
I was looking to this in a complete wrong way.
When using Drag and Drop with List based components, the 'format' is always 'itemsByIndex' and I was trying to be accepted with 'artist' 'format'.
Problem:
You have more than one List accepting data with a drag-and-drop method.
Different lists has to accept different types of data.
Solution:
Wrap the
<s:List/>
in<s:Group/>
and manually call thedragEnter
event and with it you call a function that can accept or reject the dragged data by checking it's'format'
.Accepting the drag source, the
dragDrop
event is dispatched and with that you can call a function to do whatever you want in your app ... for example, add the dragged data to the list.NOTE:
Remember if tou set the
dragEnter
anddragDrop
directly on the component, you will ne be able to check the dragged data 'format' given all list controls uses the'format'
'itemsByIndex'
Demo:
Hope this helps other people with the same problem! :)