Skip to main content
Inspiring
September 2, 2010
Answered

Load External Text

  • September 2, 2010
  • 1 reply
  • 529 views

Hi All..

I have a bit of a problem here. I'be been studying AS3, but I have a small task to do in AS2 and I'm kind of lost. I just need to load external tex, this is thre code that i have:

loadText = new LoadVars();

loadText.load("external.txt");
loadText.onLoad = function(success) {
    if(success == true) {
        text_txt.text = loadText.VARIABLE;
    }
};

I'm not sure what I"m suppoused to put in place of the variable?

Thanks a bunch ahead of time!

This topic has been closed for replies.
Correct answer kglad

what ever you used in the text file.  for example, if you used:

myvar = this is in external.txt

you could use:

loadText = new LoadVars();

loadText.load("external.txt");
loadText.onLoad = function(success) {
    if(success == true) {
        text_txt.text = this.myvar;
    }
};

or if you just have text in your textfile without assignment to a variable, use:

loadText = new LoadVars();

loadText.load("external.txt");
loadText.onData = function(src) {
 
        text_txt.text = src;

};

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 2, 2010

what ever you used in the text file.  for example, if you used:

myvar = this is in external.txt

you could use:

loadText = new LoadVars();

loadText.load("external.txt");
loadText.onLoad = function(success) {
    if(success == true) {
        text_txt.text = this.myvar;
    }
};

or if you just have text in your textfile without assignment to a variable, use:

loadText = new LoadVars();

loadText.load("external.txt");
loadText.onData = function(src) {
 
        text_txt.text = src;

};

Inspiring
September 2, 2010

Thanks a bunch Kglad! It worked!

( I had no problem doing it in AS3 - but got totally stuck with AS2!)

kglad
Community Expert
Community Expert
September 2, 2010

you're welcome.