all i want to do is have a dynamic text box that loads text from .txt file. I can't find a simple tutorial on this. I know i make a text box, give it an istance name say "holder" but i dont know what else. help please
Printable View
all i want to do is have a dynamic text box that loads text from .txt file. I can't find a simple tutorial on this. I know i make a text box, give it an istance name say "holder" but i dont know what else. help please
Ok, TeddTucker. This is something I had quite a bit of trouble with when I was starting out with Flash. Shamefully, I had to go back and look it up again today, but it's nothing too troublesome. I'll walk you through it.
First of all, create a new layer, name it 'textbox' and place a dynamic text box on it with the desired demensions. Now, give it an instance name - I'm going to use 'txt_box'.
Now click on the first frame of the layer you just created and press f9 to open the ActionScript pannel. In it, copy and paste the following code:
In line 1 we are creating a new LoadVars object named 'get_text'. Line 2 is just instructing Flash to fetch the contents of a .txt file we are yet to create. Line 3 creates a condition for when the contents of the .txt file have been loaded. Line 4 just assigns the text contained in the .txt file to your text box, txt_box.Code:get_text = new LoadVars(); //1
get_text.load('text.txt'); //2
get_text.onLoad = function(success) //3
{
txt_box.text = get_text.txt; //4
}
Now, compile your .swf and like magic . . . nothing happens. That's ok. Navigate to the folder where you compiled the swf to, and either create a new text file by right clicking> new > Text Document, or paste one you already have.
Open up the text file and type this (adjusting as necessary):
Notice that 'txt' variable is referred to in line 4 of your actionscript code. You can send flash more textfield values from this same text field, separating each with a '&'. For example:Code:&txt = "your text";
To refer to this new variable, you must add '.txt2' to the end of your get_text object. For example, if you had another text field name 'txt_box2' then your code would read:Code:&txt = "some text"&txt2 = "some more text";
I hope that explains it for you.Code:get_text.onLoad = function(success)
{
txt_box.text = get_text.txt;
txt_box2.text = get_text2.txt;
}
greenham, thank you for your detailed help but i can't get it to work. i did everything u said but the text field is coming up "undefined" when i preview it. any idea why this is happening?
Hi Greenham
I have a somewhat related problem: I have some titles on the left-hand side of a page. I want users to be able to click a title, which would then open a text box or window component, providing formatted text info about the title in the box.
That would mean clicking the title should load the txt1/2/3/4 etc variable, so that the correct variable text is called from the text file.
How do I do that?