setInterval's use up next to nothing on processor, even if you have 20 of
them going. I find that the best judgement of which to use is the task at
hand.

Because framerate is for animation, I find it best to use onEnterFrame when
doing coded animation. Flash will cause an automatic screen redraw each
frame and because the onEnterFrame executes precisely before this redraw
it's the perfect chance to make display changes and scripted tweens. To keep
processor to a minimum it is good to use only one onEnterFrame because many
of them will make a processor difference. The way to do this is set up an
"enterFrameBroadcaster" ... basically have one onEnterFrame running and
dispatching an "enterFrame" event each cycle. Then many objects can listen.
This was first used by Robert Penner I believe and is built in to the
Macromedia tween classes. I also have a version if you can't find one
suitable.

To have a smooth animation using setInterval you must call
updateAfterEvent() in the interval, forcing a redraw. Each additional screen
redraw you make is additional processor - the framerate redraw will happen
regardless. The best time to use setInterval is when you want to achieve a
specific interval of time. For example, when the user clicks a scrollbar
arrow it shouldn't move faster and slower based on the framerate a designer
sets the movie at. It will always depends on your context and the behavior
you want.

Tyler



On 5/24/06, Adam Pasztory <[EMAIL PROTECTED]> wrote:

I've found anecdotally the onEnterFrames are less CPU intensive than a
setInterval running at a similar rate.

The cons of setInterval are worth noting, but if you're using a good OOP
code design, and you're strict about tracking your interval IDs, then you
don't have to be too afraid of setInterval.  I usually define a single
member variable in a class to track a particular interval.  Any time I
want
to call set interval, I first make sure the interval is cleared.

...
if(this.intervalId)
   clearInterval(this.intervalId);
this.intervalId = setInterval(this, "someMethod", time);

Seems to work pretty well.

There is also a gotcha related to onEnterFrame that's worth mentioning: A
MovieClip can only have a single onEnterFrame handler, so when you assign
an
event handler to some MovieClip you'd better make sure it doesn't already
have a  different onEnterFrame already assigned to it.  I've run into this
kind of thing when working with animations from artists who like to put a
lot of Actionscript functionality into their MovieClips.

-Adam

On 5/24/06, Rifled Cloaca <[EMAIL PROTECTED]> wrote:
>
> Flashcoders,
>
> I'm building a modular system that contains various programmatic
> animations
> within seperate modules, coordinated by a central wrapper class.  I've
> opted
> to use empty movieclips with onEnterFrame functions to manage timing in
> animations and presentation playback, as opposed to setInterval.  Reason
> being is that I don't want to have to worry about scoping my intervals,
> and
> most of all, losing track of intervals and eventually having them stack
> up,
> interfere with eachother, and cause memory leaks.
>
> Question is, isn't it more processor intensive to use a series of
> onEnterFrames like this?  Can anyone think of any other cons to the
method
> I've chosen?
>
> Thanks in advance!
> -g
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to