Concepts > Playing with Text in Flash
 
 
 
  Text Tool and Text Fields  
 

You use the Text Tool(T), which is present on the 3 rd left position of the toolbar. Just select the text tool and click on the stage.

 
 

To add text to your flash file, you have three options:

 
 

Static Text – It is used to write any text on your flash file.

 
 

Dynamic Text – When you want to add text on runtime or want to load text from any variables, the text field needs to be dynamic.

 
 

Input Text – When you want the user to enter some value, you can select the input option in the properties panel.

 
 
 
 

Some additional options available with textfields in the properties panel:

 
 

•  Bold – To make the text bold or unbold.

•  Italics

•  Character Spacing – To increase or decrease spacing in the characters.

•  Alias/Anti Alias – If you mark the text as alias, it renders the text as smooth.

•  Selectable – If you make this option active, the text in this field is selectable.

•  HTML Text – This option ensures that the text field accepts html text.

•  Show border – If you want to show the border of the text field.

 
     
 

How to use a dynamic text field:

 
 
1) Open a new document and set size 200*200.
 
 
2) Select the text tool, and make a text field on the stage. Set the textfield size to 300*20.
 
 
3) In the properties panel, select the option ‘dynamic', and in the field below give it an instance name, say, txtName.
 
 
4) In the properties panel, select multiline.
 
 
5) Select the first frame, and press F9.This will open the actions panel. In the actions panel type the following,
 
 


/* --------------- Dynamic Textfield Example ------------------ */
stop();
txtName.wordWrap=true;
txtName.autoSize=true;
txtName.text="Hi.This example is from Flashonmind to learn how to use a dynamic text field";

 
 
6) If you want the text field to render html text, write this in the action panel.
 
 


/* -------------- Dynamic TextField with html text ----------------*
stop();
txtName.wordWrap=true;
txtName.autoSize=true;
txtName.html=true;
txtName.htmlText="<B>This example is from Flashonmind.com to learn how to use a dynamic text field</B>";

 
 
7) A textfield that can render html text can also be used to hyperlink any text.
 
 

For example,
txtName.htmlText="<B>This example is from <a href= http://www.flashonmind.net>Flashonmind.net</a> to learn how to use a dynamic text field</B>";

 
     
 

How to apply a formatting to a text field?

 
 

To apply formatting to a text field, Flash provides a text format object. You can create a new text format object and set its attributes, and then apply it to the text field.
Write this along with the above code:

 
 


var txt_fmt:TextFormat = new TextFormat();
txt_fmt.font="verdana";
txt_fmt.size = 14;
txt_fmt.color=0x000000;
txtName.setTextFormat(txt_fmt);