Resource Bundles

Flex provides support for resource bundles in your applications.

Introduction to resource bundles

A resource bundle is a list of assets that is organized by locale. These assets can be just about anything, from strings, numbers, formats, and images to styles. You typically have a separate resource bundle for each locale that your application supports.

To localize an application with resource bundles, you first create properties files that define the localized assets. You then compile these properties files into the application as resource bundles, or create resource modules from the properties files and load them at run time.

Flex lets you change locales on the fly; if you compile more than one resource bundle into an application, you can toggle the resource bundle based on the locale. In addition, if you compile resource modules, you can load and unload the SWF files at run time based on the locale. You can even create new resource bundles programmatically.

How you load your resource bundles depends on how many locales your application supports:
  • If your application supports just one or two locales, then you typically compile all the resources into the application. For more information, see Using resources.

  • If your application supports many locales, you will likely want to load the appropriate resources at run time rather than compile all supported resources into the application at compile time. To do this, you compile your resource bundles into resource modules. For more information, see Using resource modules.

If your application only needs to format numbers, currencies, and sort orders, you can use the built-in support for localization in the spark.globalization.* classes without using resource bundles.

Related information

Creating resources

You define resource bundles in resource properties files. These properties files contain key/value pairs and are in UTF-8 format. You commonly use these properties files to specify the values of Strings in your applications, such as the label on a button or the items in a drop down list. The following example specifies the values for a form's labels in English:

 # locale/en_US/RegistrationForm.properties 
 registration_title=Registration 
 submit_button=Submit Form 
 personname=Name 
 street_address=Street Address 
 city=City 
 state=State 
 zip=ZIP Code 
 thanks=Thank you for registering!

Resources can also embed binary assets such as audio files, video files, SWF files, and images. To embeds these assets in your properties files, you use the Embed() directive, just as you would include assets in a runtime style sheet. The following example embeds a JPG file as a resource:

 flag=Embed("images/unitedstates.jpg")

You can also extract symbols from an embedded SWF file when using the Embed() directive, as the following example shows:

 flag=Embed(source="FlagsOfTheWorld.swf", symbol="unitedstates")

To include custom classes, such as a programmatic skin, you can use the ClassReference() directive. The following example embeds the MySorter class in the sortingClasses.en_US package:

 SORTER=ClassReference("sortingClasses.en_US.MySorter")

For information on how to use these various types of resources in your application, see Using resources.

You typically store resource properties files in a locale/locale_name subdirectory. You add this directory to your source path so that the compiler can find it when you compile your application, and append the locale to the locale compiler option. For information on how to compile resources into your Flex application, see Compiling resources into Flex applications.

Compiling resources into Flex applications

After you create the resource properties files, you can either compile them as resource bundles into your application or you compile them into resource modules and load them at run time. If you compile the resources into the application, the compiler converts them to subclasses of the ResourceBundle class, and adds them to the application at compile time. If you compile the resources into resource modules, the compiler converts them to SWF files that you then load at run time on an as-needed basis.

For information on compiling and using resource modules, see Using resource modules.

Compile resources into the application on the command line

  1. Specify one or more locales to compile the application for with the locale compiler option. The value of this option is used by the source-path option to find the resource properties files. The library-path option also uses this value to include localized framework resources.

  2. Specify the location of the resources with the source-path option. You can add the resources for more than one locale by using the {locale} token.

  3. Set the value of the allow-source-path-overlap compiler option to true. This is optional, but if you do not set it, you might get a warning that the source path for the locale is a subdirectory of the project's source path.

In the following example, the LocalizedForm.mxml application uses a custom resource bundle for a single locale, en_US:

 mxmlc -locale=en_US -source-path=c:\myapp\locale\{locale} -allow-source-path-overlap=true c:\myapp\LocalizedForm.mxml

Properties file syntax

