About strings and the String class
453
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
Flash Player replaces string IDs with strings from the XML file,
which matches the default system language code that is returned by
language
(capabilities.language property)
.
Manually using stage language
String IDs are replaced by strings when the SWF file
compiles, and cannot be changed by Flash Player.
Using ActionScript at runtime
You can control string ID replacement by using
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.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...