1. Click on the text tool and in the Property Inspector choose Dynamic text, multiline, show border icon, and antialias for animation, and then click and drag on the Stage to create a text field.
2. Give the text field an instance name in the property inspector (content_txt is assumed for the ActionScript below).
3. Add an actions layer and in the first frame of this layer add the following ActionScript:
var content:URLRequest = new URLRequest("bill.txt");Remember that variable names are arbitrary. bill.txt is the name of the text file containted the text you want to load. By simply using the file name, this means the .txt file will be in the same folder as the .swf file produced by the .fla movie. The event listener executes the function when the file is loaded and ready to use.
4. If one publishes the Flash movie, and then changes the .txt file, simply refreshing the web page will make the new text appear in the page without any intervening use of the Flash authoring tool, e.g. by creating a new .swf file.
5. It is important that the original text size block be large enough to accomodate the dynamic text at the font size chosen. If this is not the case, either increase the size of the block for the text, or decrease the font size associated with the text block.
Flash CS3/4 supports the use of a limited set of html tags in the txt file that is loaded into the page such as <a>, <b>, <font color and size attributes), <i>, <li>, <p>, <br>, <br>. The only change required in the ActionScipt is to change the property of the text box, i.e. replace content_txt.text to content_txt.htmlText. You can also apply stylesheets to text. For details see http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/TextField.html
1. Click on the Text Tool and change the text type in the Property Inspector to Input Text. Click and drag a text box.
2. Give the text field a name in the Property Inspector, say name_txt
3. Create a button symbol and place an instance of the symbol on the stage in frame 1 (enter_btn is the assumed name for this symbo in the ActionScript below).
4. Add an actions layer and in frame 1 of this layer add the following ActionScript:
stop();
var nameString:String;
enter_btn.addEventListener(MouseEvent.CLICK, onClick)
function onClick(event:MouseEvent):void {
if (name_txt.text != "") {nameString = name_txt.text; gotoAndStop(2); }
else stop();}
5. In frame 2 add a blank keyframe (F7) in the initial layer, click on the Text Tool, in the Property Inspector set the text type to dynamic text, draw a box and in the Property Inspector. Name the instance as message_txt using the Property Inspector
6. In frame 2 of the actions layer, press F7 to add a blank keyframe and add in the Actions layer the following ActionScript
message_txt.text = "Welcome " + nameString:
This needs to be in frame 2 if the dynamic text box doesn't exist in Frame 1, otherwise you will get an error message.
Revised: August 3, 2010. Comments to Bill Pegram, bill@billpegram.com