Properties files are parsed as they are in Java. Each line typically takes the form of key=value. The following rules apply to properties files:

  • Lines in properties files are not terminated by semi-colons or other characters.

  • You can use an equals sign, a colon, or whitespace to separate the key from the value; for example:

     key = value 
     key : value 
     key value
  • To add a comment to your properties file, start the line with a # or !. You can insert whitespace before the # or ! on a comment line. The following are examples of comments in a properties file:

     ! This is a comment. 
     # This is a comment.
  • Whitespace at the beginning of a value is stripped. Trailing whitespace is not stripped from the value.

  • You can use standard escape sequences such as \n (newline), \r (return), \t (tab), \u0020 (space), and \\ (backslash).

  • Backslash-space is an escape sequence for a space; for example, if a value starts with a space, you must write it as backslash-space or the compiler will interpret it as optional whitespace preceding the value. You are not required to escape spaces within a value. The following example starts the value with a space:

     key =\ value
  • You can continue a line by ending it with a backslash. Leading whitespace on the next line is stripped.

  • Backslashes that are not part of an escape sequence are removed. For example, \A is just A.

  • You are not required to escape a double quote or a single quote.

  • Lines that contain only whitespace are ignored.

Adding new locales

To add new locales to your projects:

  1. Add the locale to the locale compiler option. This is typically a comma-separated list, as the following example shows:

     -locale=en_US,es_ES

    If you edit the flex-config.xml file, you add locales by using the following syntax:

     <locale> 
     	<locale-element>en_US</locale-element> 
     	<locale-element>es_ES</locale-element> 
     </locale>
  2. Ensure that the new locale's resource properties files are in the source path. The source path entry for localized resources typically uses the {locale} token so that all new locales are automatically added to the source path, as long as those locales' resource directories have the same parent directory.

  3. Create the framework resource bundles for the new locale, if the framework resource bundles do not already exist. You can see a list of the supported bundles by looking at the directory list under framework/bundles. The supported list includes en_US, ja_JP, fr_FR, ru_RU, and es_ES.

The locale option defines what locale's resources to include on the source path. It also instructs the compiler to include the localized framework resources for the specified locales. Framework components such as Label and Button use resources, just like your application and custom components can use resources. The resources required by these classes are located in the libraries like framework.swc or in separate resource bundle libraries. By default, framework resources for many common locales are included in the Flex SDK.

To use any supported locale, you do not need to do anything other than create properties files for your locale. For locales that are not included, such as en_IN, in addition to creating the new properties files, you must also create new framework locale files before compiling your Flex application.

To create a locale's framework resources, use the copylocale utility in the /sdk/bin directory.

The syntax for the copylocale utility is as follows:

 copylocale original_locale  new_locale

For example, to create the framework locale files for the en_IN locale, use the following command:

 copylocale en_US en_IN

This utility creates a new directory under frameworks/locale/locale_name. The name of this directory matches the name of the new locale. This directory is parallel to the other locale directories. In this example, it creates the locale/en_IN directory. This utility also creates SWC files in the new directory, including the framework_rb.swc and rpc_rb.swc files.

These resources must be in the library path. By default, the locale/{locale} entry is already set for your library-path compiler option, so you do not need to change any configuration options.

When you compile your application, and add the new locale to the locale option, the compiler includes the localized framework resources in the SWC files for that new locale.

About the ResourceBundle class

For each resource properties file, the Flex compiler generates a class that extends the ResourceBundle class, and adds that class to the application. The name of the class is the name of the properties file, with an underscore replacing the period in the filename.

The generated ResourceBundle class overrides a single method, getContent(), which returns an object that defines the values in the properties file. For example, if you use the RegistrationForm.properties file, the compiler generates the following class:

 public class RegistrationForm_properties extends ResourceBundle { 
 	override protected function getContent():Object { 
 		var properties:Object = {}; 
 		properties["registration_button"] = "Registration"; 
 		properties["submit_button"] = "Submit Form"; 
 		properties["personname"] = "Name"; 
 		properties["street"] = "Street Address"; 
 		properties["city"] = "City"; 
 		properties["state"] = "State"; 
 		properties["zip"] = "ZIP Code"; 
 		properties["thanks"] = "Thank you for registering!"; 
 		return properties; 
 	} 
 }

