PDA

View Full Version : bind static method in external AS file


tobydeh
01-09-2007, 06:51 PM
Hi Guys. I have an external .as file that has an event binded to a static method. I need to call this event somehow but im having trouble as all my methods are static. here is the code:

Lang.as: (external AS package)


// UserData ActionScript file
package
{
import mx.resources.ResourceBundle;
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.controls.Alert;
import mx.binding.utils.ChangeWatcher;
import mx.rpc.events.ResultEvent;
import mx.core.Application;
import mx.events.FlexEvent;

[Bindable]
public class Lang extends Application
{
static public var lang:String = 'en';

//english
[ResourceBundle("en_common")]
static public var common_en:ResourceBundle;
[ResourceBundle("en_titles")]
static public var titles_en:ResourceBundle;
[ResourceBundle("en_buttons")]
static public var buttons_en:ResourceBundle;

//french
[ResourceBundle("fr_common")]
static public var common_fr:ResourceBundle;
[ResourceBundle("fr_titles")]
static public var titles_fr:ResourceBundle;
[ResourceBundle("fr_buttons")]
static public var buttons_fr:ResourceBundle;

[Bindable(event="langChanged")]
static public function getline(bundle:String, key:String):String
{
return Lang[bundle+'_'+Lang.lang].getString(key);
}

[Bindable(event="langChanged")]
static public function _getline():void
{
Alert.show('yes');
}

static public function langChange():void
{
var e:Event = new Event("langChanged");
var d:EventDispatcher = new EventDispatcher;
d.dispatchEvent(e);
}

}
}


From within my application i then try to call the following:


Lang.lang = 'fr';
Lang.langChange();


Lang.langChange() is called as it should be... and the event is dispatched although the "getline" method is not initiated by the "langChanged" event.

Please help its been 12 hours of misery so far!!!

Kind regards,

Toby.

hangalot
01-17-2007, 01:07 PM
interesting code. resource bundle mmm. i like that.
anyway, why are you making these methods static (hence your binbding issues), have you considered a singleton approach?