split command

  • wiggles
  • Novice
  • Novice
  • wiggles
  • Posts: 15

Post 3+ Months Ago

i need to create a dynamic scoreboard that updates using a .txt file as its input. the .txt looks like this...

Code: [ Select ]
Event_Info=number of events|sport|team1|team2|True|location|date|time|score|score|


i need to use the split command to break each piece apart and put every different section in a different text box.

i just need to know how to split them all and label each one independently [a1,a2,a3, etc] so i can use each piece of the array in a different text box. and then have those boxes change every few seconds in accordance with the number of events.

ive started with the following commands to split each one apart, but i dont know how to call the text file as the array itself.

Code: [ Select ]
my_str = Event_Info.split("|");
   a1 = my_str[0];
   a2 = my_str[1];
   a3 = my_str[2];
   a4 = my_str[3];
  1. my_str = Event_Info.split("|");
  2.    a1 = my_str[0];
  3.    a2 = my_str[1];
  4.    a3 = my_str[2];
  5.    a4 = my_str[3];


i know this is rather wordy and poorly written, but any help would be greatly appreciated.
-jason
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

If the Event_Info string is "number of events|sport|team1|team2|True|location|date|time|score|score", then doing...

Code: [ Select ]
my_str = Event_Info.split("|");
trace(my_str[0]);
  1. my_str = Event_Info.split("|");
  2. trace(my_str[0]);


...should return "number of events"

If that's not working, then my guess would be that there's a problem reading the Event_Info string from the text file.
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

You know what's probably happening? You're probably trying to manipulate the data before the player has had a chance to load it.

I succeeded in doing what you're trying to do here by using "loadVariablesNum ("test.txt" ,0);" in the first frame, then "my_str = Event_Info.split("|");
trace(my_str[0]);" in frame 7. (frame 7 was arbitrary)

so, I could then do a for/next loop to finish up...

Code: [ Select ]
for(i=0;i=numberOfItems-1;i++){
this["a"+i]=my_str[i];
}
  1. for(i=0;i=numberOfItems-1;i++){
  2. this["a"+i]=my_str[i];
  3. }
  • wiggles
  • Novice
  • Novice
  • wiggles
  • Posts: 15

Post 3+ Months Ago

ive tried loading the file into a movie script so i can use the "onload" command to tell when its done. then i use the normal commands to tell the sections where to go. the only problem im having is that nothing shows up in the text boxes. im pretty sure that its seeing everything correctly and working ok, its just not showing anything in the boxes. ideas? could you possibly load your file so i can see what you did?
-jason
  • wiggles
  • Novice
  • Novice
  • wiggles
  • Posts: 15

Post 3+ Months Ago

oh, when i attempt to run the file it also give me an error that simply says "undefined". whats that about?
-jason
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

Is it an error that says undefined, or is that the result of a 'trace' in the output window?

If it's in the output window, it means you're tracing a variable that has no value, or is 'undefined'. So if you thought there should be a value there, something has gone awry.

I'll post my example in just a bit. Are you using Flash MX or MX2004?
  • wiggles
  • Novice
  • Novice
  • wiggles
  • Posts: 15

Post 3+ Months Ago

i have both, my work computer has flash mx, but i have mx2004. whatever is more convient for you, but i am at work now. thanks for your help.
-jason
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

http://www.chriscarney.com/cleanMe/split/

I'm not checking if the text file is loading, so you may need to refresh to let it catch up.

Here's the FLA. (MX2004)
http://www.chriscarney.com/cleanMe/split/Untitled-1.fla
  • wiggles
  • Novice
  • Novice
  • wiggles
  • Posts: 15

Post 3+ Months Ago

i havent checked your file, but i got mine to run ok. now my only remaining problem is getting it to loop properly. i need to use the first number in my array as the number of loops to make, but i need to text fields to change. i first need a delay function to hold the "for" loop for about 5 seconds. and then i need the correct syntax for the loop itself. here is the code without the loop.
Code: [ Select ]
my_str = Event_Info.split("|");

    _root.txt_sport=my_str[1];
    _root.txt_team1=my_str[2];
    _root.txt_team2=my_str[3];
    _root.txt_where=my_str[5];
    _root.txt_when=my_str[6];
    _root.txt_time=my_str[7];
    _root.txt_score1=my_str[8];
    _root.txt_score2=my_str[9];
  1. my_str = Event_Info.split("|");
  2.     _root.txt_sport=my_str[1];
  3.     _root.txt_team1=my_str[2];
  4.     _root.txt_team2=my_str[3];
  5.     _root.txt_where=my_str[5];
  6.     _root.txt_when=my_str[6];
  7.     _root.txt_time=my_str[7];
  8.     _root.txt_score1=my_str[8];
  9.     _root.txt_score2=my_str[9];

i just need a loop like so...
Code: [ Select ]
for(i=0;i<=my_str[0];i++){
   _root.txt_sport=my_str[1+8*"i"]
...etc...
}
  1. for(i=0;i<=my_str[0];i++){
  2.    _root.txt_sport=my_str[1+8*"i"]
  3. ...etc...
  4. }

anyone know how to get it to work and loop properly? the numbering scheme 1+8*"i" is because i need section in the array to move forward 8 sports every loop instance. (ie 1-->8-->16).
-jason
  • wiggles
  • Novice
  • Novice
  • wiggles
  • Posts: 15

Post 3+ Months Ago

thanks everyone for your help. i finally got it to work perfectly.
-jason

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.