Having just localized a medium sized application into Spanish, I ran
into a recurring pattern I had to work around that I really shouldn't
have to, specifically around data binding localized resources from
ActionScript.
For example, in MXML, one can data bind a localized resource and when
the localeChain is switched dynamically, all bound clients will requery
their values and the new language will display:
<mx:Label text="{resourceManager.getString(ResourceEnums.COMMON,
'labelAppointments}"/>
When the localeChain is switched, the label above will automatically
update to the Spanish version, just like magic. This is a very cool
feature of Flex 3 resource management.
However, there are many use cases where I need to bind to resource
bundles from within ActionScript, sort of like this:
public class Foo
{
[Bindable]
public var bar:String;
public function Foo()
{
bar = ResourceManager.getString(ResourceEnums.COMMON,
'labelAppointments');
}
}
When the localeChain is updated, "bar" is obviously not automatically
updated because bar is not bound to the resource, it is just a simple
assignment.
BindingUtil.bindProperty and bindSetter don't appear to offer parameters
that will work with ResourceManager. I've experimented a little, but it
does not appear possible to use BindingUtils to bind to a resource.
I had to work around this by listening for a localeChange event and then
reassigning the resource to the variable. This does not scale.
So my question is simple: can you bind a variable to a resource in
ActionScript? If so, how?
Thanks!
Erik
Erik Thomas | Small Business Group, Intuit | Staff Engineer |
650-944-2602