8 Replies Latest reply on Aug 9, 2006 4:40 PM by kglad

    Script causing Flash Player to run slowly...

    Christian_Herbig
      I am making an applet for a college level chemical engineering course, everything runs fine except for one annoying problem:
      I have a mathematically involved script that runs just fine, except that every thousand itterations or so, Flash Player 8 interrupts execution and says that the script is causing flash player to run slowly (abort script or continue). If you continue, the program runs just fine until it is finished, but the interuption is not a very nice thing to subject the user to. Potentially, this script must execute 36000 itterations. Is there a way to suppress this message box, or does anyone have any ideas on how to break up a script so that it gives flash player time to recuperate between successive executions.

      I realize this is a bit vague, but if anyone has any ideas at all, or knows a better place to send this help request, please help.
        • 1. Re: Script causing Flash Player to run slowly...
          abeall Level 3
          There's no way to supress the message, and you probably wouldn't want to because the only that would do is not inform the user why the player has frozen.

          Without seeing the formula, you can most likely split it up by performing a certain number of iteration per frame inside an onEnterFrame event. In this way, you are trying to force Flash to perform the heavy math all at once. Example:

          for(var i = 0 ; i<=100000 ; i++){
          //stuff
          }
          //done

          vs.

          var i = 0;
          onEnterFrame = function(){
          for(var n=0 ; n<100 ; n++){
          if(++i>100000){
          //done
          break;
          }
          }
          }
          • 2. Re: Script causing Flash Player to run slowly...
            Christian_Herbig Level 1
            I don't understand why I would use onEnterFrame(). The entire program only needs one frame to exist on, but maybe I don't understand how Flash needs to manage these things. I am a C++/Cocoa programmer rewriting a program that my boss made years ago in Visual BASIC. What made it work for him was to call DoEvents every 600 itterations, which pauses the execution so that the system can catch up with it's own stuff. Are you saying that onEnterFrame will do this too? How will this work if the calculation only starts when a button is pressed. Does the entire calculation routine need to take place on a different frame?

            Could you explain these things?
            • 3. Re: Script causing Flash Player to run slowly...
              kglad Adobe Community Professional & MVP
              you need to use something to break your loop in parts that execute before triggering the flash warning. you can do that with an onEnterFrame handler, a setInterval() loop or a frame loop.

              if you convert your 36000 iterations into 36 loops of 1000 iterations (and 1000 iterations do not trigger a warning), then your 36 loops of 1000 iterations each will trigger no warning.
              • 4. Re: Script causing Flash Player to run slowly...
                abeall Level 3
                > I don't understand why I would use onEnterFrame(). The entire program only
                > needs one frame to exist on, but maybe I don't understand how Flash needs to
                > manage these things.
                onEnterFrame is a confusing name, it really has nothing to do with "entering a frame" in a physicial sense. It simply means it will execute the event at the framerate, regardless of timeline playback. It might make more sense to think of as 'onEveryFrame' or even 'onFrameRate'
                • 5. Re: Script causing Flash Player to run slowly...
                  Christian_Herbig Level 1
                  I made an onEnterFrame routine, and it seems to be working just fine for smaller simulations, but I am wondering, if the calculation routine (for larger simutations) takes up more time than the framerate allows, will Flash execute a second thread for this function (and consequently mess up the results)? What I mean is that if the framrate is set at 24 fps, and a routine takes 1 second, will flash try to execute the calculation routine 24 times and make 24 extra threads run?
                  • 6. Re: Script causing Flash Player to run slowly...
                    kglad Adobe Community Professional & MVP
                    no, if the calculation (or anything else) is time-consuming beyond the capacity of the frame rate to be maintained, flash drops the frame rate. that's why some flash animations lag.
                    • 7. Re: Script causing Flash Player to run slowly...
                      Christian_Herbig Level 1
                      Thanks for your help guys, this seems to make the code stable and the player runs it without problem now. If this had not worked, I don't know what I would have done.

                      Once, again, thanks for taking time to help me with this.

                      Christian