6 Replies Latest reply on Apr 29, 2009 10:23 AM by marcinelli

    force update during processor intensive routine

    marcinelli

      hello all,
      i have a swf with several processor intensive subroutines within a main init() routine at start up (about a 5 secs startup wait).  it needs a preloader not due to asset loads but to the processor intensive routines.

      i'm trying to create a preloader that will display progress as the routines complete but when i try to write text to text field as each subroutine completes either the textField.text is not updated or the text field display is not updated after each subroutine finishes.  this prevents me from tracking the progress of the start up.

      is there a way to force an update to the display list in the middle of a processor intensive routine?  i believe flash is supposed to update after each frame but i'm not seeing this.

      also, the text field i'm displaying *before* this processor intensive routine *does* display when running locally but *does not* display before the routine when running online.  not sure why.

      thx in advance,
      michael

        • 1. Re: force update during processor intensive routine
          Rothrock Level 5

          The easy answer is, "No." The harder answer is maybe....

           

          All the code in a given frame will need to execute before that frame can be rendered and there is no way around that. So if your init() function is doing a lot of math and loops and stuff and such you will just have to wait until the whole init() function is executed before the frame will be finished.

           

          But if the calculations can be broken down into steps then you can figure out what is a reasonable sized step, calculate it, update the "preloader," do the next step. Sometimes that process can make the whole thing take a bit longr, but 7 seconds of updated progress is much better than 5 seconds of apparent frozenness. (Is that a word?) At least to my way of thinking.

           

          I don't know what the issue is with the local vs. on-line issue, but chunking up the problem will probably fix that too.

           

          If you can share what you are doing perhaps there is a common solution?

          • 2. Re: force update during processor intensive routine
            marcinelli Level 1

            thx rothrock,

            what i'm doing is a lot of vector graphics creation.  i'm trying to avoid loading bitmaps so nearly everything on screen is a vector graphic or text field.

             

            the thing i don't understand with your chunking solution is, if everything has to ultimately execute at startup, how do i stop and update the preloader in the middle of the subroutines if the entire startup routine has to execute.  what's the action to stop/update but then continue after the update?

             

            this is all in code.  nothing in frames in the timeline.

            • 3. Re: force update during processor intensive routine
              Rothrock Level 5

              The usual way is to use a Timer or a setInterval. So if you know that you need to create 1,000 vector shapes and you know that it takes 10 second to do all of them. So instead of trying to do them all in one function you would set a Timer that called a function every little bit -- something like 50 milliseconds or so.

               

              Then you would make a list of the shapes you needed to create, start a timer that called a function every 50 milliseconds, each time the timer calls the function it will make (just to be on the safe side) 4 of the vectors, crosses them off the list of those that need to be created, then the function would be done, the frame would render, any preloader could render, and so on. It would repeat until the list of vectors that need to be created was empty.

               

              You would probably want a custom class that handled this and dispatched some kind of progress and complete events.

               

              However I'm not sure why you are taking this approach. You can create all the clips inside the Flash IDE and then export them for actionscript. Then it is just a mater of loading them and the preloaders for that are generally simpler that what you are doing.

               

              There are also probably tricks to making things appear to be created and load more quickly.

              • 4. Re: force update during processor intensive routine
                marcinelli Level 1

                thx a lot rothrock.  breaking it up with setTimer() did the trick.  updates are now happening between subroutines.  that's a big help!

                 

                but i'm curious about your other solution.  i understand creating the vectors in the IDE and exporting to actionscript but won't i still have the same loading issue after exporting them to actionscript?  are you referring to not using the actionscript exports in an .as file like i'm doing but creating some sort of component out of each vector that live in the library and letting the IDE preload rather than doing it in code?

                • 5. Re: force update during processor intensive routine
                  Rothrock Level 5

                  Yeah.

                  When you create a MovieClip in the Library you can select to have it Export for Actionscript and then give it a name and/or class. Exactly how this all works depends upon if you are using AS2 or AS3. Then you either use attachMovie or the new ClassName() constructor to create instances of the item as you need them.

                   

                  It all depends upon how tricky the shapes are and how big they are, but you might have good tradeoffs.

                  • 6. Re: force update during processor intensive routine
                    marcinelli Level 1

                    thx rothrock.  i've only been doing that with bitmap imports.  didn't think to do that with the vectors i create internally.  great idea.  thx a lot for your time/help.  helps a lot.

                     

                    michael