6 Replies Latest reply on Oct 5, 2007 6:19 AM by Newsgroup_User

    Problem with repeat loop

    TimDixon
      Hi,

      I have an application I am creating that collects records from a database when the user clicks a button. There are about 10,000 records and this takes about 3 seconds to collect.

      What I'd like is for an animated flash barpole to appear whilst its getting the data, then dissapear when completed.
      (I've created the flash file and use sprite(xx).goToFrame("show") and sprite(xx).goToFrame("hide") to control the barpole).

      The problem I am having is that the data from the database is collected using a 'repeat with n = 1 to totalrows' loop - and this hangs the app for the time its in the loop. ...So much so that the flash animation will not play!!!

      Does anyone know of a way to collect the data whilst having the flash file still play/animate?

      Cheers,

      Tim
        • 1. Re: Problem with repeat loop
          Level 7
          You can stick an updateStage() command into your repeat loop. That will
          tell everything on the stage to loop again. Sometimes it has
          unpredictable results, but sometimes it works perfectly...

          repeat with i=1 to 10000
          --do something with your database
          updateStage()
          end repeat
          • 2. Re: Problem with repeat loop
            TimDixon Level 1
            Hi Mike, Thanks for the reply.

            I've tried using the updatestage idea, but it increases the time to complete the repeat loop loads!! 3secs becomes more like 10 - 15 secs!!

            Any other ideas?

            Anyone?


            Cheers
            • 3. Re: Problem with repeat loop
              Level 7
              You can try a sendAllSprites instead of updateStage. If your progress
              meter has a function named (for example)

              on progressMove me
              --update the progress meter
              end


              then you can put this into your repeat loop

              repeat with i=1 to 10000
              --do something
              sendAllSprites(#progressMove)
              end repeat

              and it will update the progress meter after each record.
              • 4. Re: Problem with repeat loop
                TimDixon Level 1
                Hi Mike,

                I had a play with this too - I can see it is passing the event through (using a simple 'put' command), but its still not updating the screen.

                I get the impression that its all the action that's displayed that freezes. eg. I have an OSControl xtra which is a progress bar - I can set the value of it, but it doesn't update until the repeat loop is complete!! - The same goes for my flash progress bar..... infact any animation on the screen freezes!!

                The only way around it is using 'updatStage' ...a quick test this morning shows that this increases the time from 3secs to 32secs!!

                I've even tried opening the progress bar in a MIAW - but guess what, the animation in there freezes too!!

                Any other ideas much appreciated - but I'm starting to think its a limitation of Director's single threading!


                Cheers,


                Tim.
                • 5. Re: Problem with repeat loop
                  Level 7
                  TimDixon wrote:
                  > I've tried using the updatestage idea, but it increases the time to
                  > complete the repeat loop loads!! 3secs becomes more like 10 - 15
                  > secs!!
                  >
                  > Any other ideas?

                  Don't do the updateStage so often:-

                  > repeat with i=1 to 10000
                  > --do something with your database
                  if (i mod 100)=0 then updateStage()
                  > end repeat

                  Andrew


                  • 6. Re: Problem with repeat loop
                    Level 7
                    Try Andrew's method. Then it will not send an updateStage() on every
                    iteration, instead it will only send one per 100. Change that number to
                    make it happen more or less often as you wish.