星期四, 5月 05, 2011

Flex3 Localization

http://www.herrodius.com/blog/123


1. create a folder in your project src to store your resource bundles (e.g. "locale")
2. create a subfolder for each locale you want to implement (e.g. "locale\en_US" and "locale\zh_TW")
3. in the locale subfolder, create a resources.properties file and save it as UTF-8
4. enter the resources in the form of "key=value", like Ant property files
example:

# locale/en_US/resources.properties
login_id=id
password=password

5. update the compiler settings: -locale=en_US,zh_TW -source-path=locale/{locale}


[ResourceBundle("resources")]



< mx:FormItem label="{resourceManager.getString('resources', 'login_id')}" ....


switch your locale at runtime by setting the localeChain property on the resourceManager:

resourceManager.localeChain = ["en_US"];
//resourceManager.localeChain = ["zh_TW"];


Set focus on textfield in Flex3

In Action Script:
login.setFocus();

In HTML:






< body onload="setFlexAppFocus();">


2. detect press Enter
   

/**
* Handle login when user press enter on password
*/
private function enterListener(e:KeyboardEvent):void {
if(e.keyCode == Keyboard.ENTER) {
enter(); // check login function
}
}