Loadiing External Text in Flash
Loading external text into flash has so many advantages. Consider this, trying to update a site every time something new happens. It would kind of get monotonous to have to edit the .fla every time this occurs. Using a text file is both easier to edit and alot faster. Doing so isnt as difficult as it seems either! It's actually QUITE easy and you can memorize the steps very quickly!
Start off by creating a dynamic text field in flash. In the field below the type of field the text box is, type "scroller". this changes the instance name and we can use this to communicate with later. Be sure also that your text field is set to "Multiline". If you have a large amount of data, it will not show up in the field.
You can use a different font, but for now, use times new roman. This insures you can read what you have typed. After you have completed that, open frame one actions. Place this script inside:
As you may have noticed, the text we will be loading will be called "test.txt" Later you can change this to your preferred text name.
The "trace" shows a message in the output window in flash mx, this will not be seen when viewed in a player or browser. This just insures that the loading of the text was successful when debugging.
Now that we have established the scripting, we need to create our text document, It also HAS to be a txt file. Include this paragraph, along with any edits you might want, edit everything except the var1=. That is needed when loading the data into flash.
As you may have noticed, the text we will be loading will be called "test.txt" Later you can change this to your preferred text name.
The "trace" shows a message in the output window in flash mx, this will not be seen when viewed in a player or browser. This just insures that the loading of the text was successful when debugging.
As I mentioned earlier, make sure the text document is named "text.txt". Make sure you export the swf where the text file is, this makes it so much simpler.
You're done! Now make sure your text document is where your swf is or it wont load.
Start off by creating a dynamic text field in flash. In the field below the type of field the text box is, type "scroller". this changes the instance name and we can use this to communicate with later. Be sure also that your text field is set to "Multiline". If you have a large amount of data, it will not show up in the field.
You can use a different font, but for now, use times new roman. This insures you can read what you have typed. After you have completed that, open frame one actions. Place this script inside:
Code:
loadVarsText = new loadVars();
loadVarsText.load("test.txt");
loadVarsText.onLoad = function(success) {
if (success) {
trace("Doc Loaded");
scroller.text = this.var1;
} else {
trace("not loaded");
}
}; As you may have noticed, the text we will be loading will be called "test.txt" Later you can change this to your preferred text name.
The "trace" shows a message in the output window in flash mx, this will not be seen when viewed in a player or browser. This just insures that the loading of the text was successful when debugging.
Now that we have established the scripting, we need to create our text document, It also HAS to be a txt file. Include this paragraph, along with any edits you might want, edit everything except the var1=. That is needed when loading the data into flash.
As you may have noticed, the text we will be loading will be called "test.txt" Later you can change this to your preferred text name.
The "trace" shows a message in the output window in flash mx, this will not be seen when viewed in a player or browser. This just insures that the loading of the text was successful when debugging.
Quote:
| var1=Hey guys this is a test.Hey guys this is a test.Hey guys this is a test.Hey guys this is a test.Hey guys this is a test.Hey guys this is a test.Hey guys this is a test. |
As I mentioned earlier, make sure the text document is named "text.txt". Make sure you export the swf where the text file is, this makes it so much simpler.
You're done! Now make sure your text document is where your swf is or it wont load.
Last edited by Solaris : 01-21-2007 at 09:20 AM.



Linear Mode


