在拖动工作期间拖放dataGrid,自定义光标

时间:2009-12-17 00:03:21

标签: flex actionscript datagrid flex3 drag-and-drop

我有一个数据网格,我希望用户对行进行排序。为了表明它是可排序的,我正在实现一些自定义游标。但是当我实际拖动一个项目时,我遇到了问题。

这是问题的伪示范

应用程序=正常光标//很好

翻转datagrid =打开手形光标//到目前为止

mousedown on datagrid =关闭手形光标//好

拖动项目=关闭手形光标//切换回正常光标(如果我快速移动它我可以立即看到我的自定义光标)

鼠标按下datadrid =打开手形光标//不确定,在我放下后它会回到打开的手但是如果我鼠标向下,不要移动并且鼠标向上我有一个闭合的手

推出datagrid =正常游标//好

datagrid代码:

<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);

这给了我正确的翻转和正确的拖动,但是如果我尝试添加任何 功能滚动它再次拧紧,所以现在我卡住了grabCursor。它 好像当我在dataGrid上设置rollOut时,它会为每一行触发,同样如此 使用mouseOut,有什么办法可以避免吗?

编辑12/21/09: 对于数据网格中的每个项目,滚动/鼠标输出/结束是一个确认的事情。我需要的解决方案是如何防止这种情况,并且只有当用户将数据网格作为一个整体移出时才触发它。我需要弯曲看森林,而不是树木。

PS。当我拖动时,卷展栏仅在每个项目上触发。无论

,mouseout都会触发每个项目

编辑12/21/09,当天结束:
我已经设法回答了我自己的问题,所以我的赏金代表对我失去了:-(无论如何,因为我的答案解决了我的问题,我会将赏金奖励给任何可以回答此问题的人。我的解决方案使用AS删除rollOut / rollOver而用户正在拖动。在dataGrid中。如何在不删除rollOut / rollOver的情况下获得相同的结果(以便在将另一个项目拖到其上时不会为每个项目触发rollOut)?

3 个答案:

答案 0 :(得分:1)

我会查看mouseOut事件,并确定在拖动过程中移动鼠标时是否触发。我已经看到拖动的对象不能用鼠标移动的情况,并且在一段时间内,鼠标实际上是悬停在另一个对象上(导致mouseOut事件被触发,从而改变了光标)。

答案 1 :(得分:1)

为什么不使用isDragging的属性DragManager如果你做了一个你不需要更改光标的拖动。如果你掉到数据网格之外,别忘了检查dragExit事件。

N.B 有时光标会在拖放后保持拖动形状,因此您可以在sectQuestReOrder移除光标并将其设置回过度状态。

样品:

public function over(evt:Event):void{ //on mouse over, added with AS
  if (DragManager.isDragging) // you are dragging so no cursor changed
   return;

  CursorManager.removeAllCursors();
  CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,-7,-7);
  var styleSheet:CSSStyleDeclaration = StyleManager.getStyleDeclaration("DragManager");
  styleSheet.setStyle("moveCursor",grabbingCursor); //style set for the drag cursor
}
public function down(evt:Event):void{ // on mouse down
    CursorManager.removeAllCursors();
    CursorManager.setCursor(grabbingCursor,CursorManagerPriority.LOW,-7,-7);     
}
public function up(evt:Event):void{
    CursorManager.removeAllCursors();
    CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,-7,-7);
}
public function out(evt:Event):void{
 if (DragManager.isDragging) // you are dragging so no cursor changed
  return;
 CursorManager.removeAllCursors();
}
public function sectQuestReOrder(e:Event):void{
    // sometime you will be stuck with the moving cursor
    // so after the drop done reset cursor to what you want
 CursorManager.removeAllCursors();
 CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,-7,-7);
 ...
}
public function onDragExit(e:Event):void {
    // in case you go out of the datagrid reset the cursor
    // so when you do a drop outside you ll not get one of your dragging cursor
 CursorManager.removeAllCursors();
}

在你的网格中添加dragExit

 <mx:DataGrid 
      id="sectQuestionsDG" 
      x="10" y="204" width="558" height="277" headerHeight="0" 
      selectable="{editMode}"
      dragExit="onDragExit(event)"
      dragMoveEnabled="{editMode}" 
      dragEnabled="{editMode}"
      dropEnabled="{editMode}"
      dragDrop="sectQuestReOrder(event);" 
      rollOver="over(event);" 
      mouseDown="down(event);" 
      mouseUp="up(event);" 
      rollOut="out(event);"/>

答案 2 :(得分:0)

确定一些道具给Gabriel那里让我的思绪脱离了车辙并以完整模式回到这个问题。我必须经过几个步骤才能得到答案

1)从mxml中删除rollOver,rollOut和mouseUp的侦听器,并通过AS中的addEventListener方法添加rollOver和rollOut

2)将监听器dragComplete添加到mxml并将之前分配给mouseUP的函数分配给它

3)将主要功能改为:

public function over(evt:Event):void{ //on mouse over, added with AS
    CursorManager.removeAllCursors();
    CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,-7,-7);
    var styleSheet:CSSStyleDeclaration = StyleManager.getStyleDeclaration("DragManager");
    styleSheet.setStyle("moveCursor",grabbingCursor); //style set for the drag cursor
}
public function down(evt:Event):void{ // on mouse down
    CursorManager.removeAllCursors();
    CursorManager.setCursor(grabbingCursor,CursorManagerPriority.LOW,-7,-7);
    sectQuestionsDG.removeEventListener(MouseEvent.ROLL_OVER,over);
    sectQuestionsDG.removeEventListener(MouseEvent.ROLL_OUT,out);
    //this is why I had to take it off the mxml, can only remove listeners
    //added with the addEventListener, I don't remember where I read that.
}
public function up(evt:Event):void{
    CursorManager.removeAllCursors();
    CursorManager.setCursor(grabCursor,CursorManagerPriority.LOW,-7,-7);
    sectQuestionsDG.addEventListener(MouseEvent.ROLL_OVER,over);
    sectQuestionsDG.addEventListener(MouseEvent.ROLL_OUT,out);
}
public function out(evt:Event):void{
    CursorManager.removeAllCursors();
}