This tutorial will discuss how to load text dynamically through a text file with out the use of xml or css.
First, create a
Dynamic text field and give it an instance name.
Then give the text all of the properties for font family and <myspace>
size</myspace> that you want for it. Make sure the "Render text as HTML" button is selected in the text panel.
If you are planning on having some of your text bolded then be sure to select
bold for the font. Don't worry, all your text won't appear in bold.
For this example I have created two different text fields to demonstrate how to load multiple text fields.
test1_txt
text2_txt
Now open notepad or any text editing program and create a new document_
The way to create a variable that flash can read is
&variableName=
In my text file, I create two sets of data and named them text1 and text2.
Here is my text.
&text1=This <
font color="#FFFFFF">text<
/font> <
u>is<
/u> <
font <myspace>
size</myspace>="12">dynamically<
/font> loaded through an external text file&text2=So <
b>is this<
/b> text
All your text must be on one line. When entering text, never hit the Return button, to make a line break use <br>.
save the file as test.txt. Be sure to save it as a .txt file not a .doc or any other format.
In a new layer, hit F9 to enter your actions panel.
ActionScript
var
myText:LoadVars = new LoadVars ();
myText.load("test.txt");
myText.on
Load = function(success) {
if(success){
test1_txt.htmlText =
myText.text1;
test2_txt.htmlText =
myText.text2;
}
}
var myText:LoadVars = new LoadVars ();
myText.load("test.txt");
First we have to create a variable and give it a name. I named it
myText. Then strict type it to LoadVars
Then we create a new LoadVars object to store all the data in. And we are telling Flash to load the data from the test.txt file.
myText.onLoad = function(success) {
if(success){
}
}
Next we are telling Flash to when it loads, it needs to perform a function. If this loading function is successful then we want to do everything inside the brackets.
test1_txt.htmlText = myText.text1;
test2_txt.htmlText = myText.text2;
This says that the text property of
test1_txt and
text2_txt will be displayed as HTML and it will be equal to the loaded data from your myText variable.
dynamicText.zip
Thank you for reading this tutorial. I hope you find it very helpful with your flash animations. For any help with this tutorial or questions, please post only in this forum thread.
~Flash Mods