Set selection to a textfield


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // To set selection a textfield, use the following;
  2.  
  3. var _textInput1:TextField = new TextField();
  4. _textInput1.addEventListener(Event.CHANGE, handleTextChange, false, 0, true);
  5.  
  6. function handleTextChange(event:Event):void {
  7.  
  8. switch(event.target){
  9. case _textInput1:
  10. trace("input 1");
  11. if(_textInput1.text.length == 2) {
  12. stage.focus = _textInput2;
  13. _textInput2.setSelection(0, _textInput2.text.length); // or second param equals 0 -> 0,0
  14. }
  15. break;
  16. }
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.