Connecting Tech Pros Worldwide Help | Site Map

Import a Text File in Flash

  #1  
Old 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.
  #2  
Old May 24th, 2009, 10:10 AM
Markus's Avatar
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.
  #3  
Old 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:

Expand|Select|Wrap|Line Numbers
  1. 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.
  #4  
Old 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.
  #5  
Old 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.
  #6  
Old 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:

Expand|Select|Wrap|Line Numbers
  1. echo "var wordList:Array = new Array( ";
  2. while(! word_list.empty() )
  3. {
  4.      echo "\"";
  5.      echo word_list[0];
  6.      echo "\", ";
  7.      word_list.erase(0);
  8. }
  9. 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/
  #7  
Old 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.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting File in Server Program but not uploding it...Need help AshishMishra16 answers 4 July 2nd, 2009 05:59 AM
How to Create SWF File For embedding to Website, Blog, MySpace, WordPress, etc lalano answers 1 September 12th, 2008 09:33 AM
How to Convert PowerPoint to Flash Manually WPeterson insights 3 September 12th, 2008 07:52 AM
Flash button hide/show a DIV-Layer on a html page? elamberdor answers 6 July 7th, 2008 09:54 PM