Flash Game Design  
 
   
 
Tutorials Articles
   
       
 
 
Dynamic Text using AS 3
 
Step 1.

In it's most simplest form the following 3 lines of code (a) are needed to create a dynamic text field using Actionscript 3. The 3 lines of code are placed on the first frame of the timeline. The text (b) is displayed with default formatting.

a)   b)
 

Line 1 - Create a TextField object called txt

Line 2 - Add what you want to be displayed, to the text property of the new object

Line 3 - Add the textfield object to the stage. You can also add it to an movieclips you create.

 

 
 
Step 2.
So you've now created a text field on the stage, but you'll likely want to position it somewhere else and format it in some way. First of all we'll position the text
a)   b)
 
 
Step 3.
To format the text we need to create a TextFormat object and set some properties. Here is a complete list of the formatting properties.
a)   b)   c)

Line 6 - Create a TextFormat object called format

Line 7 - set the color of "format". I've set it to red but you can set it to any color, by using the code that is produced in the color panel in Flash (c)

Line 8 - Set the font of the text. The default (step 1) is verdana

Line 9 - Set the size of text

Line 10 - Make the text bold

Line 11 - set "format" as the TextFormat of the txt object

 
Dowload Source
   
More Flash Tutorials
Funky Flash Site Glitter Graphic Jagged Transition
   
Bubble Flow Text Basic Flash Site Advanced Flash Site
Scroll Gallery Falling Star Text Drop Down Menu
     
Rotating Gallery Shooting Bullets XML menu
     
     
 
Site Copyright © 2006 - 2009 Nick DS. All rights reserved.