Question

I am trying to bind to a static function, I designate a binding event name and then fire the event from another static function.

[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();

My view is not updating when the event is fired, is there a better way to do this?

I have also tried dispatching the event from an instance of the class, I added this staticEventDispatcher as a last resort, but it didn't work.


The point in this if for language translations within the app, MyClass.string('stringPath') will return the translated component text. I need the app text to be updated when the user changes their language.

Was it helpful?

Solution

Binding doesn't work with static properties and methods (see this question for details Binding to static property).

In your case it's better to use the singleton pattern for resource manager and remove static from string and updateData:

MyClass.instance.string('stringPath')

and MyClass:

public static const instance:MyClass = new MyClass();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top