Changing a text field's position

You can change a text field's position on the Stage at runtime. You need to set new values for the text field's _x and _y properties, as shown in the following example.

To reposition a text field by using ActionScript:

  1. Create a new FLA file and save it as positionText.fla.
  2. Add the following ActionScript to Frame 1 of the Timeline:
    this.createTextField("my_txt", 10, 0, 0, 300, 200);
    my_txt.border = true;
    my_txt.text = "Hello world";
    my_txt._x = (Stage.width - my_txt._width) / 2;
    my_txt._y = (Stage.height - my_txt._height) / 2;
    
  3. Save the Flash document and select Control > Test Movie to see the text field centered on the Stage.

For samples that demonstrate how to work with text fields using ActionScript, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download the Samples zip file and navigate to the ActionScript 2.0/TextFields folder to access these samples: