我有一个模拟枚举,如下所示:
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;
}
}
绑定(bind)到这些枚举的按钮如下:
<mx:Button label="{Sport.BASEBALL.label}" toolTip="{Sport.BASEBALL.description}"/>
我现在需要本地化这个枚举,但是当我更新区域设置时,绑定(bind)与其他所有内容一起更新的运气并不好:
resourceManager.localeChain = [ localeComboBox.selectedItem ];
我尝试将 getter 绑定(bind)到应该由 ResourceManager 抛出的“change”事件,但这似乎不起作用。有什么想法吗?
最佳答案
你可以使用
<mx:Button label="{resourceManager.getString('resourceBundleName', Sport.BASEBALL.label)}" toolTip="{resourceManager.getString('resourceBundleName', Sport.BASEBALL.description)}"/>
其中 Sport.BASEBALL.label
和 Sport.BASEBALL.description
是您的 ResourceBundle 中的键。
您还可以查看BabelFx这消除了插入所有那些丑陋的 {resourceManager.getString(...)}
语句的需要。它使用运行时注入(inject)来本地化您的应用程序。
关于apache-flex - 如何本地化 Flex/Actionscript "enums"以确保可绑定(bind)性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4001923/