Weblog Commenting and Trackback by HaloScan.com smspoonam@gmail.com: ActionScript and Java utility classes
|

Wednesday, May 31, 2006

ActionScript and Java utility classes

Following the discussion about ressource bundles on FlexCoders mailing list, I've created some ActionScript and Java utility classes to use java resource bundles (properties files) with Flex :
- ResourceBundle.as, resource bundle container class,
- ResourceBundleLocator.as, resource bundle registration/locator class,
- ResourceBundleDelegate.mxml, delegate class to call remote object ResourceBundleService and load java resource bundles,
- ResourceBundleService.java, service class to get java resource bundles and return them to the flash client.

I've also created a payment form sample app to put the resource bundles in action (for french and english languages).

It is based on the PaymentForm sample app that Jimmy from Optimal Payments wrote :
http://www.macromedia.com/devnet/flex/articles/xmlhelp.html

The difference between the two approach :
- in the XML approach, all the messages are loaded at compile time,
- in the resource bundle approach, the messages are loaded at runtime only for a given language.

Messages inclusion at compile time increases the swf file size.
It is a nice approach if you do have to support few languages and the app is pretty small.
If you need to support several languages with thousands of messages, resource bundles loaded at runtime is a preferable way to go, because the client is only going to load the messages for its corresponding language.

If you have any suggestion to improve those classes, do not hesitate to contact me.

Benoit Hediard
ben@benorama.com

PS : those utility classes can be very easily used with cairngorm framework.
PS2: if you want a nice resource bundle editor for eclipse : http://sourceforge.net/projects/eclipse-rbe/

---------------
Downloads
---------------

Download resource bundle utility classes :
http://www.benorama.com/flex/globalization/ResourceBundle.zip

Download sample app :
http://www.benorama.com/flex/samples/PaymentFormRB.zip


---------------------------------------
How to run the sample app?
---------------------------------------

Unzip :
- actionscript user_classes files in your WEB-INF/Flex/user_classes folder,
- java classes files in your WEB-INF/Classes folder,
- PaymentApp.mxml where ever you want in your root flex folder,
- if necessary, add com.benorama.flex.globalization.* in your remote object white list (in flex-config.xml),
- (re)start flex,
- launch PaymentApp.mxml.

-------------------------
How does it work?
-------------------------

1- in each view helper, the resource bundles are registered by the locator during initialization,
...
public function SomeViewHelper() {
this.resource = new ResourceBundle();
ResourceBundleLocator.getInstance().register("com.mycompany.myapp.globalization.SomeResourceBundle", this.resource);
}
...

2- at the end of the application mxml file, the resource bundle delegate is created and initialized with default language, so it calls the ResourceBundleService on the server to get all the registered bundles for a given locale and load them in the client.
...

...

3- in each view, bindings to the bundles load the corresponding resources.

2 Comments:

At 7:46 AM, Blogger sutanuc said...

can you provide me the code?

 
At 4:00 AM, Blogger Twinja said...

Hi - will this work with Flash & AS3 or do you need Flex? Is there any way to get it working with just Flash & AS3?

ta,

James

 

Post a Comment

<< Home