Search code examples
actionscript-3apache-flexactionscriptflex4

Flex movable view issue with textinput


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?


Solution

  • 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.