0
votes

I am trying to make a view (containing a textinput) movable when the user drags the view anywhere but the textinput. Here is the code:

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

and the handlers:

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

The problem is that if I try to mark part of the text in the textInput with the mouse I am moving the view again. How I can fix this?

P.S. I also tried to start dragging if I'm not in the textInput hit area:

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

but it doesn't work too (says I'm out of the text input even if I am in it). Any ideas?

4

4 Answers

0
votes

You need to add this condition to the handleDown function:

Here is a working sample:

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();
}
0
votes
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();
  }
0
votes

Actually a check for event.parent.hasOwnProperty("text") fixed the problem because when I was clicking on the text the target was the text itself, but not the text input.

0
votes

Sorry, I did not understand the problem properly.

this may help , If you can afford an extra variable "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();
  }