I’m trying to clean up a project and I’ve found an onEnterFrame that is calling a function with a for loop in it. Seems like a bad idea for the movie’s performance. Am I crazy?
If the for loop is only doin about 10 loops or somtin, you should be alrite. But anymore then 50 and you would be crazy. 50 loops in 30fps movie thats 600loops a second, might get a little intense on the slugish computer.
it depends whats going on in that for loop. Generally, its not a problem unless your looping through 5345357475 different iterations every frame.
yeah i don’t know. its looping 19 times. its running through an array of mcs and assigning them new _x coordinates. i don’t trust it. that’s alot of calculations for a 30fps movie.
If it’s not necessary then it’s definitely not a good idea but Flash can handle a few hundred loops per frame at least (depending on many factors). Most performance issues experienced will have to do with Flash rendering vector graphics. Take for example the attached file, it has 2500 loops per frame (with about 13000 lines of code executing) and it runs fairly well - but turn the quality up and your computer might explode
Well I was beat by a little while but 19 iterations will definitely not be a problem :thumb:
Wow, that was ultra slow on high quality. Was even slow opening the rite click menu…
Just moving _x positions shouldn’t be too bad i reckon. But i would stay well away from any _alpha adjustments.
So what’s a good alternative for onEnterFrame ?
For instance, how could I check the _x of a mc constantly other than with onEnterFrame ? (setInterval perhaps ?)
Oh, talking about an infinite loop here.
An onEnterFrame would be sufficent to just check the _x of an mc.
its not about finding an alternative to onEnterFrame. onEnterFrame has a purpose - to run code every frame. Thats what it does and you use it to do that. There’s no real alternative to it because it is what it is.
its more about making sure you do things only when you need to do them. Do you need to loop through all these things every frame? Or do you need to just loop through them when the user clicks their mouse (or whatever)? its more about the logic behind running your code only when its necessary to run your code and trying to effecicently program your movie so that you are not running into bottlenecks or doing more than that which is necessary at any given time.