<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.4" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: AS2 Timer class</title>
	<link>http://www.jamesor.com/2006/10/18/as2-timer-class/</link>
	<description>Flash Guru</description>
	<pubDate>Thu, 21 Aug 2008 19:52:57 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4</generator>

	<item>
		<title>by: Antti Kupila</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-8517</link>
		<pubDate>Sat, 14 Apr 2007 22:20:55 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-8517</guid>
					<description>About the accurate timing: I had the very same problem in a project i did some time ago. Accurency was far off, especially when i had multiple separate intervals on at the same time. Since this was a local kiosk style application I was able to use other stuff than flash and ended up learning C# and doing in it with a flash interface :) Was friggin impossible to get flash to work fast enough (didn't try as3 though)
Joshua: I also tried your approach, but had the same problems there with flash, execution was off by several milliseconds, which was clearly noticable. Anyway, that's the method i used in C# and it worked perfect</description>
		<content:encoded><![CDATA[<p>About the accurate timing: I had the very same problem in a project i did some time ago. Accurency was far off, especially when i had multiple separate intervals on at the same time. Since this was a local kiosk style application I was able to use other stuff than flash and ended up learning C# and doing in it with a flash interface <img src='http://www.jamesor.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Was friggin impossible to get flash to work fast enough (didn&#8217;t try as3 though)<br />
Joshua: I also tried your approach, but had the same problems there with flash, execution was off by several milliseconds, which was clearly noticable. Anyway, that&#8217;s the method i used in C# and it worked perfect
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Joshua Mostafa</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7752</link>
		<pubDate>Tue, 20 Mar 2007 21:40:08 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7752</guid>
					<description>Why not use the total milliseconds elapsed (ignoring any time stopped) to calculate when next to stop, rather than simply within the current repetition? Then the number of repetitions would no longer have a negative affect on accuracy. You would not have 100% accurate time - without running the player at an impossible speed (i.e. 1000 FPS, or 1 frame per millisecond) - but you would get a lot closer.</description>
		<content:encoded><![CDATA[<p>Why not use the total milliseconds elapsed (ignoring any time stopped) to calculate when next to stop, rather than simply within the current repetition? Then the number of repetitions would no longer have a negative affect on accuracy. You would not have 100% accurate time - without running the player at an impossible speed (i.e. 1000 FPS, or 1 frame per millisecond) - but you would get a lot closer.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bob Stoute</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7276</link>
		<pubDate>Sat, 10 Mar 2007 00:47:09 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7276</guid>
					<description>So I guess that means there's no way to get absolute timing with AS2. What's the situation with AS3? Does that provide accurate timing?</description>
		<content:encoded><![CDATA[<p>So I guess that means there&#8217;s no way to get absolute timing with AS2. What&#8217;s the situation with AS3? Does that provide accurate timing?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: James O'Reilly</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7170</link>
		<pubDate>Thu, 08 Mar 2007 16:00:03 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7170</guid>
					<description>Matt, please send me some code that you were using to show myTimer.stop() not working.  The Timer class does  not inherit from MovieClip so the word stop as a function name should not be a problem.</description>
		<content:encoded><![CDATA[<p>Matt, please send me some code that you were using to show myTimer.stop() not working.  The Timer class does  not inherit from MovieClip so the word stop as a function name should not be a problem.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: James O'Reilly</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7169</link>
		<pubDate>Thu, 08 Mar 2007 15:58:22 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7169</guid>
					<description>Bob, the problem is setInterval and since the Timer class is a wrapper class for setInterval it inherits its problems.  Intervals less than 300 ms or so become unreliable.

Try adjusting the framerate of your movie up or down.  I found that 60 FPS yielded 0% increase with 10ms x 1000.  But 12 FPS yielded 50% increase and 30 FPS yielded 10% increase.  

From the docs: "If interval is greater than the SWF file’s frame rate, the interval function is only called each time the playhead enters a frame; this minimizes the impact each time the screen is refreshed."  Also, "the interval function is called as close to interval as possible."</description>
		<content:encoded><![CDATA[<p>Bob, the problem is setInterval and since the Timer class is a wrapper class for setInterval it inherits its problems.  Intervals less than 300 ms or so become unreliable.</p>
<p>Try adjusting the framerate of your movie up or down.  I found that 60 FPS yielded 0% increase with 10ms x 1000.  But 12 FPS yielded 50% increase and 30 FPS yielded 10% increase.  </p>
<p>From the docs: &#8220;If interval is greater than the SWF file’s frame rate, the interval function is only called each time the playhead enters a frame; this minimizes the impact each time the screen is refreshed.&#8221;  Also, &#8220;the interval function is called as close to interval as possible.&#8221;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Matt</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7159</link>
		<pubDate>Thu, 08 Mar 2007 14:26:06 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7159</guid>
					<description>I had to rename the stop function to 'kill' to get this to work properly for me. Perhaps because stop is a reserved word?</description>
		<content:encoded><![CDATA[<p>I had to rename the stop function to &#8216;kill&#8217; to get this to work properly for me. Perhaps because stop is a reserved word?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bob Stoute</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7093</link>
		<pubDate>Thu, 08 Mar 2007 02:06:14 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-7093</guid>
					<description>I like your class very much, as it provides a very convenient way of scripting with time in AS2.
However, I found that it is not accurate, especially if the used intervals are set lower then 1000ms.
I've written a test script to reveal the inaccuracy.
These are the results:

---
interval = 1000  ::  repeat = 200
*  expected elapsed seconds = 200
*  real elapsed seconds = 210
*  difference = 5%
---
interval = 1000  ::  repeat = 100
*  expected elapsed seconds = 100
*  real elapsed seconds = 104
*  difference = 4%
---
interval = 50  ::  repeat = 200
*  expected elapsed seconds = 10
*  real elapsed seconds = 11
*  difference = 10%
---
interval = 25  ::  repeat = 400
*  expected elapsed seconds = 10
*  real elapsed seconds = 15
*  difference = 50%
---
interval = 10  ::  repeat = 1000
*  expected elapsed seconds = 10
*  real elapsed seconds = 17
*  difference = 70%
---

As you can see the results become dramatic as the milliseconds decrease. I really hope that you can find out how to make the class more accurate, as I intend to use it mainly for very short repeat loops.

Kind regards / Bob Stoute


ACTIONSCRIPT USED FOR TESTING =

import mx.utils.Delegate;
import com.jor.utils.Timer;
import com.jor.events.TimerEvent;
//
var start_time = int(getTimer() / 1000);
//
var interval = 500;
var repeat = 20;
//
var myTimer:Timer = new Timer(interval, repeat);
myTimer.addEventListener(TimerEvent.TIMER, Delegate.create(this, timerHandler));
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, Delegate.create(this, timerHandler));
myTimer.start();
//
function timerHandler(event:TimerEvent):Void {
	if (event.type == "timer") {
		t = myTimer.currentCount;
		g = (int(getTimer() / interval));
		info = "myTimer.currentCount = " + t + "  ::  expected currentCount = " + g + "  ::  difference = " + (g - t);
		trace(info);
	}
	if (event.type == "timerComplete") {
		var real_seconds = int(getTimer() / 1000) - start_time;
		var expected_seconds = (interval * repeat) / 1000;
		//
		trace("---");
		trace("interval = " + interval + "  ::  repeat = " + repeat);
		trace("*  expected elapsed seconds = " + expected_seconds);
		trace("*  real elapsed seconds = " + real_seconds);
		trace("*  difference = " + (real_seconds - expected_seconds) / (expected_seconds / 100) + "%");
		trace("---");
	}
}
stop();</description>
		<content:encoded><![CDATA[<p>I like your class very much, as it provides a very convenient way of scripting with time in AS2.<br />
However, I found that it is not accurate, especially if the used intervals are set lower then 1000ms.<br />
I&#8217;ve written a test script to reveal the inaccuracy.<br />
These are the results:</p>
<p>&#8212;<br />
interval = 1000  ::  repeat = 200<br />
*  expected elapsed seconds = 200<br />
*  real elapsed seconds = 210<br />
*  difference = 5%<br />
&#8212;<br />
interval = 1000  ::  repeat = 100<br />
*  expected elapsed seconds = 100<br />
*  real elapsed seconds = 104<br />
*  difference = 4%<br />
&#8212;<br />
interval = 50  ::  repeat = 200<br />
*  expected elapsed seconds = 10<br />
*  real elapsed seconds = 11<br />
*  difference = 10%<br />
&#8212;<br />
interval = 25  ::  repeat = 400<br />
*  expected elapsed seconds = 10<br />
*  real elapsed seconds = 15<br />
*  difference = 50%<br />
&#8212;<br />
interval = 10  ::  repeat = 1000<br />
*  expected elapsed seconds = 10<br />
*  real elapsed seconds = 17<br />
*  difference = 70%<br />
&#8212;</p>
<p>As you can see the results become dramatic as the milliseconds decrease. I really hope that you can find out how to make the class more accurate, as I intend to use it mainly for very short repeat loops.</p>
<p>Kind regards / Bob Stoute</p>
<p>ACTIONSCRIPT USED FOR TESTING =</p>
<p>import mx.utils.Delegate;<br />
import com.jor.utils.Timer;<br />
import com.jor.events.TimerEvent;<br />
//<br />
var start_time = int(getTimer() / 1000);<br />
//<br />
var interval = 500;<br />
var repeat = 20;<br />
//<br />
var myTimer:Timer = new Timer(interval, repeat);<br />
myTimer.addEventListener(TimerEvent.TIMER, Delegate.create(this, timerHandler));<br />
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, Delegate.create(this, timerHandler));<br />
myTimer.start();<br />
//<br />
function timerHandler(event:TimerEvent):Void {<br />
	if (event.type == &#8220;timer&#8221;) {<br />
		t = myTimer.currentCount;<br />
		g = (int(getTimer() / interval));<br />
		info = &#8220;myTimer.currentCount = &#8221; + t + &#8221;  ::  expected currentCount = &#8221; + g + &#8221;  ::  difference = &#8221; + (g - t);<br />
		trace(info);<br />
	}<br />
	if (event.type == &#8220;timerComplete&#8221;) {<br />
		var real_seconds = int(getTimer() / 1000) - start_time;<br />
		var expected_seconds = (interval * repeat) / 1000;<br />
		//<br />
		trace(&#8221;&#8212;&#8221;);<br />
		trace(&#8221;interval = &#8221; + interval + &#8221;  ::  repeat = &#8221; + repeat);<br />
		trace(&#8221;*  expected elapsed seconds = &#8221; + expected_seconds);<br />
		trace(&#8221;*  real elapsed seconds = &#8221; + real_seconds);<br />
		trace(&#8221;*  difference = &#8221; + (real_seconds - expected_seconds) / (expected_seconds / 100) + &#8220;%&#8221;);<br />
		trace(&#8221;&#8212;&#8221;);<br />
	}<br />
}<br />
stop();
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Actionscript Classes &#187; Timer/Timer Events</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-690</link>
		<pubDate>Thu, 19 Oct 2006 02:38:57 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-690</guid>
					<description>[...] http://www.jamesor.com/2006/10/18/as2-timer-class/  [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] <a href='http://www.jamesor.com/2006/10/18/as2-timer-class/' rel='nofollow'>http://www.jamesor.com/2006/10/18/as2-timer-class/</a>  [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: JesterXL</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-688</link>
		<pubDate>Thu, 19 Oct 2006 00:45:48 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-688</guid>
					<description>Dammit... naw, I use that same exact link too, but your divs are just better.  :: scours view source ::</description>
		<content:encoded><![CDATA[<p>Dammit&#8230; naw, I use that same exact link too, but your divs are just better.  :: scours view source ::
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: James O'Reilly</title>
		<link>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-682</link>
		<pubDate>Wed, 18 Oct 2006 20:39:52 +0000</pubDate>
		<guid>http://www.jamesor.com/2006/10/18/as2-timer-class/#comment-682</guid>
					<description>Thanks Jesse, and very interesting suggestion.  I've never initialized the EventDispatcher that way before but it sounds like a good way to do it.  I've included it in my code above.

I use the site http://www.shockwave-india.com/blog/services/as-highlight2/index.php to format the text and redefined the style classes it creates to colors I prefer.  You can probably check my source for the color codes I changed them to.  If not, I can email them to you.</description>
		<content:encoded><![CDATA[<p>Thanks Jesse, and very interesting suggestion.  I&#8217;ve never initialized the EventDispatcher that way before but it sounds like a good way to do it.  I&#8217;ve included it in my code above.</p>
<p>I use the site <a href='http://www.shockwave-india.com/blog/services/as-highlight2/index.php' rel='nofollow'>http://www.shockwave-india.com/blog/services/as-highlight2/index.php</a> to format the text and redefined the style classes it creates to colors I prefer.  You can probably check my source for the color codes I changed them to.  If not, I can email them to you.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
