RE: [Flashcoders] SetInterval vs. onEnterFrame

2006-05-24 Thread Tom Lee
Yes, it would be more processor and memory intensive to use empty movieclips
for sync.  The reason for this is that a movieclip is a special kind of
object that has a ton of its own built-in methods and properties, none of
which you need for timing purposes.

Managing the interval id's shouldn't be a problem - you should be able to
scope them to one object whose purpose is to keep track of them all.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Rifled
Cloaca
Sent: Wednesday, May 24, 2006 5:03 PM
To: Flashcoders mailing list
Subject: [Flashcoders] SetInterval vs. onEnterFrame

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


Re: [Flashcoders] SetInterval vs. onEnterFrame

2006-05-24 Thread Adam Pasztory

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


Re: [Flashcoders] SetInterval vs. onEnterFrame

2006-05-24 Thread Tyler Wright

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