使用textinput灵活移动视图问题

时间:2014-05-27 11:19:44

标签: actionscript-3 flex actionscript flex4

当用户拖动视图而不是textinput时,我试图使视图(包含textinput)可移动。这是代码:

view.addEventListener(MouseEvent.MOUSE_DOWN, handleDown);
view.addEventListener(MouseEvent.MOUSE_UP, handleUp);`

和处理程序:

  private function handleDown(event:MouseEvent):void{
     //move the view if anything else than input text and action is selected
     if (!event.target.hasOwnProperty("text") && !DragManager.isDragging) {
        this.startDrag();
     }
  }
  private function handleUp(event:MouseEvent):void{
     this.stopDrag();
  }

问题是如果我尝试用鼠标标记textInput中的部分文本,我会再次移动视图。我怎么解决这个问题?

P.S。如果我不在textInput命中区域,我也尝试开始拖动:

   var point:Point = localToGlobal(new Point(mouseX, mouseY));
   if (!view.textInput.hitTestPoint(point.x, point.y))) {
        this.startDrag();
   } 

但它也不起作用(说即使我在文本输入中,我也没有)。有什么想法吗?

4 个答案:

答案 0 :(得分:0)

您需要将此条件添加到handleDown函数:

以下是一份工作样本:

mc.addEventListener(MouseEvent.MOUSE_DOWN, handleDown);
mc.addEventListener(MouseEvent.MOUSE_UP, mouseUp);

function handleDown(event:MouseEvent):void{
//move the view if anything else than input text and action is selected
  if (stage.focus != mc.textInput) {
    this.startDrag();
  }
}

function mouseUp(e:Event):void
{
    mc.stopDrag();
}

答案 1 :(得分:0)

private function handleDown(event:MouseEvent):void{
     //move the view if anything else than input text and action is selected
     if (!event.currentTarget.hasOwnProperty("text") && !DragManager.isDragging) {
        this.startDrag();
     }
  }
  private function handleUp(event:MouseEvent):void{
     this.stopDrag();
  }

答案 2 :(得分:0)

实际上检查event.parent.hasOwnProperty(" text")修复了问题,因为当我点击文本时,目标是文本本身,而不是文本输入。

答案 3 :(得分:0)

抱歉,我不能正确理解这个问题。

这可能会有所帮助,如果你能负担得起额外的变量“isDraggable”。

private var isDraggable:Boolean = true;  // You can make any component non-draggable  

    view.textInput.addEventListener(MouseEvent.MOUSE_DOWN, handleTIDown);
    view.textInput.addEventListener(MouseEvent.MOUSE_OUT, handleTIOut);
    view.textInput.addEventListener(MouseEvent.MOUSE_UP, handleTIOut);        


    view.addEventListener(MouseEvent.MOUSE_DOWN, handleDown);
    view.addEventListener(MouseEvent.MOUSE_UP, handleUp);




 private function handleTIDown(event:MouseEvent):void{
      isDraggable = false;

  }
  private function handleTIOut(event:MouseEvent):void{
     isDraggable = true;
  }


 private function handleDown(event:MouseEvent):void{
     //move the view if anything else than input text and action is selected
     if (isDraggable && !event.target.hasOwnProperty("text") && !DragManager.isDragging) {
        this.startDrag();
     }
  }
  private function handleUp(event:MouseEvent):void{
     this.stopDrag();
  }