1 Reply Latest reply on Feb 23, 2007 5:04 AM by peterent

    HTTPService Question

    wy790289 Level 1
      Hi,

      I would like to write a flex component to let user login/login to application. I create a login box component that contains 2 text fields, "userid" and "password" and a "login" button. When user press the "login" button, the program will call an Action Script function that calling a web service to check the login and return either "Y" or "N" to indicate the login status.

      In the function (source listed below) when the HTTPService is called, it seem the program do not wait the HTTPService return the result and the next statement will be executed (HTTPService executed Async.). So that I cannot get the correct result on the IF statement next to the HTTPService.send() statement. How can I prevent it?

      the function listed:

      private function chkLogin():void {
      if (loginOK.text != "Y") {
      checkLogin.send(); // HTTPService to check login
      if (checkLogin.lastResult.result.login == "Y") { // cannot get correct here here
      txUserID.enabled = false;
      txPassword.enabled = false;
      loginOK.text = "Y";
      btLogin.label = "Logout";
      } else {
      Alert.show("Login Failed, Please Retry!");
      }
      } else {
      txUserID.enabled = true;
      txPassword.enabled = true;
      loginOK.text = "N";
      btLogin.label = "Login";
      }
      return;
      }
        • 1. Re: HTTPService Question
          peterent Level 2
          All Flex data service calls are asynchronous - you cannot change it. Flex uses the http protocol which is asynchronous.

          Add a result handler to your HTTPService which will be invoked when the reply is returned. Once you've made the HTTPService request, don't do anything else. Do not show the user a new screen, just end the function. When your result handler is invoked, examine the result given and then move to the next step.