Skip to Content

Loading an external text file into Flash

Author: Bill Trikojus

 
1

Document setup

 
2

External text file

 
3

Load into flash

 
4

Summary

 
 
 
1

Document setup

 
 


OK here is a quick tute to show you how to load text from an external text file into Flash. This is useful if you have a client that wants to be able to easily update the text without having to get into the .fla.

This is what you will be making -


To download the source files for this tute click here.

OK load flash. The default settings for the new document will do for this tute.

Select the text tool and look at the Property Inspector. Make sure that "Dynamic Text" and "Multiline are selected. Choose an appropriate font, colour and size and then draw a text box on the stage that is the size of the area that you want the text to load into. Give the new text box a variable name of "myText".

Property Inspector

With dynamic text, your font is not embedded in the swf (unless you specifically choose to embed it via the "Character" button), so it is best to work with a common font such as Arial.

OK save your movie as "loadText.fla" into a folder named "load_external_text".

 
2

External text file

 
 


Now open a simple text edit program such as simpletext on the mac or notepad on the pc. Make a new document and paste in this text

myText=This is the text for the contact sections blah blah dsvfvrb tstsrtb srtbh stbsrthb tgntrn nrdn srtnsrtdnsdrtn r gdfb sdfdfb

You will recall that myText is the variable name that we gave to our text box.

Save the text file as contact.txt to the same folder as the fla.

 
3

Load into flash

 
 


OK now back to the fla. Make a button on your stage and give it an instance name of "but1". make a new "actions" layer and place this action on the first frame

but1.onRelease=function(){
loadVariablesNum ("contact.txt", 0);
}


This loads your text file into _root (level0). Be aware that if your text box is inside an mc you will need to load the text file accordingly

eg

but1.onRelease=function(){
loadVariablesNum ("contact.txt", "_root.mcInstanceName");
}


But for this tute our text box is on the main timeline so just leave the action as it was in the first example. Test your movie and click on the button.

That's pretty much it. Open the contact text file and change the text to

myText=This is the text for the about us section blah blah dsvfvrb tstsrtb srtbh stbsrthb tgntrn nrdn srtnsrtdnsdrtn r gdfb sdfdfb rn nrdn srtnsrn nrdn srtnsrn nrdn srtns

Choose "Save As" and save the file as "about.txt" to the same folder as the other files.

Now go back to flash and option-drag a copy of your button. Change the instance name of the new button to "but2" and add this action to frame 1 of your actions layer

but2.onRelease=function(){
loadVariablesNum ("about.txt", 0);
}


Save your movie and then test it again and click on both the buttons.

That's it! Go ahead and make as many different text files as you need need and buttons to load them in.

 

4

Summary

 
 


Advantages of loading in external text:

- easy to update
- text doesn't anti-alias (unless you embed the font)

Disadvantages:

- cannot animate or mask dynamic text (unless you embed the font)
- do not have complete control over the appearance of your text (unless you embed the font)

For a detailed discussion on fonts in Flash 5 (still relevant for MX) go here.

To download the source files for this tute click here.

 

bulletBack


Share

Like this? Click a link below to share it...


Subscribe and Download

Subscribe to the Swinburne Faculty of Design Podcasts

Comments

2010-04-09: vc said:
Testing and published everything works fine. However, when I upload the files online, my external .jpg's load fine, but none of the external text loads.

Perhaps you know a solution?

Thanks.

2010-04-09: vc said:
attempting to solve my problem I tried publishing and uploading this tutorial to my webpage, the text didn't show up.

2010-04-09: Bill Trikojus said:
I assume you upload the text file as well? And into the same directory as the swf? You can try adding a & to the start of the string in the text file but to be honest I would look for a tutorial on LoadVars (would be one on this site) as loadVariables is getting very old now.

All the best
Bill

2011-04-29: HADI said:
hi!
I builded or fixed a button inside the moviclip
I whant this Button for Exampel open the page5
in scene1 in the flash
please attach fla file I wait your answer HELP ME
thank.

2011-05-01: HADI said:
hi!
I want to Load an external word.doc file into Flash no text
please help me aboght word.documet file

2011-10-13: Mario said:
Thanks, just for the record, if you load the text in a movie clip, it must be like loadVariables instead of loadVariablesNum.

Do you know if I can load style the text with css?

2011-11-07: Manish said:
I want to know how to add comment in text file which will used with flash
Like we add in xml file using



Post a comment

Garbage posts and SPAM will be deleted.

* Name:
* Email: (will not be made public)
* Comment:
* Reply Notification: