0 Replies Latest reply on Nov 4, 2008 3:17 PM by Xilian

    implementing a singleton RemoteObject for different states Help

    Xilian Level 1
      Hello,
      different states in my application need to pull data from a single remote object. however, for some reason it's not been created properly. I've noticed that there are two classes of RemoteObject in flex. The packages mx.rpc.remoting and mx.rpc.remoting.mxml. I used the first one. Is this right? Below is my code.

      Help appreciated.
      Thanks,
      Xilian


      //--------------------------<Remote Object wrapped as singleton in an actionscript class>------------------------------
      import mx.rpc.remoting.RemoteObject;
      [Bindable]
      public class CrawlerHandler
      {
      private static var _crawler:RemoteObject; //only one instance for application

      /**
      * creates and initializes new web crawler engine
      */
      private static function initialize():void
      {
      _crawler = new RemoteObject();
      _crawler.destination = "Crawler";
      }

      public static function getInstance():RemoteObject
      {
      if(_crawler == null)
      initialize();
      return _crawler;

      }
      }


      //-------------------<body of code in a state's actionscript, where remote object is referenced>---------------------------------
      var crawler:RemoteObject = CrawlerHandler.getInstance();
      var csvData:String = crawler.getCSV(); //<<----------------object not created correctly
      if(csvData.length > 0)
      {
      downloadCSVFile(csvData);
      }