0 Replies Latest reply on Jun 22, 2010 6:26 AM by tyler_muth

    Variable URL in data service

    tyler_muth

      I'm new to Flex and trying to create a proof of concept Air App.  I have it connecting to an http service to retrieve data but I want the URL to be configurable.  I created a preferences page which is working, but I can't seem to load the URL preference into a variable for the http service.  Below is my code:

       

       

      <fx:Script>
              <![CDATA[
                  import mx.controls.Alert;
                  import mx.events.FlexEvent;
                 
                  import services.exadatademo.newUrl;
                 
                  //public var testDbUrl:String = "http://localhost/pls/apex/";
                  public var testDbUrl:String;
                 
                  private function init():void
                  {
                      var storedDatabaseUrl:ByteArray = EncryptedLocalStore.getItem("DatabaseUrl");
                      testDbUrl = storedDatabaseUrl.readUTFBytes(storedDatabaseUrl.length);
                     
                      services.exadatademo.newUrl = 'bar';
                      trace(testDbUrl);
                  }               
                 
                  protected function getPrefs():void
                  {
                      var storedDatabaseUrl:ByteArray = EncryptedLocalStore.getItem("DatabaseUrl");
                      dbUrlTxt.text = storedDatabaseUrl.readUTFBytes(storedDatabaseUrl.length);
                      testDbUrl = dbUrlTxt.text;
                      var storedDatabaseUserName:ByteArray = EncryptedLocalStore.getItem("DatabaseUserName");
                      dbUsernameTxt.text = storedDatabaseUserName.readUTFBytes(storedDatabaseUserName.length);
                      var storedDatabasePassword:ByteArray = EncryptedLocalStore.getItem("DatabasePassword");
                      dbPasswdTxt.text = storedDatabasePassword.readUTFBytes(storedDatabasePassword.length);
                     
                  }
                 
                  private function savePrefs():void
                  {
                      var bytes:ByteArray = new ByteArray();
                     
                      //write string text as UTF8 bytes
                      bytes.writeUTFBytes(dbUrlTxt.text);
                      EncryptedLocalStore.setItem("DatabaseUrl", bytes);
                      bytes = new ByteArray();
                      bytes.writeUTFBytes(dbUsernameTxt.text);
                      EncryptedLocalStore.setItem("DatabaseUserName", bytes);
                      bytes = new ByteArray();
                      bytes.writeUTFBytes(dbPasswdTxt.text);
                      EncryptedLocalStore.setItem("DatabasePassword", bytes);
                     
                  }
                 
             
                  protected function button1_clickHandler(event:MouseEvent):void
                  {
                      trace('foo');
                      savePrefs();
                      currentState = "Main";
                  }


                  protected function linkbutton1_clickHandler(event:MouseEvent):void
                  {
                      currentState = "Preferences";
                      getPrefs();
                  }


                 
                  protected function InterconnectTraffic_creationCompleteHandler(event:FlexEvent):void
                  {
                      //GetEmployeesResult.token = exadataDemo.GetEmployees();
                  }
                 


                  protected function button2_clickHandler(event:MouseEvent):void
                  {
                      // TODO Auto-generated method stub
                      GetEmployeesResult.token = exadataDemo.GetEmployees();
                  }


              ]]>
          </fx:Script>


      ...


      package services.exadatademo
      {
          import mx.core.FlexGlobals;
          public var newUrl:String = null;
      public class ExadataDemo extends _Super_ExadataDemo
      {
          public function ExadataDemo():void
             
          {
              super();
              trace(newUrl+'hello');
              trace(FlexGlobals.topLevelApplication['testDbUrl']);
              _serviceControl.baseURL = FlexGlobals.topLevelApplication['testDbUrl'];
             
          }


      }


      }

       

      Thanks,

      Tyler