10 Replies Latest reply on Jun 6, 2009 4:28 AM by Francisc

    Busy Cursor

    Francisc Level 3

      Hello!

       

      I have a FOR loop from 1 to 10000. How can I make the Busy Cursor appear before it starts and remove it after it ends?

      CursorManager.setBusyCursor() - before and CursorManager.removeBusyCursor() - after, doesn't do it.

      I was hoping the operations were synchronous.

       

      How can I do it? Thanks!

        • 1. Re: Busy Cursor
          Gaurav J Adobe Employee

          try breaking it into two functions, so flash player gete a chance to upate the display list. Someting like:

           

                      protected function clickHandler(event:MouseEvent):void
                      {
                          cursorManager.setBusyCursor();
                          setTimeout(runLoop, 10);
                      }
                     
                      private function runLoop():void
                      {
                          for(var ix:int =0; ix < 1000; ix ++)
                          {
                              trace(ix);
                          }
                          cursorManager.removeBusyCursor();
                      }

           

          Thanks,

          Gaurav Jain

          Flex SDK Team

          1 person found this helpful
          • 2. Re: Busy Cursor
            Francisc Level 3

            Thank you for the reply.

             

            My current code is something like this:

             

            CursorManager.setBusyCursor();

            for(var i:int=1;i<=10000;i++)

            {

                 do something

            }

            CursorManager.removeBusyCursor();

             

            But that doesn't work. If I comment the remove function the busy cursor will, of course, appear.

            I'm thinking AS parser skips the For loop to parte code after it and runs the loop in the mean time?

            • 3. Re: Busy Cursor
              Gaurav J Adobe Employee

              Flash player is single threaded, so when you call a function which is supposed to change the display list, the request is queued. And when the player gets the chance to render it, the display is updated.

               

              In your case the two requests are queued one after the another (because they are in the same function) - setBusyCursor followed by removeBusyCursor, so you don;t see the busy cursor.

               

              if you follow the sample code from my previous post, you should start seeing the busy cursor.

               

              Thanks,

              Gaurav

              • 4. Re: Busy Cursor
                Francisc Level 3

                Hmm, I understand now.

                Problem is that the Cursor will be kept so for only 10 milliseconds? Or am I misunderstanding what you wrote?

                 

                Thank you, Gaurav!

                • 5. Re: Busy Cursor
                  Gaurav J Adobe Employee

                  Yes, you are right. The duration will be too small.

                  • 6. Re: Busy Cursor
                    Francisc Level 3

                    Would there be a way to do this other than that? So that the busyCursor is removed immediatly after the for look ends?

                    • 7. Re: Busy Cursor
                      RWinscot

                      Flip the sample around a bit... and you are guaranteed at least one frame of busy cursor.

                       

                       

                                  private function doStuff():void
                                  {
                                      CursorManager.setBusyCursor();
                                     
                                      for ( var i:int = 0; i < 10000; i++ )
                                      {
                                          // zzzzz....
                                      }
                                     
                                      callLater( hideBusyCursor );
                                  }

                       

                                  private function hideBusyCursor():void
                                  {
                                      CursorManager.removeBusyCursor();
                                  }

                       

                      If you don't mind my asking... what are you trying to do? There might be an 'ideal' way to approach this if we knew the context in which you are trying to implement this behavior.

                      • 8. Re: Busy Cursor
                        Francisc Level 3

                        How much later does the callLater function execute?

                         

                        I am Building a Linechart that gets data from a lot of math equasions that must be run 10000 times = the number of points for the linechart.

                        What I am trying to do is show the busy cursor when the for begins and hide it after the chart appears - it only does so after the for ends.

                         

                        Thank you!

                        • 9. Re: Busy Cursor
                          RWinscot Level 1

                          At a minimum - you are looking at around 10ms. The maximum may last as long as several seconds if you don't actively invalidate the display list. From your description - it sounds like this should do the trick.

                          • 10. Re: Busy Cursor
                            Francisc Level 3

                            I will try that and let you know how it turned out. :)

                             

                            I was thinking of setting the Cursor to Busy, then when the Chat window opened (chart is in a window and it opens after the for) sent an event to the parent which is handeled by removing the cursor. Hm?