<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: setTimeout, setInterval, or onEnterFrame?</title>
	<link>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm</link>
	<description>Just Blog</description>
	<pubDate>Thu, 09 Sep 2010 11:28:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-1793</link>
		<pubDate>Wed, 25 Apr 2007 00:45:41 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-1793</guid>
					<description>Testing the theory.. 

//
//	FRAME / INTERVAL
//

fTime = getTimer()
iTime = getTimer();
var frame = 0;

var id = setInterval ( this, 'onInterval', 0 );
function onInterval () {
	var now = getTimer();
	var change = now - iTime;
	iTime = now;
	trace( 'onInterval: \tf: ' + ( frame ) + '\tc: ' + change );
}

this.onEnterFrame = onFrame;
function onFrame()
{
	var now = getTimer();
	var change = now - fTime;
	fTime = now
	trace( '\nonFrame: \tf: ' + ( frame++ ) + '\tc: ' + change + newline);
}


onFrame: 	f: 93	c: 88

onInterval: 	f: 94	c: 8
onInterval: 	f: 94	c: 8
onInterval: 	f: 94	c: 8
onInterval: 	f: 94	c: 8
onInterval: 	f: 94	c: 8
onInterval: 	f: 94	c: 8
onInterval: 	f: 94	c: 8
onInterval: 	f: 94	c: 8
onInterval: 	f: 94	c: 26

onFrame: 	f: 94	c: 90

onInterval: 	f: 95	c: 73
onInterval: 	f: 95	c: 5
onInterval: 	f: 95	c: 8

onFrame: 	f: 95	c: 86

onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8
onInterval: 	f: 96	c: 8</description>
		<content:encoded><![CDATA[<p>Testing the theory.. </p>
<p>//<br />
//	FRAME / INTERVAL<br />
//</p>
<p>fTime = getTimer()<br />
iTime = getTimer();<br />
var frame = 0;</p>
<p>var id = setInterval ( this, &#8216;onInterval&#8217;, 0 );<br />
function onInterval () {<br />
	var now = getTimer();<br />
	var change = now - iTime;<br />
	iTime = now;<br />
	trace( &#8216;onInterval: \tf: &#8216; + ( frame ) + &#8216;\tc: &#8216; + change );<br />
}</p>
<p>this.onEnterFrame = onFrame;<br />
function onFrame()<br />
{<br />
	var now = getTimer();<br />
	var change = now - fTime;<br />
	fTime = now<br />
	trace( &#8216;\nonFrame: \tf: &#8216; + ( frame++ ) + &#8216;\tc: &#8216; + change + newline);<br />
}</p>
<p>onFrame: 	f: 93	c: 88</p>
<p>onInterval: 	f: 94	c: 8<br />
onInterval: 	f: 94	c: 8<br />
onInterval: 	f: 94	c: 8<br />
onInterval: 	f: 94	c: 8<br />
onInterval: 	f: 94	c: 8<br />
onInterval: 	f: 94	c: 8<br />
onInterval: 	f: 94	c: 8<br />
onInterval: 	f: 94	c: 8<br />
onInterval: 	f: 94	c: 26</p>
<p>onFrame: 	f: 94	c: 90</p>
<p>onInterval: 	f: 95	c: 73<br />
onInterval: 	f: 95	c: 5<br />
onInterval: 	f: 95	c: 8</p>
<p>onFrame: 	f: 95	c: 86</p>
<p>onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8<br />
onInterval: 	f: 96	c: 8
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-1792</link>
		<pubDate>Wed, 25 Apr 2007 00:16:54 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-1792</guid>
					<description>function clearAllIntervals ( )
{
	// create new interval
	var id = setInterval ( this, 'blank', 0 );
	while ( id != 0 ){
		// count through all interval and clear them one by one
		clearInterval ( id )
		id--
	}
}
clearAllIntervals ( );</description>
		<content:encoded><![CDATA[<p>function clearAllIntervals ( )<br />
{<br />
	// create new interval<br />
	var id = setInterval ( this, &#8216;blank&#8217;, 0 );<br />
	while ( id != 0 ){<br />
		// count through all interval and clear them one by one<br />
		clearInterval ( id )<br />
		id&#8211;<br />
	}<br />
}<br />
clearAllIntervals ( );
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-684</link>
		<pubDate>Sat, 03 Mar 2007 01:05:42 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-684</guid>
					<description>comment &gt;&gt;

You can prevent the compiler from showing errors by adding the following line:

intrinsic function setTimeout():Number;

to your toplevel.as file, located in
“documents and settings\\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Classes” folder.

Conversely, for MTASC, you can add the following line:

static function setTimeout():Number;

to the TopLevel.as, located in MTASC’s “std” folder.</description>
		<content:encoded><![CDATA[<p>comment >></p>
<p>You can prevent the compiler from showing errors by adding the following line:</p>
<p>intrinsic function setTimeout():Number;</p>
<p>to your toplevel.as file, located in<br />
“documents and settings\\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Classes” folder.</p>
<p>Conversely, for MTASC, you can add the following line:</p>
<p>static function setTimeout():Number;</p>
<p>to the TopLevel.as, located in MTASC’s “std” folder.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-42</link>
		<pubDate>Thu, 07 Dec 2006 04:09:25 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-42</guid>
					<description>Check back:
http://stimpson.flashvacuum.net/mt/archives/2006/08/as_30_framedela.html</description>
		<content:encoded><![CDATA[<p>Check back:<br />
<a href="http://stimpson.flashvacuum.net/mt/archives/2006/08/as_30_framedela.html" rel="nofollow">http://stimpson.flashvacuum.net/mt/archives/2006/08/as_30_framedela.html</a>
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Michael</title>
		<link>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-27</link>
		<pubDate>Sun, 03 Dec 2006 05:00:54 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/settimeout-setinterval-or-onenterframe.htm#comment-27</guid>
					<description>One important thing to note is that timers always work to execute as close to their target interval as possible.  Even though a timer can be off, it is still working to be close.  Dealing with frame events on the other hand is a different story.  

The decision to draw data to the screen is made on an application wide level, careful consideration is taken by the developers to ensure that drawing their data doesn't intrude on the end user in any way.  Therefore events tied to drawing the screen are inherently subject to the same considerations.   This means that your frame event reliant code is optimized such that if it were to break, the end users compuer is not affected, and by 'not affected' I mean there is usually some kind of graceful degradation.

I unfortunately have limited resources in knowing the exact inner workings of the Flash Player, so all information is based on my understanding of virtual machines in general.  

With that said, there is nothing to say that timers are not affected by the VM in the same way that frame events are.  However through what I have tested it does not seem so.  It seems that timers are executed on a more direct level than frame events. This means that a lack of consideration in this aspect can leave your application in ruins.  

The use of timers and updateAfterEvent() can lead to serious issues within your application.  If a timer is set to some unreasonably low value the operating system can only go so far as to accomodate the Flash Player.  This means that it's not likely that your actual interval will reflect your desired interval.  The reason this happens can be any of an infinite possibilities.  Most likely though, it is caused by your computer not being capable of processing all of its running applications.  The developer must remember that no matter how crafty they are, they're still bound by the same physical laws the rest of the universe is.  It will always become more difficult, the more data you have to process.

The reason that your flash application begins to run slowly has just as much to do with how it is designed as it does with how the computer it's running on executes it.  In short, use what the developers give you, don't try to force an application to do something it's already having a hard time doing.  This leaves the issue of timers and frame events up as a design consideration for you the developer.

Both intervals/timers and frame based events are completely acceptable solutions to any problem that has planned their use in an 'efficieny' aware manner.

Sorry, don't know what that was about... :) Great blog, keep up the good work.
Michael</description>
		<content:encoded><![CDATA[<p>One important thing to note is that timers always work to execute as close to their target interval as possible.  Even though a timer can be off, it is still working to be close.  Dealing with frame events on the other hand is a different story.  </p>
<p>The decision to draw data to the screen is made on an application wide level, careful consideration is taken by the developers to ensure that drawing their data doesn&#8217;t intrude on the end user in any way.  Therefore events tied to drawing the screen are inherently subject to the same considerations.   This means that your frame event reliant code is optimized such that if it were to break, the end users compuer is not affected, and by &#8216;not affected&#8217; I mean there is usually some kind of graceful degradation.</p>
<p>I unfortunately have limited resources in knowing the exact inner workings of the Flash Player, so all information is based on my understanding of virtual machines in general.  </p>
<p>With that said, there is nothing to say that timers are not affected by the VM in the same way that frame events are.  However through what I have tested it does not seem so.  It seems that timers are executed on a more direct level than frame events. This means that a lack of consideration in this aspect can leave your application in ruins.  </p>
<p>The use of timers and updateAfterEvent() can lead to serious issues within your application.  If a timer is set to some unreasonably low value the operating system can only go so far as to accomodate the Flash Player.  This means that it&#8217;s not likely that your actual interval will reflect your desired interval.  The reason this happens can be any of an infinite possibilities.  Most likely though, it is caused by your computer not being capable of processing all of its running applications.  The developer must remember that no matter how crafty they are, they&#8217;re still bound by the same physical laws the rest of the universe is.  It will always become more difficult, the more data you have to process.</p>
<p>The reason that your flash application begins to run slowly has just as much to do with how it is designed as it does with how the computer it&#8217;s running on executes it.  In short, use what the developers give you, don&#8217;t try to force an application to do something it&#8217;s already having a hard time doing.  This leaves the issue of timers and frame events up as a design consideration for you the developer.</p>
<p>Both intervals/timers and frame based events are completely acceptable solutions to any problem that has planned their use in an &#8216;efficieny&#8217; aware manner.</p>
<p>Sorry, don&#8217;t know what that was about&#8230; <img src='http://www.justgooddesign.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Great blog, keep up the good work.<br />
Michael
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
