4 Replies Latest reply on Oct 3, 2006 4:05 PM by bdeen

    Text Coordinates in TextArea

    FlightGuy Level 1
      I'm trying to write a custom control that extends a text area, and provides some IDE-style auto-complete functionality. To do this, I need to be able to position a pop-up menu just below the start of the word being edited.

      So, I need the x and y coordinates of a specific index in my TextArea. I sort of hoped that a TextRange object would give it to me, but it doesn't.

      Any suggestions?
        • 1. Re: Text Coordinates in TextArea
          dave cragg Level 2
          The textField property of text objects has a getCharBoundaries method. This returns a Rectangle object describing the coordinates of any nth character in the text.

          I used this to draw rectangles that cover particular words in a textArea. By getting the rectangle of the first and last charcters of the word, I could calculate the needed coordinates from that. The main statements were of this form:

          var myRect1:Rectangle = myTextArea.textField.getCharBoundaries(n);

          where n is the character index.

          I'm pretty new to Flex, and don't know yet if there is another way to achieve this. If there is, I'd love to hear.

          • 2. Re: Text Coordinates in TextArea
            I believe textarea has a protected getTextField() method (or something named like that) so you have to override the TextArea.
            • 3. Re: Text Coordinates in TextArea
              FlightGuy Level 1
              Thanks to both of you - I was successful in using the textField property and my autocomplete dropdown now works a charm.
              • 4. Re: Text Coordinates in TextArea
                bdeen Level 1
                you might need to be careful, i've been working on a spell checker for Text areas and the calculations for some coordinates are off if you use different font sizes (probably different fonts as well).