Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string into number from .txt

Status
Not open for further replies.

Legolas7

Programmer
Mar 17, 2002
9
DE
Hello,

I've the following problem with getting values from a .txt file into flash.The problem isn't to get the Vars into the flash but to convert a string into a number. For example: the .txt file looks like this:

&t1=200&t2=400

now i want to add both numbers out of the file. I get the values into my textfields,but then Flash don't know how to add these "strings".
Flash code looks like this:

onClipEvent (enterFrame) {
loadVariablesNum("test.txt", 0);
sum = _root.t1 + _root.t2
}

Is it possible to add the numbers? Or is it only possible to do this with javascript
instead the txt file?

Thanks for any comment!
 
onClipEvent (enterFrame) {
loadVariablesNum("test.txt", 0);
sum = number(t1) + number(t2)
}
 
Sorry,

that isn't it. The problem is that the values are transmitted after the "stop()" and then nothing happens. So your code produces only s="0" in the Debugger and NaN in the output, so NotanNumber. Is there another way to load the values of the vars from a text-file?
 
spotted an error in the text file

&t1=200&t2=400&

you must have the second & symbol for numbers. not important for text just numbers.
 
for mx use loadvars

mydata = new loadvars();
mydata.onload = function(){
sum = number(mydata.var1) + number(mydata.var2);
trace(sum);
}
mydata.load("some.txt");

some text &var1=7&var2=5&

trace come back 12
 
Hm, that really works with FlashMX, but i want to use Flash5, because there are more people with Flash5 in the world then people with mx. I like mx and the debugmode, but steadiness is more then innovation for me. So what can i do? I know that the vars from the textfile are load, if i press the play button in the controlmenu again, or in html i had to rightglick the flashmovie and also hit the play field.
In My flashfilm the whole script and all actors are positioned in level0 and in the first picture of the timeline.
 
if you are using flash 5 then you might be better to have a button ,total say, which when clicked displays the result. this will give the variables time ti load. flash 5 does not wait around until variables are loaded but continues executing code. with mx the code is executed only after the variables are loaded. if you want the result displayed right away in the textbox then some preloader code will be needed.

if you check the stats you will see that almost as many people now have player 6 as have player 5. we have actually stopped publishing to 5 and tell clients that from the off.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top