6 Replies Latest reply on Aug 31, 2010 7:37 AM by InfoRoute

    setBusyCursor(): Cursor doesn't change

    flashgruven Level 1
      I have a click event handler that invokes setBusyCursor() on the CursorManager and then goes into a compute intensive section of code parsing XML and populating a DataGrid. This process takes between 2 and 7 seconds, yet the cursor stays with the hand cursor instead of the busy cursor.

      The last step in the event handler is to remove the Busy Cursor, however it was never displayed.

      Is there someway to get the Busy Cursor to display so users will know to chill?

      TIA,
      G
        • 1. Re: setBusyCursor(): Cursor doesn't change
          peterent Level 2
          The problem is that once you set the busy cursor you never give the Flex framework a chance to display it - you go right into a 'compute intensive section'. Approach it like this:

          private function doWork() : void
          {
          // do your compute intensive stuff here
          // remove the busy cursor
          }

          private function startWork() : void
          {
          // set the busyCursor
          callLater( doWork );
          }

          The callLater will enable the Flex framework to satisfy the request for the cursor change and then it will invoke your function to do the actual work. Once that's done you can remove the busy cursor.
          • 2. Re: setBusyCursor(): Cursor doesn't change
            flashgruven Level 1
            Thanks Peter! That looked like it was just the ticket however, no joy.

            Here is the scenario...

            I have a LinkBar hooked up to a ViewStack which contains 3 VBoxes. The VBoxes need to display between 300 and 700 line DataGrids from XML (4 levels of hierarchy) which is parsed using E4X (3 nested for each in loops).

            When one of the links is pressed a clickHandler(ItemClickEvent) is called which sets the busy cursor and now uses callLater(dowork) as you prescribed.

            doWork() does the parsing of the XML and on completion, removes the busy Cursor.

            I still never see the busy Cursor
            • 3. Re: setBusyCursor(): Cursor doesn't change
              peterent Level 2
              So you do:

              CursorManager.setBusyCursor();
              callLater( myLongTask );
              ...
              function myLongTask() : void {
              ....
              CursorManager.removeBusyCursor();
              }

              ?? Ok, sometimes it takes a couple of callLaters to get it work right. It is tricky when you go right into hogging the CPU. Try this:

              // set busy cursor
              callLater( step1 );

              function step1() : void { callLater(step2); }
              function step2() : void { callLater(myLongTask); }

              If that doesn't work, look into breaking your long task into shorter pieces. Maybe remember where you were in a loop and intermediate values. Then do some of the work, save values, then use callLater to invoke the function again and again until all things are done.

              An alternative is to use the enterFrame event. This fires a lot, so you might want to count a dozen frames or so, then start your task and remove the enterFrame listener function.

              Since the Flash Player is single threaded you have to resort to this sometimes.
              • 4. Re: setBusyCursor(): Cursor doesn't change
                Mitek17 Level 1
                Do you have a matching pair of setBusyCursor/removeBusyCursor ?

                Cheers,
                Mitek.
                • 5. Re: setBusyCursor(): Cursor doesn't change
                  flashgruven Level 1
                  CallLater() never really seemed to help. I encapsulated all the calls that add visible components to a VBox into functions and then call the functions using CallLater(). The cursor remains a Hand and never tells the user they should be patient with a Busy cursor.

                  My next approach is going to be to make a WebService call instead of having the data (large XMLList) variable inside the swift file. I thought things would be faster if I didn't have to return to the server at the expense of updating manually, however maybe getting the data from the webserver will be just as fast and yield a Busy Cursor.

                  THanks,
                  George
                  • 6. Re: setBusyCursor(): Cursor doesn't change
                    InfoRoute

                    I know this is more of a hack, but you could use setTimeout with an anonymous function, like below:

                     

                        private function intensiveProcessing() : void {
                            CursorManager.setBusyCursor();
                            setTimeout(function() : void {
                                    try {

                                        // do some intensive work here
                                    }
                                    catch (err : Error) {
                                        throw err;
                                    }
                                    finally {
                                        CursorManager.removeBusyCursor();
                                    }
                                }
                                , 100);
                        }

                     

                    I actually tried this and it works.

                    The try/catch/finally are not required, I just want to make sure the "busy cursor" is removed. I used an anonymous function so I don't have to use two functions.

                     

                    Hope this helps.