PDA

View Full Version : Loading External Text that's not a variable



Haig Larsen
December 23rd, 2004, 03:37 PM
Hi All. This is my first post. I'm working on a project that involves pulling a number from a text file on a remote server. I am familiar with the intricacies of loadVars and loadVariables, but in this particular case, the text file only contains a number. It is not preceeded by a variable name or anything like that. It is just: 40. Is there a way to pull this into flash without a variable name so I can display it in a dynamic text field?

Thanks,
Haig

GreenLantern
December 23rd, 2004, 04:09 PM
Are you sure you can't use a variable in the text file? I am thinking something like this would work if you are willing to have a "variable=" in your text file.

Actionscript:

loadText = new loadVars();
loadText.load("number.txt");
//creating the loadVarsText function
loadText.onLoad = function() {
dynamicTextBox.text = this.numberInTextFile;
};

Your text file:

numberinTextFile=69

icio
December 23rd, 2004, 04:15 PM
there is a way to do this - you can use the XML class to do it.
for your case, you can use something like this:

myFile = new XML();
myFile.onLoad = function() {
var myNumber:Number = Number(myFile.toString());
trace(myNumber);
}
myFile.load("number.txt");
hope this helps :thumb:

GreenLantern
December 23rd, 2004, 04:18 PM
did you even read his post? OMG !!
No I didn't. I just threw out some random code hoping to solve his problem.

GGF :evil:

icio
December 23rd, 2004, 04:20 PM
No I didn't. I just threw out some random code hoping to solve his problem.

GGF :evil:
the reason i said that was because i didn't read yours properly !! :lol:

"said what?" ;)
lol, i'm such an eejit

Haig Larsen
December 23rd, 2004, 05:25 PM
there is a way to do this - you can use the XML class to do it.
for your case, you can use something like this:

myFile = new XML();
myFile.onLoad = function() {
var myNumber:Number = Number(myFile.toString());
trace(myNumber);
}
myFile.load("number.txt");
hope this helps :thumb:

Wow, this looks like it should work. I thought maybe there was a way to do this with XML, but wasn't sure exactly how. Unfortunately, the text file is provided by a third party and I have no control over its content, so this is a good option. Thanks very much for your help!

Haig

Haig Larsen
December 27th, 2004, 11:27 AM
Okay, this worked perfectly until the client kindly informed me after the fact that it needs to be in Flash 5 format. So, no text boxes with instance names. Now, I'm having a hard time getting the myNumber variable to show up. I have a dynamic text box on stage with a variable name of winningNumber, but nothing shows up when I test the movie. Does anyone know how to accomplish this? Man, it's simple little things like this that make the endless hours and frustration of learning Actionscript make me feel like it was all in vain!!

Here's the code I'm using:

myFile = new XML();
myFile.onLoad = function() {
var myNumber:Number = Number(myFile.toString());
_root.winningNumber = "$"+myNumber;
}
myFile.load("http://www.b (http://www.ba)lahblahbah.com/");



Thanks,
Haig