Thanks Gordon for your answer.
I found the same way, overriding the resourcesChanged method.
For this simple example, I can use dataBinding directly into mxml, but
for my real application, it's useful to do some stuff with actionScript,
especially for labels who changes on user interaction (ie: login phase
with bad return).
For the "rm" instance, it was a mistake/test in my code, I use the
resourceManager property like you said.
Thank you :)
Thierry
Gordon Smith a écrit :
You're setting mybutton.label only once, when init() executes at
creationComplete time. Since you're not using databinding, the label
isn't going to automatically change when you change the localeChain.
You need to override the resourcesChanged() method and reset the label.
Since you like to use code-behind to separate the View from the
Model/Controller, wouldn't it make more sense to consider the
localized strings part of the View and put them in the MXML using
databinding so that they automatically update when the localeChain
changes?
BTW, you don't need to declare and initialize your 'rm' instance
variable. Your 'mycomp2' component already has a 'resourceManager'
property because it extends UIComponent.
Gordon Smith
Adobe Flex SDK Team
------------------------------------------------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED]
*On Behalf Of *Thierry V.
*Sent:* Monday, May 19, 2008 10:56 AM
*To:* [email protected]
*Subject:* [flexcoders] resourceManager and actionScript updates
Hello list,
I have a project with the resourceManager to have internationalisation
on the application.
All works fine when I do my stuff into mxml files, but if I add some
actionScript code into AS code-behind classes, the update seems work
only if the component has not been viewed.
Example : I have a simple mxml / as component with this code :
mxml :
<?xml version="1.0" encoding="utf-8"?>
<my:mycomp2 xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml>" width="400"
height="300"
xmlns:my="*"
creationComplete="init()">
<mx:Script>
<![CDATA[
override protected function init():void
{
// your code here
// (if really necessary, otherwise code on [Class]Base.as)
super.init();
}
]]>
</mx:Script>
<mx:Button id="mybutton" />
</my:mycomp2>
ActionScript :
package
{
import mx.containers.Canvas;
import mx.controls.Button;
import mx.resources.IResourceManager;
import mx.resources.ResourceManager;
public class mycomp2 extends Canvas
{
public var mybutton:Button;
public var rm:IResourceManager;
public function mycomp2()
{
rm = ResourceManager.getInstance();
}
protected function init():void
{
this.mybutton.label = rm.getString('myResources', 'fieldEmail');
}
}
}
On my main mxml application, I set my resourceManager, and have a
combobox to select the correct language. On the change handler of the
combobox, I use :
private function localeComboBox_changeHandler(event:Event):void
{
resourceManager.localeChain = [ localeComboBox.selectedItem ];
resourceManager.update();
}
If I don't display first time my component and change the language, the
component display correctly the update. But since I display the
component, even only one time, it seems that the ResourceManager
wouldn't made any change on the actionScript setted values for the
further displays...
Anybody know this issue / have a solution about it ??
Thanks in advance for any suggestion.
Thierry