5 Replies Latest reply on Dec 9, 2007 7:40 AM by Newsgroup_User

    Create Draggable Input text

    hanyegypt
      I Made a Draggable Inputtext but when I drag it I can not write into it ,I try to put a button beside input text and put the Drag action in the button ,it works fine but ,is there any way to make the Draggable Input text by itself without the button beside it
        • 1. Re: Create Draggable Input text
          Level 7
          >>I Made a Draggable Inputtext but when I drag it I can not write into it ,I
          >>try
          to put a button beside input text and put the Drag action in the button ,it
          works fine but ,is there any way to make the Draggable Input text by itself
          without the button beside it
          <<

          Right, probably you put the input text into a movie clip and then assigned
          onPress and onRelease events? Then the mc containing the text absorbs the
          mouse events so your input field can't get the focus. You can get around
          this fairly easily using a mouse listener that just moves the field with the
          mouse. I have an input text field with an instance name of dragText, and the
          code below is on frame 1. Note in the MouseMove test I am also testing to
          see if the control key is down - I added this to allow the mouse to still
          function normall to select text for editing, but move the field when control
          is down.


          var mouseListener:Object = new Object();
          mouseListener.onMouseDown = function() {
          this.deltaX = _xmouse - dragText._x;
          this.deltaY = _ymouse - dragText._y;
          this.dragging = true;
          };
          mouseListener.onMouseUp = function() {
          this.dragging = false;
          };
          mouseListener.onMouseMove = function() {
          if((_xmouse >= dragText._x) && (_xmouse <= dragText._x + dragText._width)
          && (_ymouse >= dragText._y) && (_ymouse <= dragText._y + dragText._height)
          && this.dragging && Key.isDown(Key.CONTROL)){
          dragText._x = _xmouse - this.deltaX;
          dragText._y = _ymouse - this.deltaY;
          }
          };
          Mouse.addListener(mouseListener);




          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Create Draggable Input text
            hanyegypt Level 1
            Thank you for your help Dave,
            you are the man
            can i get the name of the Draggable Text Daynamicly form the mouse event i.e when the mouse Press down tell me the name of the instnace
            • 3. Re: Create Draggable Input text
              hanyegypt Level 1
              Thank you for your help Dave,
              you are the man
              can i get the name of the Draggable Text Daynamicly form the mouse event i.e when the mouse Press down tell me the name of the instnace
              • 4. Re: Create Draggable Input text
                hanyegypt Level 1
                Thank you for your help Dave,
                you are the man
                can i get the name of the Draggable Text Daynamicly form the mouse event i.e when the mouse Press down tell me the name of the instnace
                • 5. Re: Create Draggable Input text
                  Level 7
                  I take it you want to move more than one text instance? I'd throw the code
                  in a class, then make an instance for each text field you want to move.


                  class com.blurredistinction.MoveText
                  {
                  private var myMouse:Object;

                  function MoveText(dragText:TextField)
                  {
                  myMouse = new Object();

                  myMouse.onMouseDown = function() {
                  this.deltaX = _xmouse - dragText._x;
                  this.deltaY = _ymouse - dragText._y;
                  this.dragging = true;
                  };
                  myMouse.onMouseUp = function() {
                  this.dragging = false;
                  };
                  myMouse.onMouseMove = function() {
                  if((_xmouse >= dragText._x) && (_xmouse <= dragText._x + dragText._width)
                  && (_ymouse >= dragText._y) && (_ymouse <= dragText._y + dragText._height)
                  && this.dragging && Key.isDown(Key.CONTROL)){
                  dragText._x = _xmouse - this.deltaX;
                  dragText._y = _ymouse - this.deltaY;
                  }
                  };

                  Mouse.addListener(myMouse);
                  }
                  }


                  Then in Flash:

                  var m1 = new com.blurredistinction.MoveText(dragText);
                  var m2 = new com.blurredistinction.MoveText(dragText2);



                  --
                  Dave -
                  Head Developer
                  http://www.blurredistinction.com
                  Adobe Community Expert
                  http://www.adobe.com/communities/experts/