1 Reply Latest reply on Feb 2, 2010 2:44 PM by jimmyrees

    as3/flex procedural timing / httpservice

    jimmyrees

      Hi there, I am creating an app that makes a few httprequests to php scripts which then return xml. I want to be able to validate the xml which will determine if a function should terminate or continue. I'm using the result event in httpservice to perform further testing on the results, which will then update a bindable boolean to determine if the function that called the httpservice should continue or stop. The problem I seem to be having is that when I send the HTTPService (in the example below, IEXPHP.send(requestObject); actionscript seems to jump to the conditional statement before the checkResult() function has finished.

       

      Is there a way to provide a boolean-type response to an httpservice request after it's resultevent has been called?

       

      Here's a excerpt of the code

       

       

                  [Bindable]public var checkResultR:Boolean;


                  public function sync():void {
                      //get IEX roster data
                      var todayCheck:int = ((GBreaks.selected || OBreakCheck.selected) ? 1 : 0);
                      var weekCheck:int = ((gTWCheck.selected || OTWCheck.selected) ? 1 : 0);
                      var nweekCheck:int = ((gNWCheck.selected || ONWCheck.selected) ? 1 : 0);
                      requestObject = {username:iexUser.text, password:iexPass.text, today:todayCheck, thisWeek:weekCheck, nextWeek:nweekCheck, request:"getIEX"}
                      appendLog("<i>Retrieving IEX Roster Data...</i>");
                      IEXPHP.send(requestObject);

                     if (checkResultR == false) {

                          return;

                     }

       

                  }

       

                     public function checkResult(event:ResultEvent, request:String):void {
                      if (request == "getIEX") {
                          if (event.result.schedule.error) {
                              appendLog("IEX Query <b>FAILED</b>. <br />Wrong Username/Password or unable to retrieve query.");
                              checkResultR = false;
                          } else {
                              IEXPayload = event.result.schedule;
                              appendLog("IEX XML data received OK!");
                              checkResultR = true;
                          }
                      }
                 
      <mx:HTTPService url="http://(...)getSchedule.php" id="IEXPHP" method="POST" result="checkResult(event, requestObject.request)" fault="Alert.show('Request failed. Check your IEX login and password')"/>