2 Replies Latest reply on Jul 30, 2008 12:04 PM by Cr99

    Waiting until a method finishes

    Cr99 Level 1
      I have a method which is making a call to a servlet via HTTPService and filling the results in an ArrayCollection. It then loops through the arrayCollection to test and see if the array contents match against a given ID. However even though the code is sequentially correct, the arraycollection doesn't get filled until after the test for the ID is made! How do I get around this?

      makeHTTPquery(); // returns results but only AFTER the following line
      IDlabel.text = generateID(id);

      private function makeHTTPquery(event:ResultEvent):void {
      IDarray=(event.result.system.data);
      }
      trace("report ID leng", reportIDs.length+"");
      }
      private function generateID(id:String):String {
      //....check IDarray for id
      }
        • 1. Re: Waiting until a method finishes
          Rob Rusher
          Remember that the execution is going to happen asynchronously, so move the second method call to inside the results handler.

          quote:


          makeHTTPquery(); // returns results but only AFTER the following line

          private function makeHTTPquery(event:ResultEvent):void
          {
          IDarray=(event.result.system.data);
          IDlabel.text = generateID(id);
          }

          private function generateID(id:String):String {
          //....check IDarray for id
          }
          • 2. Waiting until a method finishes
            Cr99 Level 1
            Oops, I thought it worked, and it does in this case because id happens to be a global variable, but what if I need to have the resultevent function get a value passed to it that is generated on the fly say in actionscript? In otherwords, what if I can't just call generateID in the makeHTTPquery function because id is generated just before or after the makeHTTPquery call?

            private function makeHTTPquery(event:ResultEvent):void
            {
            IDarray=(event.result.system.data);
            IDlabel.text = generateID(id); // <-- can't access id, need it passed as a reference
            }