I’m trying to make a flash where the text dynamically updates from a text file every time the .swf file is started.
I’m not the brightest when it comes to this, but I will try and explain what I want to make.
I want to have a .txt file in a certain format. Similar to this
example:
Team1: Time
Player1: Dusk
Player2: Dawn
Player3: Noon
Team2: Food
Player1: Pizza
Player2: Cheese
Player3: Bread
And then output the text after each element and output them to a dynamic text object with the same name.
I would have an empty text object named Team1: Where after this script is run it would say “Time” instead of blank.
I’ve tried a few different ways of reading the file, but it’s when it comes to the splitting and sending it to the dynamic text objects I have trouble.
The end result with proper adjusting from flash would look something like this
Time vs Food
Dusk Pizza
Dawn Cheese
Noon Bread
This is the current code of what I have as of right now
var TextLoader:URLLoader = new URLLoader();
TextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
var PlayerArray:Array = e.target.data.split(/\n/);
}
TextLoader.load(new URLRequest("roster1.txt"));
So the question is really, how do I split this properly with the formatting I use and then set the dynamic text to the text followed by the tag (team1:, player1:, etc)
Any help would be greatly appreciated
Here is a quick and dirty attempt at splitting the data:
It assumes the prefix and value will be separated by “: ” and that “Team” is used to determine the start of a team.
It loops through the array of strings and splits each string along “: “, then checks to see if the prefix contains the string “Team” to determine if it is the start of a new team or is currently a player of the current team.
The result is an array of team arrays, where each team array’s index 0 is the team name followed by the players.
From here you should just be able to create the textfields (or use existing ones) and set the text from the arrays.
Perhaps others can come up with a more efficient method? I also tried to see if it was possible by combining it into a long string and splitting along “Team”, then “Player”, then “: “, to try and separate it out, but it got more messy and possibly error prone if a player’s name contained “Team” or “Player” in it.