K_G
K_G

Reputation: 2901

AS3 TextField: Append text at a certain line?

I'm trying to find a way to append text (appendText) at a certain TextField line number.

I found a way to return the first character of a line:

tf.text.charAt(tf.getLineOffset(10)); //selects line 10

But I haven't found a way to append text. Any help would be appreciated!

Upvotes: 0

Views: 1288

Answers (1)

BadFeelingAboutThis
BadFeelingAboutThis

Reputation: 14406

This should do the trick (put the supplied text at the start of the supplied line), though there may be a more efficient way of doing it.

function prependToLine(textField:TextField, line:int, text:String):void {
    var lineOffset:int = textField.getLineOffset(line-1);
    textField.text = textField.text.substring(0,lineOffset) + text + textField.text.substr(lineOffset);
}

Upvotes: 1

Related Questions