6 Replies Latest reply on Dec 5, 2008 2:56 AM by groveman

    AS 2 help please

    groveman
      Hi all, I need a script to check platform user language and then load external XML files with corresponding en, fr, and de identifiers. I have the script below, but need to adapt it to load English, French or German XML depending on user language

      menuXML.load("mainMenuXML.xml");

      function initMainMenu() {

      createMainMenuItems();

      }


      Many thanks in advance
        • 1. Re: AS 2 help please
          Rothrock Level 5
          System.capabilities.language is I think what you need.

          Remember that there are people who use computers that aren't their first or preferred language. So it is always a good idea to give the user a choice.
          • 2. Re: AS 2 help please
            groveman Level 1
            Thanks for the info, but could you provide an example of what the script should be to achieve this!

            Many thanks
            • 3. Re: AS 2 help please
              Rothrock Level 5
              Have you tried using System.capabilities.language? Looked it up in the help files?

              It returns a string that reports on the user's language. Mine returns "en" so you could use an if or switch statement to decide which xml file to load. Or you could name your files with the abbreviation in them and then just do that.

              What part are you having trouble with?
              • 4. Re: AS 2 help please
                groveman Level 1
                Thanks, yes I looked it up and added this script with named external xml files, but it still does not work. I need it in AS2 syntax, Any script corrections appreciated.

                trace(System.capabilities.language);


                switch (lang) {
                case "en":
                menuXML.load("mainMenuXML_en.xml");
                break;
                case "de":
                menuXML.load("mainMenuXML_de.xml");
                break;
                case "fr":
                menuXML.load("mainMenuXML_fr.xml");
                break;

                }
                • 5. Re: AS 2 help please
                  Rothrock Level 5
                  Trace will only show YOU the value. To make your code work you need to assign the results of System.capabilities.language to a variable. And in your case you already have "lang" in the switch statement. So this line should be before the switch:

                  var lang:String=System.capabilities.language

                  Once you have that you could replace the switch with:

                  menuXML.load("mainMenuXML_"+lang+".xml");

                  But what if somebody with an italian system or a japanese system logs on?

                  You might want to go back to the switch statement and put one at the end:

                  default:
                  menuXML.load(whateverIsTheDefault.xml);


                  • 6. Re: AS 2 help please
                    groveman Level 1
                    Hi Rothrock,

                    Many thanks you were a great help, now it all works