# TextField and getCharBounds

**URL:** https://forum.kirupa.com/t/textfield-and-getcharbounds/247489
**Category:** flash
**Created:** [December 24, 2007, 2:16pm UTC](https://forum.kirupa.com/t/textfield-and-getcharbounds/247489 "2007-12-24T14:16:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tezzutezzu](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tezzutezzu](https://forum.kirupa.com/u/tezzutezzu)
#### Post date: [December 24, 2007, 2:16pm UTC](https://forum.kirupa.com/t/textfield-and-getcharbounds/247489/1 "2007-12-24T14:16:51Z")

</div>

For some strange reason, I can’t get to read the positions of the last character in my textfield. Here’s the code:

```php

var textBox:TextField = new TextField();
var counter:Number = 0;
var rectangle:Rectangle;

var s:String = "Lorem ipsum dolor sit amet ";
textBox.width = 100;
textBox.wordWrap = true;
textBox.multiline = true;
textBox.autoSize = 'left';

textBox.text = s;
addChild(textBox);

for (var i:Number=0; i<textBox.numLines; i++) {
    if (i>0) {
        counter++;
    }
    var line:String = textBox.getLineText(i);
    counter+=line.length-1; //adds the length of current line for further matching in the whole text string

    if (counter<s.length-1) {
        rectangle = (textBox.getCharBoundaries(counter));
    } else {
        trace("last character of the text")
        trace (textBox.getCharBoundaries(counter)) // returns null why?
    }
    createRect(rectangle);
    
    trace(i +1+"° "+line.length.toString()+" "+counter.toString()+" "+s.charAt(counter));
  
}

function createRect(r:Rectangle) {
    var s:Shape = new Shape();
    s.graphics.beginFill(1,.5);
    s.graphics.drawRect(r.x, r.y, r.width, r.height);
    s.graphics.endFill();
    addChild(s);
}

```

edit: I found out that for an even stranger reason this code won’t work if the wrapped lines are more than 9. In fact the above code works, but if you keep adding lines to the string it will eventually stop when the lines are 10 or more.
