Setting the Insertion Point in a Text Field : focus « TextField « Flash / Flex / ActionScript






Setting the Insertion Point in a Text Field

 


package {

  import flash.display.Sprite;
  import flash.text.TextField;
  public class Main extends Sprite {
    public function Main(  ) {
      var field:TextField = new TextField(  );
    
        stage.focus = field;                  // Set the focus to the text field
        field.text = "this is example text";  // Set the text value
        field.setSelection(0, 0);
        
        
        trace(field.caretIndex);
        addChild(field);
    }
  }
}

        








Related examples in the same category

1.Assigning Focus to a Text Field
2.To remove focus from a text field you should assign Stage.focus the null value