1 Reply Latest reply on Nov 22, 2009 6:16 AM by chris.huston.t10

    Receive answer from the server?

    mh22gw

      I have made an app that sends mail from Flex. it's working and the mail is sent. I'm using "HTTPService", I have tried to use "lastResult" to receive an enswer from the server, this will not work. How can I do to receive an answer from the server?

       

      public

       

      function sendMail():void{

       

      if(txtName.text == "" || txtMail.text == "")

      {

      Alert.show(

      "Du måste ange ditt namn.");

      }

       

      else{

      srv.send();

      }

      }

       

       

      private function getResult(event:ResultEvent):void{

      Alert.show(event.message.toString());

      }

       

       

      public function emailResult():void{

      Alert.show(

      "Ditt meddelande är skickat.");

       

      //this.submitBtn.enabled = false;

      }

       

       

      public function faultHandler():void{

      Alert.show(srv.toString());

      }

       

      <mx:HTTPService

       

      id="srv" url="http://www.mhwebb.se/swfcontact.aspx" method="POST"

      result="emailResult()" fault="faultHandler()"

      >

       

      <mx:request>

       

      <name>

      {txtName.text}

       

      </name>

       

      <mail>

      {txtMail.text}

       

      </mail>

       

      <subject>

      {txtSubject.text}

       

      </subject>

       

      <mess>

      {txtMess.text}

       

      </mess>

       

      </mx:request>

       

      </mx:HTTPService>

       

      <mx:Form height="312" width="341" x="0">

       

       

       

      <mx:Panel x="10" y="10" width="308" height="276" layout="absolute" title="mhWebb FlexMail" backgroundColor="#FDFCD3">

       

      <mx:Label x="10" y="10" text="Ditt namn:" width="100"/>

       

      <mx:Label x="10" y="36" text="Din e-post:" width="100"/>

       

      <mx:Label x="10" y="62" text="Ämne:" width="100"/>

       

      <mx:Label x="10" y="88" text="Meddelande:" width="100"/>

       

      <mx:TextInput x="118" y="8" id="txtName"/>

       

      <mx:TextInput x="118" y="34" id="txtMail"/>

       

      <mx:TextInput x="118" y="64" id="txtSubject"/>

       

      <mx:TextArea x="118" y="94" id="txtMess" height="100"/>

       

      <mx:HBox x="10" y="202" width="268">

       

      <mx:Button label="Skicka" id="btnSend" click="sendMail()" fillAlphas="[1.0, 1.0, 0.3, 1.0]" fillColors="[#FFFFFF, #FFFFFF, #A6FAB0, #05CA1C]"/>

       

      <mx:Button label="Radera" id="btnDelete" fillAlphas="[1.0, 1.0, 0.3, 1.0]" fillColors="[#FFFFFF, #FFFFFF, #FBBABA, #FF0000]"/>

       

      </mx:HBox>

       

      </mx:Panel>

       

      </mx:Form>

        • 1. Re: Receive answer from the server?
          chris.huston.t10 Level 3

          Listen for the result event in a function rather than accessing the result directly in the lastResult. This will make it much easier to debug the returned result.

           

          <mx:HTTPService

           

          id="srv" url="http://www.mhwebb.se/swfcontact.aspx" method="POST"

          result="emailResult(event)" fault="faultHandler()"

          >

           

          public function emailResult(event:ResutlEvent):void{

          trace(event.result); //Depending on your result, you may need to add the property field you want to access i.e. event.result.myMessage

          Alert.show(

          "Ditt meddelande är skickat.");

           

          //this.submitBtn.enabled = false;

          }

           

          Chris