2 Replies Latest reply on Apr 26, 2008 10:05 AM by machmila

    function listener?

      I have a function set up to loop thru an array and perform specific actions for each item in that array. The problem I'm having is that the statments aren't executing in the order I'm intending and I'm guessing it's because they are taking too long and the loop is moving on before they have finished executing. I'm trying to figure out if there is way to "pause" my for loop while I call a function - and make sure that function has returned data before the loop continues on.

      In the attached code you can see the initializeData function is where I'm looping thru an array of groups. For each group I'm trying to call "populateCategories()" which will essentially make an httpService call to load that data. The end result I'm getting though, is that the httpService is being run the correct number of times but always with the group information for the final array position, not each one in order as I'm intending. Is this possible or is there a better way to go about this?

        • 1. Re: function listener?
          jylaxx Level 1
          To serialized this type of process I use this simple queuing mechanism :
          private var qIndex : int ;
          private function initializeGroupData():void{
          groupsAC = new ArrayCollection(groupArray);

          qIndex = -1 ;
          populateNextCategory() ;

          private function populateNextCategory() : void {
          qIndex++ ;
          if ( qIndex < groupsAC.length ) {
          currentGroup = groupsAC[qIndex] ;
          populateCategories( currentGroup ) ;

          private function userDataHandler( event : ResultEvent ) : void {
          // your code to process result
          // ...

          // load next category
          populateNextCategory() ;
          • 2. Re: function listener?
            machmila Level 1
            worked great - thanks for the help!!