如何防止使用 Flex 将一个项目从另一个项目放入一个 TileList 中? [英] How to prevent an item being dropped into one TileList from another using Flex?

查看:27
本文介绍了如何防止使用 Flex 将一个项目从另一个项目放入一个 TileList 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阻止用户将某些项目从一个 TileList 拖到另一个.是否可以将它们放入 TileList 应根据与项目关联的数据来确定.

I would like to prevent a user dragging certain items from one TileList to another. Whether or not they can be dropped into the TileList should be determined based on data associated with the item.

为了表明该项目不能被拖到 TileList 中,我想在光标旁边的红色圆圈图标中显示正常的白色十字.如果在确定不应发生丢弃时尝试丢弃,我想显示一条警告消息,解释为什么无法丢弃该项目.

To show that the item cannot be dragged into the TileList I would like to show the normal white cross in red circle icon next to the cursor. If a drop is attempted when it has been determined that drop should not occur I would like to show an alert message explaining why this item could not be dropped.

推荐答案

您需要阻止对 dragDrop 事件(阻止它被添加到新列表)和 dragComplete 事件(阻止它)的默认操作从旧列表中删除).这是一个允许项目在列表内移动但不允许在列表之间移动的示例:

You'll need to prevent the default action on both the dragDrop event (to stop it from being added to the new List) and dragComplete event (to stop it from being removed from the old List). Here is an example for allowing items to be moved within a list but not between lists:

private var preventMove:Boolean = false;
private function onDragDrop(event: DragEvent): void {
    preventMove = (event.dragInitiator != event.target);
    if (preventMove)
        event.preventDefault();
}

private function onDragComplete(event: DragEvent): void {
    if (preventMove) {
        event.preventDefault();
    }
}

您可以使用任何您想要的标准来代替针对 dragDrop 目标检查 dragInitiator.除了在 dragComplete 上调用 preventDefault 外,您还可以弹出错误消息.

You can use whatever criteria you want in place of checking the dragInitiator against the dragDrop target. Along with calling preventDefault on dragComplete you can pop up your error message.

如果您有两个列表(或 TileLists 或其他):

Where you have two Lists (or TileLists or whatever):

<s:List dragDrop="onDragDrop(event)" dragComplete="onDragComplete(event)"
        dragEnabled="true" dropEnabled="true"  dragMoveEnabled="true">
</s:List>
<s:List dragDrop="onDragDrop(event)" dragComplete="onDragComplete(event)"
        dragEnabled="true" dropEnabled="true"  dragMoveEnabled="true">
</s:List>

如果您不需要能够在同一个列表中拖放内容,或者您​​只向一个方向拖动,那么只需不启用两个列表中的所有内容即可更简单.

If you don't need to be able to drag and drop things within the same List or you're only dragging one direction it can be simpler just by not enabling everything on both lists.

Chetan Sastry 链接的文章现在已经过时并且链接失效了.

The article linked by Chetan Sastry is now old and has broken links.

这篇关于如何防止使用 Flex 将一个项目从另一个项目放入一个 TileList 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