1 Reply Latest reply on Mar 30, 2007 11:26 AM by ntsiii

    how to send results to actionscript using java via HttpService

    Kingwell
      Hi,
      I do RPC using HttpService.
      In my situation, I need to send results from Java code to Flex Action script. I have defined a Java Servlet receiving data from Flex application, then it processes with the data, finally the Servlet is supposed to send some feedbacks to the client(Flex).

      My question is that how can I define codes in doPost() method that the following function will get "result" from the Java side.

      public static function httpResult(event:ResultEvent):void
      {
      var result:Object = event.result;
      //Do something with the result.
      if (result.toString() == "success")
      {
      resultMessage.text = "Login Success";
      }
      resultMessage.text = "Invalid User";
      }
        • 1. Re: how to send results to actionscript using java via HttpService
          ntsiii Level 3
          I advise having your servlet build an xml string, maybe put a status attribute in the root tag, like this:
          <myroot status="success">
          <mytext>Some text</mytext>
          </myroot>
          and return that to the calling Flex client. XML is easier to work with than Object. On the HTTPService tag, set resultFormat="e4x", and it will return plain XML.

          then in the handler, do:
          var xmlResult:XML = XML(event.result); //this will already be the myroot node
          //Do something with the result.
          if (xmlResult.@status== "success") //reads the status attribute
          {
          resultMessage.text = xmlResult.mytext.text(); //get the value of themytext text() node
          }
          resultMessage.text = "Error";
          }

          Tracy