Import a Text File in Flash

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • serdar
    New Member
    • Nov 2008
    • 88

    Import a Text File in Flash

    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.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    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.

    Comment

    • serdar
      New Member
      • Nov 2008
      • 88

      #3
      Do you mean hardcoding thousands of words (by copy/paste of course) as:

      Code:
      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.

      Comment

      • unauthorized
        New Member
        • May 2009
        • 81

        #4
        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.

        Comment

        • serdar
          New Member
          • Nov 2008
          • 88

          #5
          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.

          Comment

          • unauthorized
            New Member
            • May 2009
            • 81

            #6
            Yes, this is exactly what I mean by "scripting" . You would have to do something like this pseudo code:

            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/

            Comment

            • serdar
              New Member
              • Nov 2008
              • 88

              #7
              Okay, that's how I thought when I think how to convert the word list into an actionscript array.

              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.

              Comment

              Working...