2013-05-18 53 views
0

我想綁定到一個靜態函數,我指定一個綁定事件名稱,然後從另一個靜態函數中觸發該事件。Bindable(event =「...」)公共靜態函數

[Bindable(event="dataUpdated")] 
public static function string(path:String) :String 
{ 
    ... 
} 

private static function updateData() :void 
{ 
    //doSomthing; 
    staticEventDispatcher.dispatchEvent(new Event('dataUpdated')); 
} 

private static var staticEventDispatcher:EventDispatcher = new EventDispatcher(); 

我的觀點在事件被解僱時沒有更新,有沒有更好的方法來做到這一點?

我也嘗試從班級實例派遣活動,我添加了這個staticEventDispatcher作爲最後的手段,但它沒有奏效。


在此點如果在應用程序中的語言翻譯,MyClass.string('stringPath')將返回翻譯組件中文。我需要在用戶更改語言時更新應用文本。

回答

2

綁定不適用於靜態屬性和方法(有關詳細信息,請參閱此問題Binding to static property)。

在你的情況下,最好使用單件模式的資源管理器,並從stringupdateData刪除static

MyClass.instance.string('stringPath') 

MyClass

public static const instance:MyClass = new MyClass(); 
+0

謝謝,現在固定。 – Drahcir