NEW! FLASH Tutorials in Video Format - Powered by LearnFlash.com: 45 minutes of flash tutorials now available in streaming format or download. Topics Include flash for beginners, text effects, actionscripting, audio/video, Flash CS3 and more.

Loading External Text into a Flash Movie

By Blue_Chi | Flash MX

This tutorial would teach you how to read external text files into your flash movie, the benefit of this feature makes it possible for you to update the content of your flash website without editing the flash file itself, but just editing text files that has the text of the website.

You can download the example FLA with the text file from here.

 

Creating the movie and text

In an empty folder, create a Flash Movie and name it Load Text. Create a text file and name it mytext, both files have to be in the same folder.

 

Preparing the Text File.

1- Open the text file, and put this:

content=I want to see this text.

2- Now save the file.

The first part of the line was the name of the variable, it is just a name that I chose to label the text, the second part was the actual text that I wanted the movie to read, so if you want to change what you will see at the end result, you should change everything after the equal mark.

 

Preparing the Flash Movie

1- Create a new empty flash movie and create a text field on the stage using the text tool.

2- For a text box to be interactive with Actionscript, it has to be formatted as Dynamic Text, you set that from the text properties panel, just click on Static and change it to Dynamic text.

3- The text file actually has variables that are read by the flash movie, for this to happen, the text field has to allocated to a certain variable that it would be showing, we have to give the name of the variable contained in the text file, in this case, we already chose contents, so put this in the variable field. (Number 3 on the diagram)

4- Now for the movie to be able to display the text properly, you have to tell it to store character shapes of a certain font, just click on the Character button in the property panel, and select All Characters. (Number 4 on the diagram)

Writing the Actions

1- Click on the only frame you have in the movie.

2- Now if using Flash MX, press F2 to show the Actions Panel, or simply right-click the frame and select Actions.

3- Now click on the + sign, go to Actions > Browser Network >loadVariables

4- If you are using the basic mode you will see a URL field which you will have to put in it the name of your text file mytext.txt , otherwise you would have ot type the name as you see in the following code, (or just copy and paste the whole line instead of going through the Actions sub-menus.

loadVariablesNum("mytext.txt", 0);

Everything should be ready to work now press Ctrl and Enter to test your movie and see the text that you had in your text file. The loadVariablesNum action loads external text files into the movie clip, you have to only put the name of the text file and its level. The level should be put as "0" (Zero) to send the variables to the _root flash movie.

Extra

- You can load multiple variables in the same text file by typing "&" then putting the name of the second variable followed by an equal mark and its content.

- You can load HTML that could be read by the page to generate links and other effects like Bold and Italics. You set that from the property panel as well.

- Other settings could be changed as well, such as multi-line texts and text wrapping.

This technique for loading external text in Flash is no longer recommended, you should use the Loadvars() Class for loading external textual content if using Flash MX or later.

End of tutorial, please check the forum if you need any more help.