Skip to main content
Known Participant
April 23, 2007
Frage

Loading from a text file

  • April 23, 2007
  • 6 Antworten
  • 474 Ansichten
I have the follwoing code to load from a text file. My text files are in pairs.

The code i have in my first frame is as follows.

myData = new LoadVars();
myData.onLoad = function() {
lu.Recsign = this.myvariable;
};

if (loadlang = "UK") {
myData.load("UK.txt");
}

if (loadlang = "IT") {
mydata.load ("IT.txt") ;
}


english_btn.onPress = function() {
loadlang=("UK");
langIdx = 0;
updateDisplay();
gotoAndPlay(3);
};
italian_btn.onPress = function() {
loadlang=("IT");
langIdx = 1;
updateDisplay();
gotoAndPlay (3)
};


however whats happening is, it only ever picks up the UK file. I have tried commenting out the uk lines and just using the second part of the if statement, but the produces undefined. I know both text files are named correctly, i think its a problem with my if statement. Can anybody help?
Dieses Thema wurde für Antworten geschlossen.

6 Antworten

kglad
Community Expert
Community Expert
April 23, 2007
so what are the names of the two files and which statement is in which file?

what trace() result do you see when you press english_btn and what do you see when you press italian_btn.
kglad
Community Expert
Community Expert
April 23, 2007
show the first characters in each of your text files.
Known Participant
April 23, 2007
myvariable=hello

AND

myvariable=hello2

There is only one variable in each file at the moemnt. There is nothing else in there
kglad
Community Expert
Community Expert
April 23, 2007
remove (or comment) the updateDisplay() function and your gotoAndPlay() function. retest.
Known Participant
April 23, 2007
i wish it did but unfortunately it still doesn't work.

I added a trace in there as you can see below, and this comes back as undefined
english_btn.onPress = function() {
myData.load("UK.txt");
//updateDisplay();
//gotoAndPlay(3);
};
italian_btn.onPress = function() {
myData.load ("IT.txt")

//updateDisplay();
//gotoAndPlay(3);
};

myData = new LoadVars();
myData.onLoad = function() {
lu.Recsign = this.myvariable;
trace(lu.Recsign)
};
Known Participant
April 23, 2007
ok i changed it round to read the following, it does something very bizzare now. If i press one of the buttons it just says undefined. however if i then press the back button on the next frame then one of the buttons again, it always reads from the UK file.

english_btn.onPress = function() {
loadlang=("UK");
langIdx = 0;
updateDisplay();
gotoAndPlay(3);
};
italian_btn.onPress = function() {
loadlang=("IT");
langIdx = 1;
updateDisplay();
gotoAndPlay (3)
};

myData = new LoadVars();
myData.onLoad = function() {
lu.Recsign = this.myvariable;
};

if (loadlang == "UK") {
myData.load("UK.txt");
}

if (loadlang == "IT") {
mydata.load ("IT.txt") ;
}
kglad
Community Expert
Community Expert
April 23, 2007
mydata is not the same as myData. use:

Known Participant
April 23, 2007
Thanks for the code, however it still faces me with the same problem. I have deleted all other code on this frame to isolate it and this still occurs. Seems strange.
kglad
Community Expert
Community Expert
April 23, 2007
if loadlang is only defined after a button press you should not try and use loadlang before a button is pressed. ie, put your mydata.load() statements in your button handlers where it would be unnecessary to use an intermediate variable (loadlang), unless it's used elsewhere.
kglad
Community Expert
Community Expert
April 23, 2007
use the double equal (==) to test for equality. otherwise, you're making a value assignment.
Known Participant
April 23, 2007
i tried this

if (loadlang == "UK") {
myData.load("UK.txt");
}

if (loadlang == "IT") {
mydata.load ("IT.txt") ;
}

but neither work on this just get un-defined in the text box.