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.
[AS]var loadText = new loadVars();
loadText.load(“textfile.txt”);
loadText.onLoad = function(success) {
if (success) {
myVar = this.textVar;
} else {
trace (“Error loading data”);
}
};[/AS]
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
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:
[AS]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”);
}
};[/AS]
[edit]and theres no point of using my_str = myVar; you should use my_str = this.name;[/edit]
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
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
I’m not sure, but I think load has to come after onLoad, and that my_str has to be put in _root.
[AS]
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)
[/AS]
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:
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 ?
May i ask what you want to do?
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?
Can you post your fla?
next message is the text field
here is the text…you can paste a big text file in it if you want to see the column thing working
Unexpected File Format.
hope this one is good