To view the generated classes, you can set the keep-generated-actionscript compiler option to true when you compile your application with an existing resource properties file.

You can write your own classes that extend the ResourceBundle class rather than create resource properties files that the compiler then uses to generate the resource bundle classes. You can then use those classes if you include them in your project. For more information, see Creating resource bundles at run time.

Using resource bundles

After you create a resource properties file, you can use it in your Flex application as a resource bundle (the compiler converts properties files to subclasses of the ResourceBundle class when you compile your application). You can either bind values from the resource to an expression, or you can use methods of the ResourceBundle class to access those values.

There are two ways to access the values in resource bundles:

  • @Resource directive

  • Methods of the ResourceManager class

Using the @Resource directive to include resource bundles in your application is the simplest method. In the directive, you specify the name of the properties file and the key that you want to use. This method is simple to use, but is also restrictive in how it can be used. For example, you can only use the @Resource directive in MXML and you cannot change locales at run time. In addition, this directive only returns Strings.

The other way to access resource bundles is through the ResourceManager class. You can use the methods of the ResourceManager class in ActionScript, whereas you can only use the @Resource directive in MXML. These methods can return data types other than Strings, such as ints, Booleans, and Numbers. You can also use this class to switch locales at run time, so if you compiled multiple locales into the same application, you can change from one locale to the other.

The following sections describe how to use the @Resource directive and the ResourceManager class to access resource bundles in your Flex application.

Using the @Resource directive

In MXML, you can use the @Resource directive to access your resource bundles. You pass the @Resource directive the name of the resource bundle (the name of the properties file without the .properties extension) and the name of the key from the key/value pairs in the properties file. The directive returns a String of the key's value from your resource bundle.

