5 Replies Latest reply on Oct 25, 2007 9:41 PM by kglad

    For Loop direction

    Web_Maven Level 1
      I need some direction with the For Loop

      I am using a For Loop to run through and Array. Everything is working except that I need the loop to wait. Each time the loop runs I am downloading an image. I want the Loop to wait for the image to download the continue to the next image wait and continue. The problem is the Loop runs too fast, should I use a Loop or a both a Loop and an "IF" statement?

      I don't want to use a timer because it may take longer to download an image then the timer.

      Can someone put me on the right track?

      Thanks
        • 1. Re: For Loop direction
          kglad Adobe Community Professional & MVP
          you can't make a for-loop wait.

          use two (or more) functions to call each other. that will form a loop and any function call can be delayed while you're waiting for an asynchronous event (like a movieclip load) to occur.
          • 2. For Loop direction
            clbeech Level 3
            you could do away with the FOR loop and use the MovieClipLoader class, and loadClip(). then once an image's download is complete you could use the onLoadComplete or onLoadInit handler to increment the array index and load the next clip. You can also use the onLoadProgress handler to control a progress bar during each load, to inform the user that something is happening, and reuse the same preloader for each load.

            EDIT: ... holy crap kg, lol!!!
            • 3. Re: For Loop direction
              nstanz
              why does it have to wait? Is it hanging?
              You can use an onEnterFrame function and have it delete when the end of the array is reached. That will run a bit slower or create a function and add a setInterval(functionName) and kill the interval when the end of the array is reached.
              • 4. Re: For Loop direction
                Web_Maven Level 1
                Thanks Kglad I like that idea and started thinking that way on my commute.

                clbeech that's a good idea too but I am using Northcode which will give me the onloadcomplete.

                nstanz I have to wait for the image to download and I need to be sure I have the file and I can't download anything else until the routine is complete.

                Thanks for your help and pointing me in the right direction!
                • 5. Re: For Loop direction
                  kglad Adobe Community Professional & MVP
                  you're welcome.