2 Replies Latest reply on Apr 26, 2009 11:50 AM by IlyaG

    How to access httpService data from mx:script?

    IlyaG

      Hi guys, I am trying to test the data I am getting from httpService, but I don't know how to access it.

       

      This is my httpService:

       

       

      <mx:HTTPService id="loginRequest" url="http://localhost/login.php" useProxy="false" method="POST" >

              <mx:request xmlns="">

                  <username>{username.text}</username>

                  <password>{password.text}</password>

              </mx:request>

          </mx:HTTPService>

       

       

      the login.php is testing if the pass is match, this is how its looks like:

       

       

      <?php

      define( "DATABASE_SERVER", "localhost" );

      define( "DATABASE_USERNAME", "root" );

      define( "DATABASE_PASSWORD", "" );

      define( "DATABASE_NAME", "test2" );

       

      //connect to the database.

       

      $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);

       

      mysql_select_db( DATABASE_NAME );

       

      $quary="SELECT * FROM users WHERE username='".$_POST['username']."'";

      $Result = mysql_query($quary);

      $User = mysql_fetch_object( $Result );

       

      $Return = "<user><username>"."wrong"."</username></user>";


      if ($_POST['password']==($User->password))

      $Return = "<user><username>".$User->username."</username></user>";


      mysql_free_result($Result);

      mysql_close($mysql);

      echo ($Return);

      ?>

       

       

      Now I wont to see what the login.php found, was it the correct pass or not, I was trying lots of thing but I have no idea how to do it.

      This is what I was trying at the lost time:

       

       

       

      <mx:Script>

              <![CDATA[



                     private function login():void

                     {

                 

                            loginRequest.send();

                            Alert.show(loginRequest.lastResult.user,"Testing");

                     }

                ]]>

       

      the funny thing that I have no problem to put this on dataGrid, it works fine, just cant test the data only post it

        • 1. Re: How to access httpService data from mx:script?
          Michael Borbor Level 4

          You need to add an event listener to the httpservice, the calls to services are asynchronous so that's the reason you'll need to add to your HttpService something like this:

           

          result="myResultHandler(event)"
          

          and then create the result handler something like this;

           

          private function myResultHandler(event:ResultEvent):void{
                Alert.show(loginRequest.lastResult.user,"Testing");
          }
          

          Although you could omit the event parameter. In the DataGrid your code works because the binding mechanisms detect that the data has change and update the DataGrid, but in this case once you call your function there isn't a way that Flash Player will execute it again withouth calling the function again.

          1 person found this helpful
          • 2. Re: How to access httpService data from mx:script?
            IlyaG Level 1

            Wow tnx a lot, this is working now.