8 Replies Latest reply on Jan 29, 2007 10:48 AM by jonjon09

    read text with actionscript

    jonjon09
      I have been looking all around for this answer but I never really found the exact answer I'm looking for.... I need something that would read a .txt file and compare it to a variable containing a .txt file (already loaded), and if it is the same then it will do an action.
      My case is that I have 1 file for each language (3 languages) containing the same information but in a different language. And I would like to check what language is already loaded, so that it knows what language file it should load in the variable when someone presses a button in the nav bar.
      I hope I'm clear enough. Please let me know if you know or if you need me to find a better way to say this.
      Thanks you.
        • 1. Re: read text with actionscript
          sly one Level 1
          This is called conditional logic. You use an if statement to check on the value of your variable. Example:

          • 2. Re: read text with actionscript
            jonjon09 Level 1
            hum, it seems to work when I put english but even if I'm on the french page, it loads the english text file..maybe I'm not writing the right thing? or maybe I didn't understand the exact function of your code... it checks what language the file is writen in??
            • 3. read text with actionscript
              SymTsb Level 2
              Test scenario based on what I got from your post....

              Your menu has a Language option to allow them to choose the language of the site. You want it so that if they click on a given button, it loads the proper language file. easy enough i think.


              A few things need to happen.

              First, make the user select their language. Store this in the main timeline as a variable named language. Optionally, you could make a language menu in the main movie and allow them to change languages on a whim. All you have to do is change the language variable when they release the button.

              Second, your files need to be named the same through out the site but the different languages need an identifying pre-marker. For instance, let's say you have 3 welcome files. English would be en_welcome.txt, French would be fr_welcome.txt and Spanish would be sp_welcome.txt. Each of these files contain some content starting with content=

              (Assuming a knowledge of next to nothing here)
              Third, you need a movie clip named target_mc on the _root timeline with a dynamic text field inside it with a variable name (not instance name) of content.

              You could then use the following AS to load the proper welcome file based on the language variable.

              • 4. Re: read text with actionscript
                jonjon09 Level 1
                It gave me a bunch of errors...I corrected some (or tried to, don't know if I'm good enough to do the right thing) but I still can't get it too work :(
                Do I need to give an instance name to the dynamic text field in the movie clip containing the text field?? and for this: function loadFile(var theFile:String) { .... I need to remove the "var" thing, correct? it says it's unexpected...
                • 5. Re: read text with actionscript
                  SymTsb Level 2
                  Sorry. Tried writing the code for you very late last night. Now that I am a bit more awake, here are step by step instructions to create a small version of what I am talking about. You will have to modify it to fit your exact situation.

                  1) create a new flash file and save it on the hard-drive.
                  2) Create a new text file inside notepad or equivalent program.
                  3) In this file, write content=Welcome to our home. Save it as en_welcome.txt, making sure to save it in the same folder as your flash file.
                  4) Create another new text file inside notepad.
                  5) In this file, write content=Bienvenidos a nosotros casa. Save it as sp_welcome.txt making sure to save it in the same folder as your flash file.

                  6) In your new flash file, create a dynamic text field on the stage. Set the variable field in the options bar to content.
                  7) Select the text field and create a symbol out of it. Name it something you'll remember. Give it an instance name of target_mc on the Stage.

                  8) Create a new layer in the main movie for your language menu. Create two buttons on the stage...one for English and one for Spanish. Give each a proper instance name, in my code, I'll be using "english_btn" and "spanish_btn".

                  9) Add a new layer to the main movie again for your standard menu. Create a static text field with the word "Welcome" in it. Select the word welcome and create a symbol out of it named menu and give it an instance name of menu. Double click the new symbol on the stage. Select the word welcome and create another symbol out of it named Welcome and give it an instance name of welcome.

                  10) Now we start coding
                  • 6. Re: read text with actionscript
                    jonjon09 Level 1
                    Thank you for taking your time and explaining everything to me. I appreciate it.
                    I tried to make it work for my file but it didn't work, so I tried with your step by step instructions on a new file...and it still doesn't work! it loads with the spanish text already there and it doesn't change when I click on the buttons :s
                    maybe you can help me better if I give you examples from the code I actually have...
                    • 7. Re: read text with actionscript
                      SymTsb Level 2
                      I'm finally back in the office today. I'll try to get you actual zipped examples today during my lunch break.
                      • 8. Re: read text with actionscript
                        jonjon09 Level 1
                        ok, thanks. I'll check it out after school.