Using the Locale class
The Locale class (mx.lang.Locale) allows you to control how multilanguage text is displayed
in a Flash application at runtime. With the Strings panel, you can use string IDs instead of
string literals in dynamic text fields, which allows you to create a SWF file that displays text
loaded from a language-specific XML file. You can use the following methods to display the
language-specific strings contained in the XML Localization Interchange File Format
(XLIFF) files.
Automatically at runtime
which matches the default system language code that is returned by
(capabilities.language property)
Manually using stage language
compiles, and cannot be changed by Flash Player.
Using ActionScript at runtime
ActionScript, which is controlled at runtime. This option gives you control over both the
timing and the language of string ID replacement.
You can use the properties and methods of the Locale class when you want to replace the
string IDs by using ActionScript to control the application when it plays in Flash Player. For a
demonstration of how to use the Locale class, see the following procedure.
To use the Locale class to create multilanguage sites:
1.
Create a new Flash document and save it as locale.fla.
2.
Open the Strings panel (Window > Other Panels > Strings) and click Settings.
3.
Select two languages, en (English) and fr (French), and click Add to add the languages to
the Active languages pane.
4.
Select the Via ActionScript at Runtime option, set the default runtime language to French,
and click OK.
5.
Drag a ComboBox component from the User Interface folder of the Components panel
(Window > Components) onto the Stage and give it the instance name lang_cb.
6.
Create a dynamic text field on the Stage using the Text tool and give the text field the
instance name greeting_txt.
7.
With the text field selected on the Stage, type a string identifier of greeting in the ID text
box of the Strings panel and click Apply.
You'll notice that Flash converts the greeting string into IDS_GREETING.
8.
In the String panel's grid, type the string hello in the en column.
Flash Player replaces string IDs with strings from the XML file,
.
String IDs are replaced by strings when the SWF file
You can control string ID replacement by using
language
About strings and the String class
453
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?