410 Working with Text and Strings
5. Select the Export for ActionScript and Export in First Frame options, enter the linkage
identifier Arial-10, and click OK.
6. Add the following ActionScript to Frame 1 of the main Timeline:
var text_fmt:TextFormat = new TextFormat();
text_fmt.font = "Arial-10";
text_fmt.size = 10;
this.createTextField("my_txt", 10, 20, 20, 320, 240);
my_txt.autoSize = "left";
my_txt.embedFonts = true;
my_txt.selectable = false;
my_txt.setNewTextFormat(text_fmt);
my_txt.multiline = true;
my_txt.wordWrap = true;
var lorem_lv:LoadVars = new LoadVars();
lorem_lv.onData = function(src:String) {
if (src != undefined) {
my_txt.text = src;
} else {
my_txt.text = "unable to load text file.";
}
};
lorem_lv.load("http://www.helpexamples.com/flash/lorem.txt");
normal_mc.onRelease = function() {
my_txt.antiAliasType = "normal";
};
advanced_mc.onRelease = function() {
my_txt.antiAliasType = "advanced";
};
The preceding code is separated into four key areas. The first block of code creates a new
TextFormat object, which specifies a font and font size to be used for a text field that will
be created shortly. The specified font, Arial-10, is the linkage identifier for the font
symbol that you embedded in a previous step.
The second block of code creates a new text field with the instance name
my_txt. In order
for the font to be properly embedded, you must set
embedFonts to true for the text field
instance. The code also sets the text formatting for the new text field to the TextFormat
object that you created earlier.
The third block of code defines a LoadVars instance that populates the text field on the
Stage with the contents of an external text file. After the document is fully loaded (but not
parsed), the entire contents of the file are copied into the
my_txt.text property, so that
they are displayed on the Stage.