Title : Loading text into Flash
Level : Beginner
Author : Darren Richardson
Website :www.DarrenRichardson.com
Download the files here to help you through the tutorial

Loading txt form a text file.

This is the first in a number of tutorials all explaining how to gather server side data and display it within Flash.

This has a lot of benefits, the main one being able to dynamically display your data.

This first tutorial will look at simply retrieving some data from a text file placed in the same location as our swf file and then displaying it in a text box in our flash application.

Step 1: creating our text file.

We will use normal text in the first tutorial and explore HTML embedding tag later.

Open notepad or similar and type the following

Mydata=This is where we place all of our text that our flash movie will display, this is currently un-formatted but later we will use html to format the text&

Save this file as data.txt in the same folder as your movie that we will create now.

Step 2: Creating our Flash movie.

Make the movie size 300 px Width and 300 px Height then create four layers and name them info, AS, textbox and frame, see below.

In the info layer add your text, for example ‘NEWS Blog’

Next add the actionscript, this is one line of code:

loadVariablesNum ("data.txt", 0);

The first part (loadVariablesNum) is the command to get the file, it have two parameters, the first is the file you want to call, which in our case is ‘data.txt’ the second is the level we want our text to be loaded into, I have chosen the top level as we are not loading any more objects/data in after this.

The Frame layer is just a box that the text sits in to show it off a bit you will see this in the final screen shot and the file you can download.

Now we create our text box.

Draw a text object on the main stage and the set the following properties in the text options tab.

Select Dynamic Text then Multiline and click word wrap, lastly put Mydata into the variable box. If you want to embed your fonts also click the [..] button.

Save you movie and run, you should see this.

How it works:

The movie has open the text file and read in the variable mydata, now we have told our text box to assign it’s self to any variable called mydata. …. Simple J

To change the formatting to include hyper links and bold text etc just change your text file. Here is an example to get you started.

Mydata=This is where we place all of our text that our flash movie will display,<br> this is currently formatted <BR> here is are <u><a href='http://www.actionscripts.co.uk' target='_blank'>hyperlink</a></u> pretty cool hey&

Also change your text options and click the HTML option.

Example here:

Download the files here to help you through the tutorial

Contact: Daren@actionscripts.co.uk