Loading text from an external text at runtime

Another way to include non-Roman text in your Flash file is by loading it from an external text file.

  1. Create your text file containing the non-Roman text that you want to work with. This file can contain Unicode-formatted text, and does not seem to need any coding indicating that it's in Unicode. Structure the file ike this, defining variables and assigning values to it. No quotes are necessary. Note the ampersand character separates text items.

    varname1 = 我的文字&varname2=中華民國萬歲

  2. Save the text file as "externalText.txt"
  3. Make a movie clip. It does not have to contain anything.
  4. Place the movieclip on stage. Name it "mc1"
  5. Script the movieclip:

    onClipEvent(data) {
             //text manipulation routines here. For example, to place the value of varname1 into a text field called "myText"
             _root.myText.text = varname1
             //You can split the text into an array, then put the 3rd word of the sentence into the text field
             myArray = varname1.split("");
             _root.myText.text = myArray[2];
             //Whatever
    }

  6. Script the frame to call the external file. Put this script in the frame script, or inside the script of a button.

    loadVariables("externalText.txt", "_root.mc1");

  7. The text file must travel with your Shockwave movie, staying in the relative position to the movie file, and not changing name.

Note: In case you're wondering why I don't use the LoadVars object, I have found that it does not "reset." After running successfully once, the function will not re-check the file a second time. In other words, if you load the text file once, then change the text file, and try to re-load it, the function will think it has already successfully loaded the text file, and will not bother to do it again. The LoadVariables command is stateless, and so I chose to use it instead.

 


This tip was written by Dennie Hoopingarner of the Center for Language Education And Research (CLEAR) at Michigan State University. Copyright © 2003 by Michigan State University Board of Trustees. All rights reserved.