Translating PopupMenuButton

5 views
Skip to first unread message

gravitystorm

unread,
Feb 22, 2011, 2:15:19 PM2/22/11
to BabelFx
Hi there,

I've been struggling to translate a Flex3 PopupMenuButton, and I'm not
sure how to approach things. I have a simple button with and array of
two objects in the dataProvider:

<mx:PopUpMenuButton id="gpsButton" styleName="appBarButton"
itemClick="if (event.index==0) { trackLoader.load(); } else { new
MyGpxDialog().init(); }">
<mx:dataProvider>
<mx:Array>
<mx:Object label="GPS data" id="gpsData" />
<mx:Object label="My tracks" id="myTracks" />
</mx:Array>
</mx:dataProvider>
</mx:PopUpMenuButton>

In the smartresourceinjector I can reference the objects:

<ResourceProxy property="gpsButton.dataProvider[0].label"
key="main.gps_data" />
<ResourceProxy property="gpsButton.dataProvider[1].label"
key="main.my_tracks" />

And in the console everything appears fine:

19:05:58.268 [DEBUG]
com.mindspace.l10n.injectors::SmartResourceInjector inject 'GPS
Informations' into 'gpsButton.dataProvider[0].label' from resource
p2_main::main.gps_data
19:05:58.268 [DEBUG]
com.mindspace.l10n.injectors::SmartResourceInjector inject 'Mes
Pistes' into 'gpsButton.dataProvider[1].label' from resource
p2_main::main.my_tracks

The other things I'm translating work fine too. But the problem is the
text on the PopupMenuButton doesn't change. I'm certainly no expert on
binding, but I think the problem is that using Objects means that when
the label attribute is changed there's no binding events triggered to
cause the PopupMenuButton to update itself from the altered
dataProvider. I've tried various approaches using XML, XMLLists,
ArrayCollections but in every case haven't got it working - either the
injector is happy but nothing changes, or I can't get the
ResourceProxy to fire properly ("target ... is unknown" and
"Unresolved node" errors, mainly).

Can anyone suggest a solution, or point me to working example that I
can get some inspiration from?

Cheers,
Andy
Message has been deleted
Message has been deleted

ThomasBurleson

unread,
Feb 22, 2011, 10:24:42 PM2/22/11
to BabelFx
Andy,
The problem (as you deduced is a Databinding issue). Arrays of generic
objects will not dispatch propertChange events so UI databinding will
trigger and update.
You have only two choices: (1) create a bindable value object class or
(2) make changes in the LocalizationMaps to run a custom closure/
eventHandler after localChanges.

See this Gist for details:

https://gist.github.com/5153153be93de655dc3c

Option 1) will work... but it is not ideal because a custom
valueObject class is required.
Option (2) is really the only viable solution to these issues when the
presentation models are not bindable.

Notice, here we elected to not use any ResourceProxy tags... we simply
want to know when the localeChanged.
Each SmartResourceInjector will dispatch its own localeChanged
event... so you can easily get access to all target instances.
Then you manually build the dataProvider with calls to the
ResourceManager.

gravitystorm

unread,
Feb 23, 2011, 5:45:35 AM2/23/11
to BabelFx
Hi Thomas,

Thanks very much for your examples. I've tried both, and the second
one worked. The first one has a limitation where although the data
provider changes successfully the PopupMenuButton doesn't redraw the
displayed label until you (re)select one of its items from the
dropdown. I'm not sure whether that's because there's a bug in the
Flex component or whether there's again something wrong in the binding
chain, but I'll go with your second option for now.

Many thanks again,
Andy
Reply all
Reply to author
Forward
0 new messages