PDA

View Full Version : loading variables in a loop



Hartwig
April 26th, 2002, 05:35 AM
Hi!

I've a .txt-file containing variables. The variables are structured like this:

aaa_301, bbb_301, ccc_301
aaa_302, bbb_302, ccc_302
...
aaa_325, bbb_325, ccc_325

To use them in Flash I have to read them from the .txt-file and assign them. This could look like this:

onClipEvent (data) {
&nbsp &nbsp &nbsp &nbsp _root.aaa_301 = aaa_301;
&nbsp &nbsp &nbsp &nbsp _root.bbb_301 = bbb_301;
&nbsp &nbsp &nbsp &nbsp _root.ccc_301 = ccc_301;
&nbsp &nbsp &nbsp &nbsp _root.aaa_302 = aaa_302;
&nbsp &nbsp &nbsp &nbsp _root.bbb_302 = bbb_302;
&nbsp &nbsp &nbsp &nbsp _root.ccc_302 = ccc_302;
&nbsp &nbsp &nbsp &nbsp ...
&nbsp &nbsp &nbsp &nbsp _root.aaa_325 = aaa_325;
&nbsp &nbsp &nbsp &nbsp _root.bbb_325 = bbb_325;
&nbsp &nbsp &nbsp &nbsp _root.ccc_325 = ccc_325;
}

Is it possible to use a loop instead of write 301, 302, ...325?

I thought of:

onClipEvent (data) {
for (i=301; i=325; i++){
&nbsp &nbsp &nbsp &nbsp _root.aaa_i = aaa_i;
&nbsp &nbsp &nbsp &nbsp _root.bbb_i = bbb_i;
&nbsp &nbsp &nbsp &nbsp _root.ccc_i = ccc_i;
}
}

Any idea how the code could look like?

Many thanks,

Hartwig

upuaut8
April 26th, 2002, 06:13 AM
Are you sure that you're txt is writen correctly?

It should look something like

&aaa_301=something&bbb_301=something&ccc_301=something&aaa_302=something&bbb_302=something&ccc_302=something&

Hartwig
April 26th, 2002, 07:51 AM
Hi!

Yes of course. The .txt-file is written correctly. I just wanted to demonstrate the structure of the variables. But how could the for-loop look like?

Hartwig

I am not Jubba
April 26th, 2002, 08:04 AM
i think that code looks right...maybe create 3 for loops one for aaa, one for bbb, and one for ccc?

ilyaslamasse
April 26th, 2002, 08:23 AM
No no no no.
onClipEvent (data) {

for (i=301; i=325; i++){

root["aaa_"+i] = this["aaa_"+i] ; // no _ in front of root.

root["bbb_"+i] = this["bbb_"+i] ;

}

}But I don't see why you need to put them in the root.

pom 0]

Hartwig
April 26th, 2002, 08:27 AM
writing this

onClipEvent (data) {
&nbsp &nbsp &nbsp &nbsp for (i=301; i<326; i++) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp set ("_root.name_"+i, "aaa_"+i);

the result ist that the variables get the value aaa_301, aaa_302, ... and not the value that is assigned in the txt-file.

Are the " " on a wrong position?

Hartwig

Hartwig
April 26th, 2002, 08:36 AM
Hi!

making the _ infront of root, everything works fine

THX a lot

Hartwig

ilyaslamasse
April 26th, 2002, 09:53 AM
Just in case (I'm not saying this to you, Hart), it's usually not a good idea to put an equality as a condition of a for loop (here it's i=325). i<=325 or i<326.

pom 0]

ilyaslamasse
April 26th, 2002, 10:00 AM
What did I write ?? Of course there's a _ in front of root. !!

pom 0]

Hartwig
April 26th, 2002, 11:38 AM
Yes, you're right Pom. (i=301; i<326; i++) is better, because = causes the system to get very slow