Newsletter: Learn More ||| Multimedia Presentation Software |||
Load Text into Flash MX
Introduction
Here is a quick tutorial 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:
You may download the source files for this tutorial from here.
Contents
Instructions

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".

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.

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

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.

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.

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)

This tutorial was written by Bill Trikojus of Tableau Design.
 
©2007 Wildform, Inc | Policies | Contact Us | Newsletter Options
 
©2008 Wildform, Inc | Policies | Contact Us | Newsletter Options
 
Wildform provides a 100% satisfaction guarantee on all our Flash software. If you are not completely satisfied with our Flash multimedia software for any reason you may request a refund within 15 days of purchase.