2010-10-23 56 views
2

我有一個模擬的枚舉如下:如何本地化Flex/Actionscript「枚舉」以確保可綁定性?

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; 
    } 
} 
結合這些枚舉如下

和按鈕:

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

我現在需要本地化此枚舉,但沒有多少運氣得到結合當我更新的區域與其他內容一起更新:

resourceManager.localeChain = [ localeComboBox.selectedItem ]; 

我試圖綁定干將的「改變」事件,理應得到由ResourceManager拋出,但似乎並不奏效。有任何想法嗎?

回答

3

你可以使用

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

其中Sport.BASEBALL.labelSport.BASEBALL.description是從你的資源包的鑰匙。

你也可以看看BabelFx,它不需要插入所有那些醜陋的{resourceManager.getString(...)}語句。它使用運行時注入來本地化您的應用程序。

+0

沒錯,這是一個選項。儘管如此,它感覺並不理想。我會看看BabelFX。 – wachunga 2010-10-25 16:19:45