Import a Text File in Flash 
May 23rd, 2009, 04:31 PM
| | Member | | Join Date: Nov 2008
Posts: 80
| | |
Hi,
I'm developing a flash game and need to read data from a text file (about 100k). I do not want to read it from an external file.
-Is it possible to somehow import a text file into flash and compile swf without a need for an external file to read at runtime?
-How about putting the huge data into a string object defined in an .as file? Or is there a specific class to handle such data?
Let me know the right direction to do it.
FYI, the text file contains a list of words (I'm making a word game) and I split the list into an array.
| 
May 24th, 2009, 10:10 AM
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,858
Provided Answers: 9 | | | re: Import a Text File in Flash
Create an array of the words in a AS file that is compiled with the program.
However, I don't recommend this; what if you want to give updates to the word list, or what if you wanted to allow the user to add their own words? A separate file would be best.
| 
May 24th, 2009, 05:26 PM
| | Member | | Join Date: Nov 2008
Posts: 80
| | | re: Import a Text File in Flash
Do you mean hardcoding thousands of words (by copy/paste of course) as: - var wordList:Array = new Array("apple", "orange", "banana");
I'm trying to protect the word list and don't like to do encryption in the text file.
With this method I still can have an external file for users to add new words (I don't think it's likely so in this kind of a game though) and append it to the compiled array.
| 
May 26th, 2009, 11:46 AM
| | Member | | Join Date: May 2009
Posts: 81
| | | re: Import a Text File in Flash
Anybody can see the source code for your flash object, so putting it inside the script won't make much difference. If you want to keep your word list safe, you have to use an encrypted SSL communication and a server side script to supply words.
With that said, there are hundreds of scripting languages (Python comes to mind) that can write the code for you from the word list. It would take <1min to write one.
| 
May 26th, 2009, 03:46 PM
| | Member | | Join Date: Nov 2008
Posts: 80
| | | re: Import a Text File in Flash
I just need to hide it from the average people who like to add the game into their website. I don't like the idea to include a plain text file to the zip archive.
Maybe I should also add a simple encryption to make it harder to get the words by viewing the binary code of the swf (or by using decompilers?), but it's not that much important actually.
About using a scripting language; do you mean generating the .as file from the plain text file? I do have some 'filtering' scripts (PHP) to pick appropriate words in a larger word list so I can easily use them to generate the .as file too.
| 
May 26th, 2009, 07:04 PM
| | Member | | Join Date: May 2009
Posts: 81
| | | re: Import a Text File in Flash
Yes, this is exactly what I mean by "scripting". You would have to do something like this pseudo code: - echo "var wordList:Array = new Array( ";
-
while(! word_list.empty() )
-
{
-
echo "\"";
-
echo word_list[0];
-
echo "\", ";
-
word_list.erase(0);
-
}
-
echo " );";
You don't have to generate the whole .as, just the long and boring part that is easy to automate.
As for keeping people from putting your flash on their website... don't bother, it won't happen. The biggest corporations can't figure out how to keep binary machine code executable warped through the 9 circles of hell (read: SecuROM) from being mass copied, so your Flash object stands no chance. Some basic URL checks will be effective enough against people who know too little to rip the decryption key out of the dissembled script.
If you still want to go through it, you will probably want to take a look at http://code.google.com/p/as3crypto/ | 
May 26th, 2009, 10:40 PM
| | Member | | Join Date: Nov 2008
Posts: 80
| | | re: Import a Text File in Flash
Okay, that's how I thought when I think how to convert the word list into an actionscript array. Quote: |
As for keeping people from putting your flash on their website
| Actually, I do want them to download and use the game in their site (probably with high scores functionality disabled etc.). Just not prefer to deliver a plain text file.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|