*   Random Wallpaper
Ashlee Simpson 24

Ashlee Simpson 24

Please pick a resolution for download

800x600
1024x768
1280x960
1600x1200





*   Affiliates
Jokes and Forwards Space Technology Indian Stock Market PSP Accessories.us Vista Themes Heavenly Glimpses Tutorial Garden Pixel2Life

Cache Error: close() - Cannot write to cache file.

Cache Error: close() - Cannot write to cache file.

Loading Text into Flash Dynamically
Loading Text into Flash Dynamically
Views: 10117
Date Added: 28-07-2007
Category: Actionscript

< Previous   1 2



Step 3


Now is be a good time to create the text file from which we are actually going to load content. For this, create a new text file with the name ‘dynamic_text.txt’ and make sure that it is saved in the same place as your .fla file.(oh, in case you haven’t saved your flash file, please do so!). Now open your dynamic_text.txt file and copy and paste the following text.


&sitenews=9-2-2007: Hurray! We upgraded to our new servers. Everything is going to be super fast now!6-2-2007: We will be shut down for maintenance on 8th February, but hope to be back by the 9th.1-2-2007: New web design contest announced.



Okay, it does look like Greek at first, but ‘&sitenews’ is actually our variable and it contains the text that we need to load. (You could type in any text you want to load actually, but make sure you have the &sitenews variable defined in the beginning as shown here) The ‘’ tags work just like they do in html and create linebreaks. Make sure you save the file after pasting the above text.

Step 4


We are nearly there! We now need to tell Flash to load text from the file we just saved to the text box which we created. This is done by action script. To do this, create a new layer called ‘actions’ above your ‘dynamic text’ layer and in the first frame type in the following piece of action script:


var myLV:LoadVars = new LoadVars();
myLV.load("dynamic_text.txt");

myLV.onLoad = function(success) {
if (success){
sitenews_txt.htmlText=myLV.sitenews;
}
else{
sitenews_txt.text="Text failed to load due to an error. Please contact the webmaster.";
}
}


Here is what the code does:

In the first two lines of the code, we create an object of LoadVars class called ‘myLV’ to hold the contents of the variables present in the dynamic_text.txt file. This, in our case, will be the text that we entered after the “&sitenews=” in our txt file.

Next the onLoad event handler will pass a true or false value which it will store in the variable ‘success’. In the function, we check the value of the success variable. If it is true, then contents of the ‘sitenews’ variable in the text file will be loaded to the text field instance sitenews_txt. If the value of ‘success’ variable is false, we will load an error message onto the sitenews_txt instance.


All said, your layers and timeline should now look something like this:



Press Ctrl+Enter to publish your movie and if all went well you will have the text loaded!



Here are the completed files for this tutorial:
File Download: Loading Text Files


< Previous   1 2




Cache Error: close() - Cannot write to cache file.