在 dataGrid 中拖放,拖动期间自定义光标不起作用
我有一个数据网格,我希望用户对其行进行排序。为了明显地表明它是可排序的,我正在实现一些自定义游标。但是当我实际拖动一个项目时遇到了问题。
这是问题的伪演示
应用程序 = 正常光标 // 很好
滚动数据网格 = 打开手形光标 // 到目前为止,
数据网格上的鼠标按下 = 闭合手形光标 // 良好的
拖动项目 = 闭合手形光标 // 切换回正常光标(如果我快速移动它,我可以立即看到我的自定义光标)
将鼠标放在 datadrid = 张开的手形光标上 // 不确定,在我放下它后,它会返回到张开的手形,但如果我按下鼠标,则不要移动并向上移动鼠标我有一个闭合的
手卷展数据网格=正常光标//良好的
数据网格代码:
<mx:DataGrid id="sectQuestionsDG" x="10" y="204" width="558" height="277" headerHeight="0" selectable="{editMode}"
dragMoveEnabled="{editMode}" dragEnabled="{editMode}" dropEnabled="{editMode}"
dragDrop="sectQuestReOrder(event);" rollOver="over();" mouseDown="down();" mouseUp="up();" rollOut="out();"/>
功能:
public function over():void{
CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,0,0);
}
public function down():void{
CursorManager.setCursor(grabbingCursor,CursorManagerPriority.HIGH,0,0);
}
public function up():void{
CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,0,0);
}
public function out():void{
CursorManager.removeAllCursors();
}
编辑12/17/09: 我已经取得了一点进展,我现在正在 rollOver 上执行此操作,
var styleSheet:CSSStyleDeclaration = StyleManager.getStyleDeclaration("DragManager");
styleSheet.setStyle("moveCursor", grabbingCursor);
CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW);
这给了我正确的翻转和正确的拖动,但是如果我尝试添加任何 函数来 rollOut 它再次搞砸了,所以现在我被抓取光标困住了。它 似乎当我在 dataGrid 上设置 rollOut 时,它会为每一行触发,相同 使用 mouseOut,有什么办法可以避免这种情况吗?
编辑 2009 年 12 月 21 日: 对于数据网格中的每个项目,滚动/鼠标移出/过火是已确认的事情。我需要的解决方案是如何防止这种情况发生,并且仅当用户将鼠标移出整个数据网格时才触发它。我需要灵活地看到森林,而不是树木。
附言。当我拖动时,卷展栏只会在每个项目上触发。 mouseout 会在每个项目上触发,无论
编辑 2009 年 12 月 21 日,当天结束:
我已经设法回答了我自己的问题,所以我的赏金代表对我来说失去了:-(无论如何,因为我的回答解决了我的问题,我将向任何可以回答这个问题的人授予赏金。我的解决方案使用 AS 来删除 rollOut/rollOver 而在 dataGrid 中,如何在不删除 rollOut/rollOver 的情况下获得相同的结果(以便在将另一个项目拖动到每个项目上时不会触发 rollOut)?
I have a datagrid that I want the user to sort the rows on. To make it obvious that it's sortable I am implementing some custom cursors. But I'm having a problem when I actually drag an item.
here's a pseudo demonstration of the problem
Application = normal cursor // fine
Rollover datagrid = open hand cursor // good so far
mousedown on datagrid = closed hand cursor // good
dragging item around = closed hand cursor // switches back to normal cursor (if I move it around real fast I can see my custom curser for an instant)
mouse up on datadrid = open hand cursor // not sure, after I drop it goes back to open hand but if I mouse down, dont move and mouse up I have a closed hand
rollout of datagrid = normal cursor //good
datagrid code:
<mx:DataGrid id="sectQuestionsDG" x="10" y="204" width="558" height="277" headerHeight="0" selectable="{editMode}"
dragMoveEnabled="{editMode}" dragEnabled="{editMode}" dropEnabled="{editMode}"
dragDrop="sectQuestReOrder(event);" rollOver="over();" mouseDown="down();" mouseUp="up();" rollOut="out();"/>
functions:
public function over():void{
CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,0,0);
}
public function down():void{
CursorManager.setCursor(grabbingCursor,CursorManagerPriority.HIGH,0,0);
}
public function up():void{
CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,0,0);
}
public function out():void{
CursorManager.removeAllCursors();
}
Edit 12/17/09:
I've made a little bit of progress, I'm now doing this on rollOver
var styleSheet:CSSStyleDeclaration = StyleManager.getStyleDeclaration("DragManager");
styleSheet.setStyle("moveCursor", grabbingCursor);
CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW);
This is giving me the correct rollover and correct drag, but if I try to add any
function to rollOut it screws up again, so now I'm stuck with the grabCursor. It
seems like when I set a rollOut on the dataGrid it's firing for each row, same
with mouseOut, is there any way to avoid that?
Edit 12/21/09:
It is a confirmed thing that roll/mouse out/over fire for every item in the datagrid. The solution I need is how to prevent that and only fire it when the user mouses out of the datagrid as a whole. I need flex to see the forest, not the trees.
PS. the rollout only fires on every item when I am dragging. mouseout fires on every item regardless
EDIT 12/21/09, End of the day:
I have managed to answer my own question so my bounty rep is lost to me :-( Anyway since my answer solves my problem I will award the bounty to anyone that can answer this. My solution uses AS to remove the the rollOut/rollOver while a user is dragging. In a dataGrid. How can you get the same result without removing the rollOut/rollOver (so that rollOut is not firing for each item as you drag another item over it)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您进行拖动时不需要更改光标,为什么不使用
DragManager
的属性isDragging
呢?并且不要忘记检查dragExit
事件,以防您落在数据网格之外。注意
有时光标在放置后会保持拖动形状,因此您可以在
sectQuestReOrder
中删除光标并将其设置回 over 状态。示例:
并在网格中添加 DragExit
Why not use the property
isDragging
ofDragManager
if you are doig a drag you dont need to change the cursor. And dont forget to check for thedragExit
event in case you drop outside the datagrid.N.B
sometimes the cursor keep with the dragging shape after the drop so you can in your
sectQuestReOrder
remove the cursor and set it back to over state.sample:
And in your grid add dragExit
我会查看 mouseOut 事件并确定当您在拖动过程中移动鼠标时它是否会触发。我见过这样的情况:拖动的对象不完全随鼠标移动,并且在很短的时间内,鼠标实际上悬停在另一个对象上(导致 mouseOut 事件触发,从而改变光标)。
I would look at the mouseOut event and determine if its firing when you're moving the mouse during a drag. I have seen cases where the dragged object doesn't move exactly with the mouse, and for a short while, the mouse is actually hovering over another object (causing the mouseOut event to fire, thus changing the cursor).
好的,请给加布里埃尔一些支持,让我的思想摆脱困境,并以完整模式回到这个问题。我必须经过几个步骤才能得到我的答案
1)从 mxml 中删除 rollOver、rollOut 和 mouseUp 的侦听器,并通过 AS 中的 addEventListener 方法添加 rollOver 和 rollOut
2)将侦听器 DragComplete 添加到 mxml 并分配之前分配给 mouseUP 的函数
3) 将 main 函数更改为:
OK some props to Gabriel there for getting my mind out of a rut and back into this problem in full mode. I had to go through a few steps to get to my answer
1)remove the listeners for rollOver, rollOut, and mouseUp from the mxml and add rollOver and rollOut through the addEventListener method in AS
2) add the listener dragComplete to the mxml and assign the function previously assigned to mouseUP to it
3) change the main function to this: