3 Replies Latest reply on Feb 22, 2008 6:06 AM by 23059600

    Problem with HTTPService in ActionScript

    23059600
      Hello All,

      I created an itemRenderer and now it have to use parameters from a xml in the server. To do that, I created a new AS Class and used the HTTPService in and listeners for the ResultEvent and FaultEvent. But after call the send() method nothing happens, none of events is triggered.

      The class code is below. Anyone can see what I did wrong?

      Thank you!

      Marcos

      package
      {
      import mx.rpc.http.HTTPService;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.AsyncToken;

      public class ConfigReader
      {
      private var _iServer:String;
      private var _project:String;
      private var _configXML:XML;

      public function ConfigReader() {

      var httpService:HTTPService = new HTTPService();

      // the server.xml file is in the same package of the application
      httpService.url = "server.xml";
      httpService.contentType = HTTPService.CONTENT_TYPE_XML;
      httpService.method = "GET";
      httpService.resultFormat = HTTPService.RESULT_FORMAT_E4X;
      httpService.useProxy = false;

      httpService.addEventListener(ResultEvent.RESULT, resultHandler);
      httpService.addEventListener(FaultEvent.FAULT, faultHandler);

      httpService.send();

      if ( _configXML == null ) {
      _iServer = "";
      _project = "";
      } else {
      _iServer = trace(_configXML.iservers.iserver[0].@name) as String;
      _project = trace(_configXML.iservers.iserver[0].@project) as String;
      }

      }

      public function getIServer():String {
      return _iServer;
      }

      public function getProject():String {
      return _project;
      }

      // Result handler
      private function resultHandler(event:ResultEvent):void

      {
      _configXML = event.result as XML;
      }

      // Fault handler
      private function faultHandler(event:FaultEvent):void

      {
      _project = "error!";
      }
      }
      }