EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 454

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
454 Working with Text and Strings
9. Type the string bonjour in the fr column.
You use these strings when you use the
lang_cb combo box to change the language on
the Stage.
10. Add the following ActionScript to Frame 1 of the main Timeline:
import mx.lang.Locale;
Locale.setLoadCallback(localeListener);
lang_cb.dataProvider = Locale.languageCodeArray.sort();
lang_cb.addEventListener("change", langListener);
greeting_txt.autoSize = "left";
Locale.loadLanguageXML(lang_cb.value);
function langListener(eventObj:Object):Void {
Locale.loadLanguageXML(eventObj.target.value);
}
function localeListener(success:Boolean):Void {
if (success) {
greeting_txt.text = Locale.loadString("IDS_GREETING");
} else {
greeting_txt.text = "unable to load language XML file.";
}
}
The preceding ActionScript is split into two sections. The first section of code imports the
Locale class and specifies a callback listener that is called whenever a language XML file is
finished loading. Next, the
lang_cb combo box is populated with a sorted array of
available languages. Whenever the
lang_cb value changes, Flashs event dispatcher triggers
the
langListener() function, which loads the specified-language XML file. The second
section of code defines two functions,
langListener(), and localeListener(). The
first function,
langListener(), is called whenever the lang_cb combo boxs value is
changed by the user. The second function,
localeListener(), is called whenever a
language XML file is finished loading. The function checks if the load was successful, and
if so, sets the
text property of the greeting_txt instance to the greeting for the
selected language.
11. Select Control > Test Movie to test the Flash document.
TIP
The XML file that you use must use the XML Localization Interchange File Format
(XLIFF).
CAUTION
The Locale class is different from the other classes in the ActionScript 2.0 Language
Reference, since it is not part of the Flash Player. Because this class installed in the
Flash Authoring classpath, it is automatically compiled into your SWF files. Using the
Locale class increases the SWF file size slightly, because the class must be
compiled into the SWF file.

Table of Contents

Related product manuals