Coming from a Java background, I wanted to have something on the lines of using resource bundles for my Flex Application pages. Though I don’t have any qualms in proclaiming myself ‘too’ lazy, I hated to hard code values in the mxml files. Also, I am hopeful that my current application is going to be used worldwide. Hope was never a bad thing, you see… You can ask that from my hiring managers about that. J Anyways I was excited that resource bundles were used in Flex. Flex coders all over the world are blessed.
Cool… so let’s start… I’ll show you how this is done in Flex.
Add the locale folder to the Flex build path.

The locale can now have subdirectories for each of the languages that you plan to deploy your application. (eg. en_US and en_UK)
Add the properties files to the subdirectories. (say the PageProp.properties)
Add the ‘Key-Value’ pairs to the properties file in the following format.
Key = Value
Key : Value
The Resource bundle values can be accessed in two ways
- @Resource directive
- ResourceManager class methods.
Using the @Resource directive
mx:Label text="@Resource(key='pageTitle', bundle='PageProp')"
Using the ResourceManager class
mx:Label text="{resourceManager.getString('PageProp','pageTitle')}"
0 comments:
Post a Comment