【问题标题】:Bindable(event="...") public static functionBindable(event="...") 公共静态函数
【发布时间】:2013-05-13 13:49:18
【问题描述】:

我正在尝试绑定到一个静态函数,我指定一个绑定事件名称,然后从另一个静态函数触发该事件。

[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') 将返回翻译后的组件文本。我需要在用户更改语言时更新应用文本。

【问题讨论】:

    标签: actionscript-3 apache-flex binding mxml


    【解决方案1】:

    绑定不适用于静态属性和方法(有关详细信息,请参阅此问题Binding to static property)。

    在您的情况下,最好对资源管理器使用单例模式,并从 stringupdateData 中删除 static

    MyClass.instance.string('stringPath')
    

    MyClass:

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

    【讨论】:

      猜你喜欢
      • 2019-10-02
      • 2010-10-19
      • 2014-12-28
      • 1970-01-01
      • 1970-01-01
      • 2014-04-27
      • 2011-03-01
      • 2015-09-13
      • 1970-01-01
      相关资源
      最近更新 更多