The following example creates a form; the values for the labels in the form are extracted from the RegistrationForm.properties resource properties file.
<?xml version="1.0"?> 
<!-- resourcebundles/LocalizedForm.mxml --> 
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark"> 
 
    <s:layout> 
        <s:VerticalLayout/> 
    </s:layout> 
 
    <s:Form> 
        <s:FormItem label="@Resource(key='personname', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="@Resource(key='street_address', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="@Resource(key='city', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="@Resource(key='state', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="@Resource(key='zip', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
    </s:Form> 
</s:Application>

Because this application only uses a single locale, you compile it with the following compiler options:

 -locale=en_US -allow-source-path-overlap=true -source-path=locale/{locale}

Accessing the values in a resource bundle with the @Resource directive is restrictive in that the directive can only be used in an MXML tag. In addition, you cannot change the locale at run time.

To use a class, such as a programmatic skin, as a resource, you use the ClassReference() directive in your properties file. The following example embeds the MyCheckBoxIcon_en_US class in the properties file:

 CHECKBOXSKIN=ClassReference("MyCheckBoxIcon_en_US")

You then reference that class in your style properties, as the following example shows:

 <mx:CheckBox selected="true" 
 	selectedUpIcon="@Resource(key='bundle1', 'CHECKBOXSKIN')" 
 	selectedDownIcon="@Resource(key='bundle1', 'CHECKBOXSKIN')" 
 	selectedOverIcon="@Resource(key='bundle1', 'CHECKBOXSKIN')"/>

To use a binary asset such as an image, you embed the image in the resource properties file. You can then use the asset anywhere that you might use an embedded image. To embed an image in the properties file, you use the Embed directive in your properties file, as the following example shows:

 flag=Embed("images/unitedstates.gif")

The location of the image is relative to the location of the properties file. In this case, the images directory is under locale/en_US.

In your application, you use the @Resource directive anywhere a String might supply the location of the image. The following example uses the image as a source for the <s:Image> tag:
<?xml version="1.0"?> 
<!-- resourcebundles/LocalizedFormResourceWithImage.mxml --> 
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark"> 
     <s:layout> 
        <s:VerticalLayout/> 
    </s:layout> 
 
   <s:Image source="@Resource(key='flag', bundle='RegistrationForm')"/> 
 
    <s:Form> 
        <s:FormItem label="@Resource(key='personname', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="@Resource(key='street_address', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="@Resource(key='city', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="@Resource(key='state', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="@Resource(key='zip', bundle='RegistrationForm')"> 
            <s:TextInput/> 
        </s:FormItem> 
    </s:Form> 
</s:Application>

Using the ResourceManager

To use resource bundles in ActionScript, you use the methods of the ResourceManager class, such as getString() and getClass(). Using the ResourceManager is more flexible than using the @Resource directive because it lets you dynamically rather than declaratively set the values of properties from resources. It also lets you change locales at run time so that all localized resources in your application can be updated at once.

When using the ResourceManager, you must specify metadata that defines the resource bundles for your application. The syntax for this metadata is as follows:

 <fx:Metadata> 
 	[ResourceBundle("Resource_file_name")] 
 </fx:Metadata>

For example:

 <fx:Metadata> 
 	[ResourceBundle("RegistrationForm")] 
 </fx:Metadata>

For multiple resource bundles, add each one on a separate line inside the same <fx:Metadata> tag, as the following example shows:

 <fx:Metadata> 
 	[ResourceBundle("RegistrationForm")] 
 	[ResourceBundle("StyleProperties")] 
 	[ResourceBundle("FormatterProperties")] 
 </fx:Metadata>

In an ActionScript class, you apply the metadata above the class name, as the following example shows:

[ResourceBundle("RegistrationForm")] 
 public class MyComponent extends UIComponent {  
 	... 
 }

You can also bind expressions to the ResourceManager. These expressions are updated any time the locale changes.

The following example uses ActionScript to set the value of the Alert message, and binds the labels in the form to resources by using the ResourceManager's getString() method.
<?xml version="1.0"?> 
<!-- resourcebundles/LocalizedFormWithBinding.mxml --> 
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark"> 
 
    <fx:Script><![CDATA[ 
        import mx.resources.ResourceBundle; 
        import mx.controls.Alert; 
 
        private function registrationComplete():void { 
            Alert.show(resourceManager.getString('RegistrationForm', 'thanks')); 
        }  
    ]]></fx:Script> 
 
    <s:layout> 
        <s:VerticalLayout/> 
    </s:layout> 
 
    <fx:Metadata> 
        [ResourceBundle("RegistrationForm")] 
    </fx:Metadata> 
    <s:Form> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','personname')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','street_address')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','city')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','state')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','zip')}"> 
            <s:TextInput/> 
        </s:FormItem> 
    </s:Form> 
    <s:Button id="b1" 
        label="{resourceManager.getString('RegistrationForm','submit_button')}" 
        click="registrationComplete()"/> 
</s:Application>

To use a binary asset such as an image with the ResourceManager, you embed the image in the resource properties file. You can then use the asset anywhere that you might use an embedded image. To embed an image in the properties file, you use the Embed directive in your properties file, as the following example shows:

 flag=Embed("images/unitedstates.gif")

The location of the image is relative to the location of the properties file. In this case, the images directory is under locale/en_US.

To use the image in your application, you use the ResourceManager's getClass() method. The following example uses the GIF file as both a skin for the Button control and a source for the <s:Image> tag:
<?xml version="1.0"?> 
<!-- resourcebundles/LocalizedFormBindingWithImages.mxml --> 
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    creationComplete="initApp()"> 
    <fx:Script><![CDATA[ 
        import mx.resources.ResourceBundle; 
        import mx.controls.Alert; 
 
        private function initApp():void { 
            b1.setStyle("downSkin", resourceManager.getClass("RegistrationForm", "flag"));            
        } 
 
        private function registrationComplete():void { 
            Alert.show(resourceManager.getString('RegistrationForm', 'thanks')); 
        }  
    ]]></fx:Script> 
    
    <s:layout> 
        <s:VerticalLayout/> 
    </s:layout> 
 
    <fx:Metadata> 
        [ResourceBundle("RegistrationForm")] 
    </fx:Metadata> 
    <s:Image source="{resourceManager.getClass('RegistrationForm', 'flag')}"/> 
 
    <s:Form> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','personname')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','street_address')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','city')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','state')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','zip')}"> 
            <s:TextInput/> 
        </s:FormItem> 
    </s:Form> 
    <s:Button id="b1" 
        label="{resourceManager.getString('RegistrationForm','submit_button')}" 
        click="registrationComplete()"/> 
