Actionscript 3 如何在locale类和UI组件之间设置绑定
我正在试图弄清楚如何正确设置我的语言环境类和mxml文件之间的绑定 我的主mxml文件包含:Actionscript 3 如何在locale类和UI组件之间设置绑定,actionscript-3,apache-flex,binding,Actionscript 3,Apache Flex,Binding,我正在试图弄清楚如何正确设置我的语言环境类和mxml文件之间的绑定 我的主mxml文件包含: <mx:Button id="TMP" label="{Locale.getLocaleString('title'}"/> 这就是我找到的解决方案: 扩展EventDispatcher,使类可绑定,并在加载完成时发送事件。() 将类从静态类转换为单例(,) 这是我的最终代码: [Bindable(event="loaded")] public class LocaleSingleto
<mx:Button id="TMP" label="{Locale.getLocaleString('title'}"/>
这就是我找到的解决方案:
- 扩展
,使类可绑定,并在加载完成时发送事件。()EventDispatcher
- 将类从静态类转换为单例(,)
[Bindable(event="loaded")]
public class LocaleSingleton extends EventDispatcher{
private var _dictionary:Dictionary = new Dictionary();
public function LocaleSingleton(){/* Do check to make sure it is a singleton*/}
public function get instance(){...}
public function loadResources():void {
...
dispatchEvent(new Event("loaded")); // Method in EventDispatcher
}
public function getLocaleString(featureID:String):String {
if(_dictionary[featureID]==null){
return "";
}
return _dictionary[featureID];
}
}
实际上,您允许绑定到函数。我不知道资源管理器是否会分派相应的绑定事件,但我怀疑它会分派。请注意,无论何时创建静态类,你很可能做得不对…@Amy你可以绑定到一个函数,但是你如何让它更新?为什么不使用Flex提供的
ResourceManager
?你可以,即使这就是为什么你想使用你自己的类。更好的解决方案是使用.Dispatch绑定事件。有关绑定工作原理的更多信息,请查看。不幸的是,adobe.tv上录制的演示文稿现在无法使用,否则我会发送给您,这样会更好。但这总比什么都没有好。
[Bindable(event="loaded")]
public class LocaleSingleton extends EventDispatcher{
private var _dictionary:Dictionary = new Dictionary();
public function LocaleSingleton(){/* Do check to make sure it is a singleton*/}
public function get instance(){...}
public function loadResources():void {
...
dispatchEvent(new Event("loaded")); // Method in EventDispatcher
}
public function getLocaleString(featureID:String):String {
if(_dictionary[featureID]==null){
return "";
}
return _dictionary[featureID];
}
}