Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : Script causing Flash Player to run slowly...


Christian Herbig
8/3/2006 8:12:03 PM
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.
abeall
8/3/2006 8:34:58 PM
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;
}
}
}
Christian Herbig
8/4/2006 10:49:42 PM
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?
kglad
8/4/2006 11:48:55 PM
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.
abeall
8/5/2006 6:30:52 PM
[quoted text, click to view]
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'
Christian Herbig
8/7/2006 8:39:51 PM
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?
kglad
8/8/2006 1:34:53 AM
Christian Herbig
8/9/2006 8:02:59 PM
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
kglad
8/9/2006 11:40:58 PM
AddThis Social Bookmark Button