4 Replies Latest reply on Nov 14, 2006 11:14 AM by ntsiii

    HTTPService issues

    dr_ross Level 1
      hi all, i'm having problems scripting the HTTPService, when i use the mxml style like this

      <mx:HTTPService id="userRequest" url="check1.php" useProxy="false" method="POST">
      <mx:request xmlns="">
      <username>{username.text}</username><password>{password.text}</password><emailaddress>{em ailaddress.text}</emailaddress>
      </mx:request>
      </mx:HTTPService>

      it all works fine, but when i try and script it like this i can't seem to get a response from the server script.

      var service:HTTPService = new HTTPService();
      service.url="check1.php";
      service.useProxy = false;
      service.method = "POST";
      service.request = {userName:username.text,password:password.text,emailaddress:emailaddress.text};
      service.addEventListener("result", authenticateHandler);
      service.send();

      any ideas would be much appreciated,
      dr_ross
        • 1. Re: HTTPService issues
          NUMB-LOCK Level 1
          Has the result made it to your "authenticateHandler(event:ResultEvent):void" function?
          • 2. Re: HTTPService issues
            ntsiii Level 3
            Exactly the correct question.

            Tracy

            • 3. Re: HTTPService issues
              dr_ross Level 1
              thanks for the replies,
              yeah my listener is being broadcast to now, only issues i'm having now is with the formatting of the passed event.

              heres my listener

              private function authenticateHandler(event:ResultEvent):void
              {

              Alert.show("Result:"+":"+event.result.users);
              }

              and the php that was called printed out somethinig like this
              <users><user><username>name1</username><user><user><username>name2</username><user><users>

              but i can't seem to access any of the data in the result event. all i get is either null, or the old [object Object].
              I was thinking the event.result.users should be an array i could reference lik event.result.users.user[0].username but Flex really didn't like that
              • 4. Re: HTTPService issues
                ntsiii Level 3
                I advise setting the resultFormat="e4x". I believe the default is "object".

                Then in the handler do:
                var xmlResult:XML = XML(event.result);
                Alert.show("Result:"+":"+xmlResult.toXMLString());

                You should see your xml.

                The e4x XML object is very powerful, with XPath-like selection expressions that return an XMLList, which has properties similar to arrays.

                Tracy