PDA

View Full Version : FMX -Loading external text into variable



borispc
August 6th, 2003, 02:50 PM
Hi!
What is the best method to load external text into a variable, not directly into a text field but a variable that is going to be used later. thanx.

claudio
August 6th, 2003, 02:55 PM
var loadText = new loadVars();
loadText.load("textfile.txt");
loadText.onLoad = function(success) {
if (success) {
myVar = this.textVar;
} else {
trace ("Error loading data");
}
};

borispc
August 6th, 2003, 02:56 PM
let me try it again...but that is exactly the method I was using and it didn't work...I guess I did something wrong...:S let me check
thanx claudio

borispc
August 6th, 2003, 03:08 PM
ok so here is what I have:
My external text file is called data.txt and has a variable named "name":

var loadText = new loadVars();
loadText.load("data.txt");
loadText.onLoad = function(success) {
if (success) {
myVar = this.name;
trace(myVar);//this one traces the name variable in the text field fine
} else {
trace("Error loading data");
}
}
trace(myVar);//this one returns undefined
//Then I wanted to assign that value to my_str:

my_str = myVar;

so I get the name and undefined in the output window.... :d:

claudio
August 6th, 2003, 03:12 PM
var loadText = new loadVars();
loadText.load("data.txt");
loadText.onLoad = function(success) {
if (success) {
myVar = this.name;
my_str = myVar;//you have to do this after the txt file is loaded
trace(mystr);
} else {
trace("Error loading data");
}
};

and theres no point of using my_str = myVar; you should use my_str = this.name;

borispc
August 6th, 2003, 03:15 PM
I had tried that but same thing happens:

var loadText = new loadVars();
loadText.load("data.txt");
loadText.onLoad = function(success) {
if (success) {
myVar = this.name;
my_str = myVar;
trace(my_str);//this one's fine
} else {
trace("Error loading data");
}
}
trace(my_str);//this one is undefined...I need to used it right here outside the function...it's undefined..making the variable global didn't work either

borispc
August 6th, 2003, 03:18 PM
It makes more sense like this but still doesn't work:
var loadText = new loadVars();
loadText.load("data.txt");
loadText.onLoad = function(success) {
if (success) {
my_str = this.name;
trace(my_str);//right value
} else {
trace("Error loading data");
}
}
trace(my_str);//undefined

Voetsjoeba
August 6th, 2003, 03:20 PM
I'm not sure, but I think load has to come after onLoad, and that my_str has to be put in _root.


var loadText = new loadVars();
loadText.onLoad = function(success) {
if (success) {
myVar = this.name;
_root.my_str = myVar;
trace(_root.my_str);//this one's fine
} else {
trace("Error loading data");
}
}
loadText.load("data.txt");
trace(_root.my_str)

borispc
August 6th, 2003, 03:24 PM
that doesn't make sense to me...
if you don't load it at the beginning how is flash supposed to pick up the variables of the text file unless it's loaded?
:p:

Voetsjoeba
August 6th, 2003, 03:26 PM
I think, but I'm not sure, that onLoad defines what Flash must do when it is loaded, and that load actually loads it. So first tell what to do, then load, instead of load and then tell what to do.

Have you tried putting it in root ?

claudio
August 6th, 2003, 03:28 PM
May i ask what you want to do?

borispc
August 6th, 2003, 03:50 PM
ok...what I want to do is the following:
I want to load an external text file and format that in flash in consecutive columns. The column part is already solved, all I need is to have the text in a variable called my_str. So all I need is to load that text into my_str.
Another thing...how do I format that text (external text) if I'm creating the text fields on the fly with the method: createTextField (instanceName, depth, x, y, width, height)??? I want to be able to control line breaks specially (<br>), so how do I assign the htmlText property to that field created with AS?

claudio
August 6th, 2003, 04:03 PM
Can you post your fla?

borispc
August 6th, 2003, 04:17 PM
next message is the text field

borispc
August 6th, 2003, 04:18 PM
here is the text..you can paste a big text file in it if you want to see the column thing working

Voetsjoeba
August 6th, 2003, 04:20 PM
Unexpected File Format.

borispc
August 6th, 2003, 04:21 PM
hope this one is good