AS3 – textfield setSelection()

Have you tried to set selection on atextfield after a validation procedure? Have you noticed that it doesn’t work quite right? Here’s the quick solution for that:

Normally you would use the yourTextField.setSelection(startIndex, endIndex); method, but like I said before that doesn’t really work very well.

You just need to set the focus to the textfield and then set the selection:

Example: (assuming you have a textfield called “tf”)

....
tf.stage.focus = tf;
tf.setSelection(0, tf.length);
...

And that’s how you solve the textfield.setSelection() problem

Creative Commons License
The AS3 – textfield setSelection() by Tiago's Weblog, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 2.5 Switzerland License.
Leave a comment

3 Comments.

  1. Thanks, helped me a lot!

  2. Thank you! I’ve searched high and low for this solution. Glad I found you.

  3. Kool , you are the one of the best i come across

Leave a Reply


[ Ctrl + Enter ]