View Full Version : Override default text drag behavior of TextArea

02-01-2008, 07:26 AM
In AIR, you can drag selected text and drop it into the same TextArea or into another TextArea (Or even outside of the AIR window). I would like to override or prevent this behavior, but I have not yet found a way.
It seems that this behavior is embedded in the TextField object.

Is there anyone that can point me in the right direction?

02-05-2008, 04:41 PM
This behavior is not specific to AIR. What you could do is just make the text non-selectable. But to have it selectable AND not dragable, I don't think is possible. I'll try some tests.

02-05-2008, 04:49 PM
Okay, correction: it IS specific to AIR.

...working on solution, i'll get back to you.

02-05-2008, 05:11 PM
Well, here's an idea. See what you can get from it.

tf1_txt.addEventListener(MouseEvent.MOUSE_DOWN, listen);
tf1_txt.addEventListener(MouseEvent.MOUSE_UP, noListen);

var myMouseX:Number = 0;
var myMouseY:Number = 0;

function listen(event:MouseEvent):void
myMouseX = this.stage.mouseX;
myMouseY = this.stage.mouseY;
tf1_txt.addEventListener(MouseEvent.MOUSE_MOVE, mover);

function noListen(event:MouseEvent):void
tf1_txt.removeEventListener(MouseEvent.MOUSE_MOVE, mover);

function mover(event:MouseEvent):void
trace("Aha! Caught you!");

You'll just create two input text fields, tf1_txt and tf2_txt. Enter some data in the first text field (tf1_txt) then try to select and drag it to the second (tf2_txt).

02-06-2008, 08:03 AM
Thanks for your input.

And you were in fact right initially when you claimed this not to be specific to AIR; this behaviour has been there all the time if the code was running in the Safari web browser (or so I've been told by Mac users).

Eventually we solved it with a bit of a hack: We pick up the nativeDragDrop event and set the text of the target area back to what it was before the dragged text was dropped onto it. This does not prevent the user from dragging and dropping text but it at least prevents the effects from that action.