Flex Does Not Find Resource Bundles

LocalizationProblem

Recently I had the problem that my Flex code, which used the ResourceManager, would not find the resource bundle, which contained all resources for my application. However, the application compiled but it would always crash whenever the first time a resource should be loaded. I checked my compiler arguments a 1000 times but everything was correct and did work well in another Flex application. The problem was that my resource bundle was not present in the ResourceManager, it just did not load it.

My application did not have any UI elements just a visualization UIComponent that I wrote myself. Thus, I did not load any resources from my MXML. A some point I added a UI element (a Button) and tried to load a resource directly from that Button in order to see if it worked there:

1
<mx:Button label="@Resource(bundle='myResources', key='OBJECT')" />

And it worked fine in that Button and suddenly in the whole application as well. So it seemed to me that Flex refused to load the resource bundle if it was not referenced from the MXML. As I did not want to use an UI element in my application I looked for a workaround and stumbled upon this:

1
2
3
<mx:Metadata>
        [ResourceBundle("myResources")]
</mx:Metadata>

This piece of MXML code just needs to be added in the top of your Application or WindowedApplication in order to trigger the loading of the resource bundle.

Posted in Actionscript, Adobe Air, Flash, flex Tagged with: Actionscript, Adobe Air, as3, Flash, flex, flex builder, localization