Skip to main content
Inspiring
December 2, 2008
Answered

AS 2 help please

  • December 2, 2008
  • 4 replies
  • 484 views
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
This topic has been closed for replies.
Correct answer Rothrock
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);


4 replies

RothrockCorrect answer
Inspiring
December 4, 2008
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);


grovemanAuthor
Inspiring
December 5, 2008
Hi Rothrock,

Many thanks you were a great help, now it all works
Inspiring
December 3, 2008
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?
grovemanAuthor
Inspiring
December 4, 2008
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;

}
grovemanAuthor
Inspiring
December 3, 2008
Thanks for the info, but could you provide an example of what the script should be to achieve this!

Many thanks
Inspiring
December 2, 2008
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.