0

次のシングルトンがあります。

package singletons{

import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.net.SharedObject;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.registerClassAlias;


public class AppConfiguration extends EventDispatcher
{
    public static const SUCCESSFULCONFIGURATION:String = "ConfigurationSuccessful";
    public static const CONFIGURATIONERROR:String = "ConfigurationError";

    private var _userID:Number;     
    private var _serverIP:String;       
    private var _serverPort:Number;     
    private var _serverURL:String;
    private static var _instance:AppConfiguration; 


    public static function getInstance():AppConfiguration
    {
        if (_instance == null) 
        {
            _instance = new AppConfiguration();
            registerClassAlias( "singletons.AppConfiguration", AppConfiguration );
        }

        return _instance;
    }       

    public function initialize():Boolean
    {           
        var configFile:SharedObject = SharedObject.getLocal("InternalConfiguration");


        if (configFile.data.internalConfiguration == null) 
        {               
            return false;
        }           

        var localConf:AppConfiguration =  AppConfiguration(configFile.data.internalConfiguration);
        _userID = localConf.UserID;
        _serverIP = localConf.ServerIP;
        _serverPort = localConf.ServerPort;
        _serverURL = "http://" + _serverIP + ":" + _serverPort;

        return true;        
    }

    public function setInternalConfiguration(userID:Number, serverIP:String, serverPort:Number):void
    {
        _userID = userID;
        _serverIP = serverIP;
        _serverPort = serverPort;
        _serverURL = "http://" + _serverIP + ":" + _serverPort;

        var configurationRequest:URLRequest = new URLRequest(_serverURL + "/getHello?userID=" + _userID);
        var requestLoader:URLLoader = new URLLoader();
        requestLoader.addEventListener(Event.COMPLETE, getConfigurationHandler);
        requestLoader.addEventListener(IOErrorEvent.IO_ERROR, getConfigurationErrorHandler);
        requestLoader.load(configurationRequest);
    }

    private function getConfigurationHandler(event:Event):void
    {
        // 1.2.- Asignar los valores de las variables obtenidas a las variables locales


        var configFile:SharedObject = SharedObject.getLocal("InternalConfiguration");
        configFile.data.internalConfiguration = this as AppConfiguration;
        configFile.flush();

        var successEvent:Event = new Event(SUCCESSFULCONFIGURATION);
        dispatchEvent(successEvent);            
    }

    private function getConfigurationErrorHandler(event:IOErrorEvent):void
    {
        var failedEvent:Event = new Event(CONFIGURATIONERROR);
        dispatchEvent(failedEvent);                 
    }


    public function get UserID():Number 
    {           
        return _userID;
    }

    public function get ServerIP():String 
    {           
        return _serverIP;
    }

    public function get ServerPort():Number 
    {           
        return _serverPort;
    }       
    public function get ServerURL():String 
    {           
        return _serverURL;
    }       
}

}

また、2 つのシングルトンのプロパティ ServerURL と UserID を HTTPService のプロパティ URL と Request にバインドしようとすると、変更後に HTTPService で値が更新されません。バインディングを作成するコードは次のとおりです。

<fx:Declarations>
    <s:HTTPService id="getStatusService"
                   url="{internalConfiguration.ServerURL}/getObject"
                   result="getStatusHandler(event)" fault="getStatusErrorHandler(event)">
        <s:request>
            <codec>{internalConfiguration.CodecID}</codec>
        </s:request>
    </s:HTTPService>                    
</fx:Declarations>

そして、getStatusService.send() を実行すると、「null/getObject」になります。

HTTPService 内で変数が更新されない理由を知っている人はいますか?

助けてくれてありがとう。

セバスチャン

4

1 に答える 1