</s:Application>

To use a class, such as a programmatic skin, as a resource, you use the ClassReference() directive in your properties file. The following example embeds the MyCheckBoxIcon_en_US class in the properties file:

 CHECKBOXSKIN=ClassReference("MyCheckBoxIcon_en_US")

You can bind the value of the getClass() method for programmatic skins, as the following example shows:

 <mx:CheckBox selected="true" 
 	selectedUpIcon="{resourceManager.getClass('bundle1','CHECKBOXSKIN')}" 
 	selectedDownIcon="{resourceManager.getClass('bundle1','CHECKBOXSKIN')}" 
 	selectedOverIcon="{resourceManager.getClass('bundle1','CHECKBOXSKIN')}"/>

For more information about the ResourceManager, see About the ResourceManager.

Changing locales at run time with the ResourceManager

A common use of localization is to provide multiple locales for a single application, and to let the user switch the locale at run time. You can compile all possible locales into the application and then choose from among them. This solution is not very flexible because you can only select from locales that you added to the application at compile time. This solution can also lead to larger applications because the resource properties files and all of their dependencies must be compiled into the application.

You can also compile resource properties files into resource module SWF files, and then dynamically load those SWF files at run time. These modules provide all the resources for the locales. The advantage to this approach is that the application SWF file is smaller because the resources are externalized, but it requires an additional network request for each resource module that the client loads. For information on using resource modules, see Using resource modules.

You change the locale at run time by changing the value of the ResourceManager's localeChain property. This property takes an Array as its value. The Array's first element is the current locale (such as en_US or es_ES).

To be able to change the locale at run time without using resource modules, you compile all the available locales into the application at compile time by including them as part of the locale option. This compiler option takes a comma-separated list of locales. If you add a second locale, such as es_ES, change the locale option to the following:

 -locale=en_US,es_ES

The Flex application uses the list of locales in the localeChain property to determine precedence when getting values from resource bundles. If a value does not exist in the first locale in the list, the Flex application looks for that value in the next locale in the list, and so on.

Before compiling additional locales into an application, you must generate the framework resources for that locale, if they are not already created. You do this with the copylocale command-line utility. For more information, see Adding new locales.

The order of the locales on the command line can be important. The application defaults to the first locale in the list if you do not specifically set the value of the ResourceManager's localeChain property when the application initializes.

