H  1  2  3  4.1  4.2  4.3  5  6  7  8  9 

Hands-On: Flash MX 2004 the Basics

Exercise 6: Linking a Text File into a Dynamic Text Field

This exercise will show you how to link a .TXT file to a Flash movie. You could consider this text file to be from a database or an external file, however, for the exercise we will only use a pre-written external file saved as .txt. The nice thing about linking a text file is that you can update the file outside of the Flash movie and the Flash movie will update automatically. This text file can include HTML coding and in another exercise I’ll show you how to add Cascading Style Sheets coding too.

The text file you will be linking to is the Martin Luther King, “I’ve got a Dream” speech. In part two and three exercises you’ll be adding Scroll Buttons and Sound On/Off Buttons for a .WAV file of the speech.

This is a preview of what the HTML looks like at the top of the text file:

content=<b><i><font size="20pt"> "I Have A Dream"</font></i></b>

by <b>Martin Luther King, Jr.</b>

<font color="#000080"><i> Delivered on the steps at the Lincoln Memorial in Washington D.C. on August 28, 1963.

Source: Martin Luther King, Jr: The Peaceful Warrior, Pocket Books, NY 1968</i></font>

The most important part of this .txt file is the word and the equal sign content= this declares that the text within the text file will be assigned to the variable (var) name content. The <b><i><font size="20pt"> is basic HTML that makes the text bold and italic and a rather large font size.

The dreamSpeech.fla flash file has a couple of graphics in the Library that will save time for you.

Follow these steps:

  1. Download the dreamSpeech.fla file listed below and save it in your working folder.
  2. Download the dream.txt file listed below and save it in the same folder that you saved the exercise.
    The Timeline with the holder layer.
  3. In the Timeline, add a new layer by clicking the Insert Layer button, and rename this layer holder. Make sure that the holder layer is above the background layer.
    The Properties Inspector for Multiline textareas.
  4. Select the Text tool from the Toolbar and click the Stage to activate the Properties Inspector, choose Dynamic Text, Multiline, and the two icons Show Border Around Text and Render Text as HTML. Make sure the Fontcolor is set to black and the Font Type is set to Verdana with a Point Size of 10. Name the instance field, (the field below Dynamic Text) to myText
  5. With the holder layer selected and the Text tool still selected, click and drag on the Stage to create a Dynamic Text field that uses these dimensions: W= 430, H=217, X=250, Y=25
  6. In the Properties Inspector, type the word content in the Var: (variable) field. This will be the variable name that is assigned to the text field. (The first word of the dream.txt file shown above.)
    The Timeline with the Actions layer added.
  7. Selecting scrollable text. With the Arrow selection tool, click inside of the text area box you have on the Stage, right-button click and choose Scrollable.
  8. In the first frame of the Actions layer select the Actions panel [F9] and choose: Global Functions > Browser/Network > loadVariables
    Finding the action from the Actions panel.
  9. In-between the parentheses ( ) of the code type the following: "dream.txt", this. Please do not forget to put the double quotations as shown or it will not work.
    The Actions panel coding.
  10. Test [Control] + [Enter] your work and see the file linked to the Flash movie, however, at this point you have no way of scrolling through the text on the page. That will come in the next exercise.

 

You can download these two files to create this Hands-On Exercise:

http://profal2.com/cis127/pdf/assets/flash/dreamSpeach.fla

http://profal2.com/cis127/pdf/assets/flash/dream.txt


Back to Top