1 Reply Latest reply on May 5, 2011 5:37 PM by Teriath

    Update button label when locale changes, in AS3


      What I'm trying to do is pretty do what this does:


      <s:Button label="{resourceManager.getString('Strings', 'some_resource')}"/>


      but in ActionScript code. I have a function to add a new tab button to a layout which takes a string and just trying to set the label to the same string doesn't work obviously. So what I need is a way to set the button label to some bindable value that will update whenever the locale changes, like it does automatically when doing it in MXML.

        • 1. Re: Update button label when locale changes, in AS3
          Teriath Level 1

          Nevermind, I figured it out. For those of you that are curious about the solution I found it's in the code below. The only way I could figure out how to get it working is by declaring a local function right after creating a button and attaching it as a "change" event handler to the resourceManager.


          public function addTab(resourceName:String):uint
               var newTab:Button = new Button();
               newTab.label = resourceManager.getString('Strings', resourceName);
               newTab.setStyle("skinClass", Skins.Buttons.TabButton);
               // Create a local function that will update the button label whenever the locale changes
               var localeChangeHandler:Function =
                    function (e:Event):void
                         newTab.label = resourceManager.getString('Strings', resourceName);
               resourceManager.addEventListener("change", localeChangeHandler);