2 Replies Latest reply on Mar 11, 2008 2:57 AM by Greg Dove

    Pausing a for loop to wait for result

      I am trying to cycle through an array and send each element to a database, but I don't want the next element to be sent until the previous element has returned a result. I am not really sure how to do that in actionscript? Any ideas?
        • 1. Re: Pausing a for loop to wait for result
          Greg Dove Level 4
          If the array is large it could take a while to do that as each single element would represent a single http exchange. If the subsequent values being sent are not changing as a result of each individual one's response from the server then I would be inclined to send them all at once. (Within reason... if there is a huge amount then perhaps its helpful to split them up also).

          You could do what you're describing using LoadVars or XML (depends on the data type in each array element, and also on preference) , using the sendAndLoad method to send to the server script which processes each element and send back a response to the sendAndLoad method's receiving target argument (usually the same type: either another LoadVars or another XML). You would start the sequence again in that receiving object's onLoad handler. Check out some of the examples for LoadVars.sendAndLoad or XML.sendAndLoad in the help files.

          Or you may want to investigate remoting (e.g. amfphp etc)
          • 2. Pausing a for loop to wait for result
            Greg Dove Level 4
            In just read the title of your topic. In the example I described above you wouldn't use a for loop. You would use a variable to keep track of the current index and increment it each time as you process the next one. The loop is 'event' based, driven by the amount of time it takes for each upload/download cycle for the data being exchanged.