2 Replies Latest reply on Feb 2, 2009 8:32 PM by SiHoop

    Text field width

    SiHoop Level 1
      I'm trying to find the x coordinate of each character in a text field. To do this, I place the text into an array and then add the text (plus a space) into a second text field. I calculate the width of second text field to calculate the exact position of each character in the string. My problem is that when I trace the position of each character, the line breaks on the screen do not match the line breaks in my trace statement. In the trace shown below, the letter 'e' should be the last letter that shows in the text field, but the letters 'f' and 'g' both show on the same line. Can anyone explain what I'm doing wrong?

      Text width=17 Text=a Text field width=17
      Text width=18 Text=b Text field width=35
      Text width=17 Text=c Text field width=52
      Text width=18 Text=d Text field width=70
      Text width=17 Text=e Text field width=87
      Text width=15 Text=f Text field width=2
      Text width=17 Text=g Text field width=19
      Text width=18 Text=h Text field width=37
      Text width=13 Text=i Text field width=50
      Text width=14 Text=j Text field width=64
      Text width=18 Text=k Text field width=82
      Text width=13 Text=l Text field width=95
      Text width=23 Text=m Text field width=18
      Text width=18 Text=n Text field width=36
      Text width=18 Text=o Text field width=54
      Text width=18 Text=p Text field width=72
      Text width=18 Text=q Text field width=90
      Text width=15 Text=r Text field width=5
      Text width=16 Text=s Text field width=21
        • 1. Re: Text field width
          SiHoop Level 1
          I've just discovered the difference between textField.width and textField.textWidth, but still the values in the code below do not work properly. The problem remains that the traced textWidth of the text characters do not sum to the locations of the line breaks in the textField.
          • 2. Re: Text field width
            SiHoop Level 1
            The error was the manner in which the end of a line was calculated.

            //Track the width of each line of the text field
            textFieldWidth += tf1.textWidth
            textFieldWidth = textFieldWidth%tf0.width

            should have been:

            //Track the width of each line of the text field
            textFieldWidth += tf1.textWidth
            if(textFieldWidth>tf0.width){
            textFieldWidth=tf1.textWidth
            }