私は構成情報へのグローバルアクセスのためのシングルトンクラスを持っています。 ConfigurationDataというこのシングルトンクラスは、EventDispatcherを継承しています。いくつかのためにFlex/AS3シングルトンクラスから送出されたイベントをリッスンするときの問題
ConfigurationData.getInstance().addEventListener(Event.CONFIGURATION_LOADED, onConfigurationLoaded);
:
/**
* Dispatched when the config file has been loaded.
*/
[Event (name="configurationLoaded", type="flash.events.Event")]
/**
* Dispatched when the config file has been loaded.
*/
[Event (name="configurationLoadFailed", type="flash.events.Event")]
public class ConfigurationData extends EventDispatcher{
// Event name constants.
public static const CONFIGURATION_LOADED:String = "configurationLoaded";
public static const CONFIGURATION_LOAD_FAILED:String = "configurationLoadFailed";
// The singleton instance.
private static var singleton:ConfigurationData;
/**
* Don't call the constructor directly, use getInstance() instead.
*/
public function ConfigurationData(pvt:PrivateClass){
// init
}
/**
* Get the singleton ConfigurationData.
* @return The ConfigurationData instance.
*/
public static function getInstance():ConfigurationData{
if (!ConfigurationData.singleton) ConfigurationData.singleton = new ConfigurationData(new PrivateClass());
return ConfigurationData.singleton;
}
public function initialize():void{
var configureService:HTTPService = new HTTPService;
configureService.url = _config_base_url + _config_path;
configureService.addEventListener(FaultEvent.FAULT, onConfigureFault);
configureService.addEventListener(ResultEvent.RESULT, onConfigureResult);
configureService.send();
}
private function onConfigureResult(event:ResultEvent):void{
var i:int = 0;
for(i=0; i<event.result.carriers.carrier.length; i++){
_mobile_carriers.addItem({label:event.result.carriers.carrier[i].name, data:event.result.carriers.carrier[i].id});
}
dispatchEvent(new Event(CONFIGURATION_LOADED));
}
private function onConfigureFault(event:FaultEvent):void{
_mobile_carriers = _default_carriers as ArrayCollection;
dispatchEvent(new Event(CONFIGURATION_LOAD_FAILED));
}
}
// This class is used to ensure that the ConfigurationData constructor can't be called directly,
// getInstance() must be used instead.
class PrivateClass {
public function PrivateClass() {}
}
は、その後、私はCONFIGURATION_LOADEDイベントをリッスンMXMLコンポーネントを持っている:ここでは、クラス(私はこの短いを維持するために変数宣言のようないくつかのものを残していることに注意)がありますこの理由により、次のエラーが発生します。 1119:静的型Classの参照を介して、おそらく未定義のプロパティCONFIGURATION_LOADEDへのアクセス。
これを修正する方法を知っている人はいますか?私はそのイベントを聞くことができますか?
ありがとうございます!
素晴らしい、ありがとうございました!私はこれが問題だと知っていましたが、私はそれを解決する最善の方法を知らなかった。 Btw、おそらくあなたは私の他のFlexの問題を見てみることができますか? http://stackoverflow.com/questions/825377/scroll-thumb-is-extending-beyond-scroll-track-in-flex-app – Tony