Page 1 of 1

Simple Method of Loading Dynamic Text from a Text File Rate Topic: -----

#1 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 6006
  • View blog
  • Posts: 10,429
  • Joined: 28-September 07

Post icon  Posted 07 May 2008 - 08:54 AM

The premise of this tutorial is to show you how to use ActionScript and a text file to create dynamic text in a Flash presentation as seen here.

Flash can be used to create some unique and amazing websites and presentations. However, changing text within a Flash presentation can be an aggravation. In this tutorial, I will outline one method of simplifying this process.

Step 1: Creating the Buttons

Use the dynamic text option over a button shape to create your links. In the example site shown above, I have used green rectangles for my buttons with a dynamic text area over top.

Set the button shapes go to frame[x], where x is the frame number corresponding to the text to be used in that particular frame. In my example, the frames linked to are consectutive (ie, Button1 links to frame1, etc).

Set each dynamic text box a unique variable name. Keep these variable names in mind as you will need them later. In my example, I have used &t_var1, &t_var2, etc.

Step 2: Starting the Text File

Next, create a new text file. In my example, I have named mine "text.txt". We will be listing the text for the dynamic text areas over the button shapes.

Please bear in mind you will need to set fonts, font sizes and text colors for these text areas in your properties tab in Flash. And remember to use the variable names designated to each text area in the previous step!

&t_var1=Link 1
&t_var2=Link 2
&t_var3=Link 3
&t_var4=Link 4



Step 3: Creating the Text Area in Flash

Now you can add the following ActionScript to each Flash frame affected by the dynamic text. Feel free to play around with the specific settings to suit your needs. The ActionScript below merely shows the settings used in my example.

In the loadVariable command, be sure to change "text.txt" to the name of your text file. The line "_root" indicates the text file is located in the same directory as your swf.

In the createTextField command, you will have to adjust the numeric values to indicate the desired size and position of your dynamic text area. Hint: It may be easier to set frmInfo.border to "true" until the size and position are adjusted to suit your needs. In my example, my text area location remains the same across all frames, though the size and location used could be varied from one frame to another.

The variable name declared in the frmInfo.variable command MUST be the same variable name used in your text file in the next step. Change this variable name for each frame affected by the dynamic text. For my example, I have used "text1", "text2", "text3" and "text4".

loadVariables("text.txt",_root);
_root.createTextField("frmInfo",1,169,60,362,361);
frmInfo.multiline = true;
frmInfo.wordWrap = true;
frmInfo.border = false;
frmInfo.html = true;
frmInfo.type = dynamic;
frmInfo.selectable = false;
frmInfo.background = false;
frmInfo.variable = "text1";
stop();



Step 4: Adding the Text to the Text File

Now back to our text file. On a new line below your link names, add the code shown below. Remember to change the variable names to match the variables used in your ActionScript in the previous step! Notice also that you will change fonts, font sizes and text colors for the text area inside the text file.

&text1=<font face="Arial"><font size="15"><font color="#003060">
Add text here.  With wordwrap and multiline functions enabled in the ActionScript, this text should wrap around the text area as it would in a CSS container on an HTML page.  With HTML set to True, the bracketed information on font sizes and colors should also work in your Flash presentation.

&text2=<font face="Tahoma Bold"><font size="25"><font color="#ff0000">
Add a bunch of junk related to your second link here.

&text3=<font face="Impact"><font size="15"><font color="#ff00ff">
Add more junk related to your third link here.

&text4=<font face="Arial"><font size="12"><font color="#003060">
Add junk related to your fourth link here.  And so on and so forth.....



You can now easily make changes to your site's or presentation's text by simply accessing your text file and avoid the hassle of modifying the actual Flash source!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1