how do you read in string variables from a txt file, and display this in a text box, so that the variables may be of use later.
Welcome, man.
Check the tutes. There’s one about scrolling imported text that shows how you can do that.
pom :cowboy:
thanks for the reply, but the thing is :-
lets say i have an output text box called “outFile”, it requires me to use “outFile=hello&”, within the text file itself, is there any way of getting around this where i dont need to use “outFile=”.
Well, yeah, read the tute, kid. You use a loadVars object, and you can do whatever you like in the onLoad.
pom :moustache
sorry i didnt make myself clear, i read the tutorials and used loadVariables(url,target)
but it seems that the actually content of the file is required to consist of an assignment of the target variable.
outFile= …&
what do you mean by using the onLoad as it only returns a boolean value.
so you want to be able to load an external txt file without it containing thisTEXT=“content”??? If so… Um, may I ask why?
Peace
so i can use the variables for comparison
*Originally posted by zkac050 *
**sorry i didnt make myself clear, i read the tutorials and used loadVariables(url,target)
// not loadVariables, loadVars
what do you mean by using the onLoad as it only returns a boolean value.
// err… WHA’?**
The tute: http://www.kirupa.com/developer/mx/dynamic_scroller.asp
The idea:
loadText = new loadVars();
loadText.load("kirupa.txt");
//creating the loadVarsText object and load function
loadText.onLoad = function() {
// the variable container in the text is called Kirupatext
// but you retrieve it as scroller.text.
scroller.text = this.kirupatext;
};
Is that what you are trying to do?
yeah thanks K, i found and used :-
function fileRead() {
loadVarsText = new loadVars();
loadVarsText.load("textfile.txt");
loadVarsText.onLoad = function() {
outFile=loadVarsText;
};
}
but i get:-
there%20%20was%20a%20young%20man%20from%20downducket%20with%20a%20bob&onLoad=%5Btype%20Function%5D
from the text: "there was a young man from downducket with bob. "
What is all that other stuff in between, and the text added onto the end, something to do with onload.
Strange. Use unescape:
a="there%20%20was%20a%20young%20man%20from%20downducket%20with%20a%20bob&onLoad=%5Btype%20Function%5D"
trace (unescape(a));
pom :pirate:
It seems to insert information about the onload[type function] to the end of the string, which i dont want. how do i stop this happening.
Try this:
myFile = new LoadVars();
myFile.onData = function(rawDataFromMyFile){
myText = unescape(rawDataFromMyFile);
}
myFile.load(“myTextFile.txt”);
That’ll override the normal onData handler (which overrides the procedures that look for variable/data pairs in your file) and simply drop the raw text data (minus escape characters) into the variable: myText.
You may want to put the following line after all that to un-override the onData method for the myFile object if you want to load other files in the usual way (with variable/data pairs).
delete myFile.onData;
Cheers.
-Al
thanks i tried this:-
myFile = new LoadVars();
myFile.onData = function(rawDataFromMyFile){
myText = unescape(rawDataFromMyFile);
}
outFile=myFile.load(“textfile.txt”);
but all it returns is true:-NOTE "outFile"is my output box.
all it prints out is " True"
You need to put:
myFile = new LoadVars();
myFile.onData = function(rawDataFromMyFile){
outFile = unescape(rawDataFromMyFile);
}
myFile.load(“textfile.txt”);
-Al
Thank the almighty god, alert the church elders, we have a genius in the house, thank A, you are a life saver.
:beam:
Why not use xml?
myXML = new XML();
myXML.onLoad = function (success) {
if (success){
trace ("loaded successfully");
myTextBox.text = unescape(myXML);
}else{
trace("Error Loading Specified File");
}
}
myXML.load ("Textfile.txt");
onData does work, but using the way above, you get the error checking feature integrated with hassle-free loading.
cheers;
myLoadVars = new LoadVars();
myLoadVars.onLoad = function (success) {
if (success){
trace ("loaded successfully");
myTextBox.text = this.myvar;
}else{
trace("Error Loading Specified File");
}
}
myLoadVars.load ("Textfile.txt");
:-\
Hi senocular, just try the code above and you’ll see what i meant.
cheers;
you lost me