all groups > flash actionscript > october 2004 >
You're in the

flash actionscript

group:

Converting the string into a number



Converting the string into a number bobrun
10/9/2004 10:35:43 PM
flash actionscript: In Falsh I retrieve variables from external *.txt file.
All variables received from an external source are treated as Strings.
I would like using a Number function convert external variable "headline_0"
which became a String back into a number.
Code below converts string variable assigned in Flash but doesn't convert
retrieved external variable, Please see 2 samples:

This code works and string gets coverted to a number:

loadVariablesNum("test_1.txt", 0);
i="3";
headline_0 = Number(i);
headline_1 = topic1;
headline_2 = topic2;
headline_3 = topic3;
headline_4 = topic4;
headline_5 = topic5;
gotoAndPlay(headline_0);

However when I try to convert actual external variable into a number
it covertes it to 0 (zero) however it should be 5 (five) according to *.txt
file:

loadVariablesNum("test_1.txt", 0);
headline_0 = Number(topic0); //this variable stores amount of records in
database
headline_1 = topic1;
headline_2 = topic2;
headline_3 = topic3;
headline_4 = topic4;
headline_5 = topic5;
gotoAndPlay(headline_0); //I'm trying to use retrieved value for navigation or
duplicating movie clip

Could you please advice how to fix it?
Re: Converting the string into a number kglad
10/10/2004 3:39:10 PM
this statement: headline_0 = Number(topic0);

is being executed before your variables have loaded. you should use a data
handler to ensure your data are loaded before you try and use those data. for
the code you've shown you could use

loadVariablesNum("test_1.txt", 0);
_level0.onData=function(){
for(ivar=0;ivar<=5;ivar++){
_level0["headline_"+i]=Number([_level0["topic"+i]);
}
}

but because this will fire when your _level0 instantiates, as well as when the
data are received it would be better to use a movieclip to receive the data:

_level0.createEmptyMovieClip("dataHolder",1);
dataHolder.loadVariables("test_1.txt");
dataHolder.onData=function(){
for(ivar=0;ivar<=5;ivar++){
_level0["headline_"+i]=Number([this["topic"+i]);
}
}
Re: Converting the string into a number bobrun
10/10/2004 10:25:18 PM
Kglad, Thank you for the tip. I placed suggested by you code on first frame of
main timeline.

_level0.createEmptyMovieClip("dataHolder",1);
dataHolder.loadVariables("test_1.txt");
dataHolder.onData=function(){
for(ivar=0;ivar<=5;ivar++){
_level0["headline_"+i]=Number([this["topic"+i]);
//_level0.gotoAndPlay(whatever);
}
}

But I'm getting output error message:

Scene=Scene 1, Layer=actions, Frame=1: Line 5: ']' or ',' expected
_level0["headline_"+i]=Number([this["topic"+i]);

Could you please advice on how to debug it?
Re: Converting the string into a number bobrun
10/11/2004 12:23:30 AM
Thank you, It was a great help!
Almost all variables are loading succesfully into movieClip "dataHolder".
Except "headline_0" variable. On trace I get no value in output window
"headline_0= "
Here is a code on the first frame:

_level0.createEmptyMovieClip("dataHolder1",1);
dataHolder.loadVariables("test_1.txt");
dataHolder.onData=function(){
for(ivar=0;ivar<=5;ivar++){
_level0["headline_"+i]=Number(this["topic"+i]);
}
}
trace("headline_0="+headline_0);

The "headline_0" variable is important because it holds amount of the records
information,
which is going to be different every day. I was thinking of looping last
headline back to the first.
You can see attached zipped headlines.fla file & test_1.txt file.
Re: Converting the string into a number kglad
10/11/2004 1:00:53 AM
that trace statement is outside your data handler and so, again it's going to
execute before the data are loaded. try:

_level0.createEmptyMovieClip("dataHolder1",1);
dataHolder.loadVariables("test_1.txt");
dataHolder.onData=function(){
for(ivar=0;ivar<=5;ivar++){
_level0["headline_"+i]=Number(this["topic"+i]);
trace("headline_0="+_level0.headline_0);
}
}
trace("headline_0="+headline_0);
Re: Converting the string into a number bobrun
10/11/2004 1:12:11 AM
Kglad,

I tried but still got same output message only repeated several times.

headline_0=
headline_0=
headline_0=
headline_0=
headline_0=
headline_0=
headline_0=
Re: Converting the string into a number Jeckyl
10/11/2004 9:02:23 AM
there was a typo in his reply ,

[quoted text, click to view]

AddThis Social Bookmark Button