5 Replies Latest reply on Jul 26, 2007 7:31 PM by theLoggerGuy

    Cursor positioning

    cstormer
      How can you get the current position of the blinking cursor in a text area and is there a way to set this position programmatically?
        • 1. Re: Cursor positioning
          dimival Level 1
          There is a setSelection( ) method which lets you select the text in an specific range determined by an start and end indexes, if these indexes are the same then the cursor is positioned on that index, example:

          textArea.setSelection(4, 4);

          that will set the cursor on the index 4 of the text inside a textArea
          • 2. Re: Cursor positioning
            cstormer Level 1
            Thanx for You answer man but I need curent position in pixels.Do You have any idea about that?
            • 3. Re: Cursor positioning
              dimival Level 1
              Nope, not really
              • 4. Re: Cursor positioning
                theLoggerGuy Level 1
                This is an old post, but exactly what I'm looking for. Unfortunately no answer. Does anyone know how to get the current position in pixels in a TextArea?
                • 5. Re: Cursor positioning
                  theLoggerGuy Level 1
                  The Internet has all the answers. I modified this from someone else's code (unfortunately I can't find the originator's uri)

                  package components
                  {
                  import mx.controls.TextArea;
                  import mx.controls.TextInput;
                  import mx.core.UIComponent;

                  public class AdvancedTextArea extends TextArea
                  {
                  public function AdvancedTextArea( ):void
                  {
                  super();
                  }

                  override protected function createChildren( ):void
                  {
                  super.createChildren( );
                  }

                  public function get caretPosition( ): int
                  {
                  return textField.caretIndex;
                  }

                  public function set caretPosition( newPostion: int ): void
                  {
                  this.selectionBeginIndex = newPostion;
                  this.selectionEndIndex = newPostion;
                  }
                  }
                  }


                  Declare it thusly:

                  <local: AdvancedTextArea id="myAta"/>


                  Access the cursor position:

                  trace ( "current position " + myAta.caretPosition );