PDA

View Full Version : loading a .txt file


chris-sharpe99
08-06-2003, 11:12 AM
I've got a typwriter effect with three frames and a dynamic text box with the variable name textbox

//first frame
q = 1;
text = "text goes here"

//second frame
if (q < text.length) {
textbox = text.substring(0, q);
q++
} else {
textbox = text;
gotoAndStop(1);
}

//third frame
gotoAndPlay(2);


I want to load an external text file, say called "stuff.txt", into the variable "text" but I don't know how. I looked at the loadVaribles tutorial but I still don't have a clue. Any help greatly appreciated.
Chris

Sualdam
08-06-2003, 11:18 AM
Create a text file:

text=stuff here&eof=1

Save it as stuff.txt.

In frame 1 of your main movie put:loadVariablesNum("stuff.txt",0);
eof=0;In frame 3 put:if(eof==0){
gotoAndPlay(2);
}Put the rest of your movie and code in frame 4 or 5 onwards.

Make sure you take text="this is text" out foyour existing code otherwise it'll overwrite the value pulled in from the text file.

chris-sharpe99
08-06-2003, 11:44 AM
Thanks but that isn't working, even when I change it around, take the eof out and stuff like that. I think that when it loads the text it stops. but when I put a play(); command in it the eof gets declared as 1 straight away and it goes to the rest of the movie. If I take the eof out and put in the play(); command it just plays the text, finishes and starts again.

Ricod
08-06-2003, 12:26 PM
Does it play alright ? It starts over again because Flash loops. Put a stop(); at the last frame if you don't want this one to loop.

The eof 'stuff', is there to make sure all the variables are loaded, and if not, to wait a bit, so your typewriter effect doesn't start without the actual text being loaded.

Ofcourse, your typewriter code should start from frame 4 onwards now.

chris-sharpe99
08-06-2003, 01:31 PM
Got it working. I put if (
textbox.length >= amount-1) {
gotoAndStop(4);
}else {gotoAndPlay(2);}
in the third frame, and set "amount" in my text file as the amount of charachters in my string. Thanks anyway.
Chris

Ricod
08-06-2003, 01:42 PM
Well, whatever works for you. But for the record : It's exactly the same as what Sualdam suggested. You make a variable at the end of your textfile so Flash knows everything is loaded before continueing. oh well, it works. :)

chris-sharpe99
08-07-2003, 03:41 PM
yeah its similar, but not the same. "amount" is the amount of carachters I want to appear, and when the length of the text box is the same as amount, it continues.