RE: [Flashcoders] Getting the line index at the caretIndex

2010-04-10 Thread Benny
After *appending* a character the caret is positioned after the last character input pointing to the next position it will accept input. Hence when you call getLineIndexOfChar(caret) you ask for info about a none existing character. This should work: var tf:TextField = new TextField(); tf.type =

Re: [Flashcoders] Getting the line index at the caretIndex

2010-04-09 Thread Taka Kojima
You have to do something like caret-1, and do some logic to detect if the current line contains at least one character, and if it doesn't do a line++, something along those lines. My suspicion (which I just confirmed) was that the caret isn't actually counted as a character in the textField,

Re: [Flashcoders] Getting the line index at the caretIndex

2010-04-09 Thread Taka Kojima
I was curious, seems to get pretty ugly logic wise actually, this is the quickest, easiest solution I came up with: tf.addEventListener(Event.CHANGE, onChange); function onChange(event:Event):void{ var caret:int = tf.caretIndex; tf.appendText(_); var line:int = tf.getLineIndexOfChar(caret);