The following example lets you select a new locale from the ComboBox control. When you change that value, the application updates the localeChain property. The application's locale-specific assets, such as the form labels, flag image, and alert message should change to the new locale.
<?xml version="1.0"?> 
<!-- resourcebundles/BasicLocaleChain.mxml --> 
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    creationComplete="initApp()"> 
    <s:layout> 
        <s:VerticalLayout/> 
    </s:layout> 
 
    <fx:Script><![CDATA[ 
        import mx.resources.ResourceBundle; 
        import mx.controls.Alert; 
 
        [Bindable] 
        private var locales:Array = [ "es_ES","en_US" ]; 
 
        private function initApp():void { 
            b1.setStyle("downSkin", resourceManager.getClass("RegistrationForm", "flag"));            
    
            // Initialize the ComboBox to the first locale in the locales Array. 
            localeComboBox.selectedIndex = locales.indexOf(resourceManager.localeChain[0]); 
        } 
 
        private function registrationComplete():void { 
            Alert.show(resourceManager.getString('RegistrationForm', 'thanks')); 
        }  
        private function comboChangeHandler():void { 
            // Set the localeChain to either the one-element Array 
            // [ "en_US" ] or the one-element Array [ "es_ES" ]. 
            resourceManager.localeChain = [ localeComboBox.selectedItem ]; 
            
            // This style is not bound to the resource bundle, so it must be reset when 
            // the new locale is selected. 
            b1.setStyle("downSkin", resourceManager.getClass("RegistrationForm", "flag"));            
        } 
    ]]></fx:Script> 
 
    <fx:Metadata> 
        [ResourceBundle("RegistrationForm")] 
    </fx:Metadata> 
    <s:Image source="{resourceManager.getClass('RegistrationForm', 'flag')}"/> 
 
    <mx:ComboBox id="localeComboBox" 
        dataProvider="{locales}" 
        change="comboChangeHandler()"/> 
 
    <s:Form> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','personname')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','street_address')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','city')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','state')}"> 
            <s:TextInput/> 
        </s:FormItem> 
        <s:FormItem label="{resourceManager.getString('RegistrationForm','zip')}"> 
            <s:TextInput/> 
        </s:FormItem> 
    </s:Form> 
    <s:Button id="b1" 
        label="{resourceManager.getString('RegistrationForm','submit_button')}" 
        click="registrationComplete()"/> 
</s:Application>

When you compile this example application, you must add both locales to the locale option, as the following list of compiler options shows:

 -locale=en_US,es_ES -allow-source-path-overlap=true -source-path=locale/{locale}

Because this application uses multiple locales, you must prepare properties files for each one. You should have the following files in your project to use this example:

 /main/BasicLocaleChain.mxml 
 /main/locale/en_US/RegistrationForm.properties 
 /main/locale/en_US/images/unitedstates.gif 
 /main/locale/es_ES/RegistrationForm.properties 
 /main/locale/es_ES/images/spain.gif

The contents of the properties files for this example should be similar to the following:

 # /locale/en_US/RegistrationForm.properties 
 registration_title=Registration 
 submit_button=Submit Form 
 personname=Name 
 street_address=Street Address 
 city=City 
 state=State 
 zip=ZIP Code 
 thanks=Thank you for registering! 
 flag=Embed("images/unitedstates.gif") 
  
 # /locale/es_ES/RegistrationForm.properties 
 registration_title=Registro 
 submit_button=Enviar el formulario 
 personname=Nombre 
 street_address=Dirección de calle 
 city=Ciudad 
 state=Estado 
 zip=Código postal 
 thanks=¡Gracias por inscribirse! 
 flag=Embed("images/spain.gif")

If you do not bind the properties in your application to your resources, then those values are not updated when the locale changes.

When you compile an application for multiple locales, the ResourceManager's localeChain property is initialized to the locales specified by the locale compiler option. For example, if the locale option is -locale=en_US,es_ES, the application defaults to the English resources because en_US is listed first. You can override this default initial value at run time by specifying the value of the localeChain as an application parameter in the flashVars variable in the HTML template.

If you write your own HTML template, you can pass variables as flashVars properties in the <object> and <embed> tags. The following example specifies that the es_ES locale is the first in the localeChain property's Array:

 <object id='mySwf'  
 	classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  
 	codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab'  
 	height='100%'  
 	width='100%'> 
 	<param name='src' value='BasicLocaleChain.swf'/> 
 	<param name='flashVars' value='localeChain=es_ES,en_US'/> 
 	<embed name='mySwf'  
 		src='FlashVarTest.swf'  
 		pluginspage='http://www.adobe.com/go/getflashplayer'  
 		height='100%'  
 		width='100%'  
 		flashVars='localeChain=es_ES,en_US' 
 	/> 
 >

If you are using SWFObject 2, the default template that Flex uses, define and pass the flashVars object to the embedSWF() JavaScript method, as the following example shows: