Question

I have a simulated enum as follows:

public class Sport {
    public static const BASEBALL:Sport = new MyEnum("Baseball", "Baseball ...");
    public static const FOOTBALL:Sport = new MyEnum("Football", "Football ...");

    public var label:String;
    public var description:String;

    public function Sport(label:String, description:String):void {
        this.label = label;
        this.description = description;
    }
}

And buttons that bind to these enums as follows:

<mx:Button label="{Sport.BASEBALL.label}" toolTip="{Sport.BASEBALL.description}"/>

I now need to localize this enum, but haven't had much luck getting the binding to update along with everything else when I update the locale:

resourceManager.localeChain = [ localeComboBox.selectedItem ];

I've tried binding getters to the "change" event that supposedly gets thrown by ResourceManager, but that doesn't seem to work. Any ideas?

Was it helpful?

Solution

You could use

<mx:Button label="{resourceManager.getString('resourceBundleName', Sport.BASEBALL.label)}" toolTip="{resourceManager.getString('resourceBundleName', Sport.BASEBALL.description)}"/>

where Sport.BASEBALL.label and Sport.BASEBALL.description are the keys from your ResourceBundle.

You can also take a look at BabelFx which eliminates the need to insert all those ugly {resourceManager.getString(...)} statements. It uses runtime injection to localize your application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top