<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: AS2.0 Event based Timer class.</title>
	<atom:link href="http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/</link>
	<description>in the kingdom of the blind... stay off the highway!</description>
	<lastBuildDate>Wed, 16 Sep 2009 17:40:40 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jason Milkins</title>
		<link>http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/comment-page-1/#comment-48</link>
		<dc:creator>Jason Milkins</dc:creator>
		<pubDate>Fri, 28 Apr 2006 09:28:58 +0000</pubDate>
		<guid isPermaLink="false">http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/#comment-48</guid>
		<description>&lt;code&gt;go()&lt;/code&gt; already handles this using the &lt;code&gt;running&lt;/code&gt; flag.

Look more closely at these methods..

&lt;pre name=&quot;code&quot; class=&quot;js&quot;&gt;
// --- &gt;8 snip
	public function go() : Void {
		if(!running) {
			running = true;
			setTimeout();
		} else {
			restart();
		}
	}
	
	private function setTimeout () : Void {
		timerInterval = setInterval (Delegate.create(this, timeoutComplete), duration);
	}

	public function restart (newDuration : Number) : Void {
		if(newDuration != undefined) {
			duration = newDuration;
		}
		dispose();
		go();
	}
// --- &gt;8 snip
&lt;/pre&gt;

&lt;code&gt;go()&lt;/code&gt; doesn&#039;t run &lt;code&gt;setTimeout()&lt;/code&gt; unconditionally, also &lt;code&gt;setTimeout&lt;/code&gt; is a private method. The public methods are the constructor, &lt;code&gt;go()&lt;/code&gt;, &lt;code&gt;restart()&lt;/code&gt; and &lt;code&gt;dispose()&lt;/code&gt; (and it&#039;s aliases, crush, kill, destroy ;-) )

I hope this addresses your potential bug, if I&#039;m on the wrong track, could you explain the circumstances under which the bug could arise. Cheers.</description>
		<content:encoded><![CDATA[<p><code>go()</code> already handles this using the <code>running</code> flag.</p>
<p>Look more closely at these methods..</p>
<pre name="code" class="js">
// --- >8 snip
	public function go() : Void {
		if(!running) {
			running = true;
			setTimeout();
		} else {
			restart();
		}
	}

	private function setTimeout () : Void {
		timerInterval = setInterval (Delegate.create(this, timeoutComplete), duration);
	}

	public function restart (newDuration : Number) : Void {
		if(newDuration != undefined) {
			duration = newDuration;
		}
		dispose();
		go();
	}
// --- >8 snip
</pre>
<p><code>go()</code> doesn&#8217;t run <code>setTimeout()</code> unconditionally, also <code>setTimeout</code> is a private method. The public methods are the constructor, <code>go()</code>, <code>restart()</code> and <code>dispose()</code> (and it&#8217;s aliases, crush, kill, destroy ;-) )</p>
<p>I hope this addresses your potential bug, if I&#8217;m on the wrong track, could you explain the circumstances under which the bug could arise. Cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ketan</title>
		<link>http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/comment-page-1/#comment-47</link>
		<dc:creator>ketan</dc:creator>
		<pubDate>Fri, 28 Apr 2006 00:35:22 +0000</pubDate>
		<guid isPermaLink="false">http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/#comment-47</guid>
		<description>Potential bug if somethings calls Timeout.go() before the timer is has run out.
Simple fix in the setTimeout Function to add clearInterval

	private function setTimeout () : Void {
		clearInterval(timerInterval);
		timerInterval = setInterval (Delegate.create(this, timeoutComplete), duration);
	}</description>
		<content:encoded><![CDATA[<p>Potential bug if somethings calls Timeout.go() before the timer is has run out.<br />
Simple fix in the setTimeout Function to add clearInterval</p>
<p>	private function setTimeout () : Void {<br />
		clearInterval(timerInterval);<br />
		timerInterval = setInterval (Delegate.create(this, timeoutComplete), duration);<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Administrator</title>
		<link>http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/comment-page-1/#comment-46</link>
		<dc:creator>Administrator</dc:creator>
		<pubDate>Tue, 25 Apr 2006 11:46:52 +0000</pubDate>
		<guid isPermaLink="false">http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/#comment-46</guid>
		<description>Of course this is also an example of the Observer &amp; Chain of Responsibility GOF design patterns, if you have the option to use the &lt;b&gt;&lt;em&gt;TopLevel.&lt;/em&gt;setTimeout()&lt;/b&gt; function I would still place it within the event framework used in this class.

If you need to do something quick and dirty then it&#039;s always ok to use whatever method you like, however, when you develop larger systems in Flash using AS2.0 it is (very often) beneficial in the long run to design your application along the lines of an event based model.

As an aside, I&#039;ve been looking closely at the NSNotificationCenter which has been implemented in the ASAPFramework and also in ActionStep, this is a very cool event model which allows objects to listen for messages for which they don&#039;t neccessarily know the broadcaster.

&lt;a href=&quot;http://developer.apple.com/documentation/WebObjects/Reference/api/com/webobjects/foundation/NSNotificationCenter.html&quot;&gt;Some more info about Notifications.&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Of course this is also an example of the Observer &#038; Chain of Responsibility GOF design patterns, if you have the option to use the <b><em>TopLevel.</em>setTimeout()</b> function I would still place it within the event framework used in this class.</p>
<p>If you need to do something quick and dirty then it&#8217;s always ok to use whatever method you like, however, when you develop larger systems in Flash using AS2.0 it is (very often) beneficial in the long run to design your application along the lines of an event based model.</p>
<p>As an aside, I&#8217;ve been looking closely at the NSNotificationCenter which has been implemented in the ASAPFramework and also in ActionStep, this is a very cool event model which allows objects to listen for messages for which they don&#8217;t neccessarily know the broadcaster.</p>
<p><a href="http://developer.apple.com/documentation/WebObjects/Reference/api/com/webobjects/foundation/NSNotificationCenter.html">Some more info about Notifications.</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Administrator</title>
		<link>http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/comment-page-1/#comment-45</link>
		<dc:creator>Administrator</dc:creator>
		<pubDate>Tue, 25 Apr 2006 11:27:23 +0000</pubDate>
		<guid isPermaLink="false">http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/#comment-45</guid>
		<description>Yep, it is working when I compile from Flash 8 to a FlashPlayer 6 profile. This wasn&#039;t the problem I was trying to solve here.

The thing is many people have yet to upgrade to Flash 8, (sad as that may be.) And so the class uses &lt;b&gt;setInterval&lt;/b&gt; instead of &lt;b&gt;setTimeout&lt;/b&gt;.</description>
		<content:encoded><![CDATA[<p>Yep, it is working when I compile from Flash 8 to a FlashPlayer 6 profile. This wasn&#8217;t the problem I was trying to solve here.</p>
<p>The thing is many people have yet to upgrade to Flash 8, (sad as that may be.) And so the class uses <b>setInterval</b> instead of <b>setTimeout</b>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Epictive</title>
		<link>http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/comment-page-1/#comment-44</link>
		<dc:creator>Epictive</dc:creator>
		<pubDate>Fri, 21 Apr 2006 17:27:52 +0000</pubDate>
		<guid isPermaLink="false">http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/#comment-44</guid>
		<description>It is working in my movie published as Flash 6 fine. Is it not for you?</description>
		<content:encoded><![CDATA[<p>It is working in my movie published as Flash 6 fine. Is it not for you?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Administrator</title>
		<link>http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/comment-page-1/#comment-43</link>
		<dc:creator>Administrator</dc:creator>
		<pubDate>Fri, 21 Apr 2006 09:16:22 +0000</pubDate>
		<guid isPermaLink="false">http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/#comment-43</guid>
		<description>Thing is, setTimeout is an undocumented &lt;b&gt;Flash 8&lt;/b&gt; function... that&#039;s why I didn&#039;t use it in the class, many projects are still targeted at &lt;b&gt;Flash 6&lt;/b&gt; (sadly!)

So this is for maximum compatibility in AS2.0.</description>
		<content:encoded><![CDATA[<p>Thing is, setTimeout is an undocumented <b>Flash 8</b> function&#8230; that&#8217;s why I didn&#8217;t use it in the class, many projects are still targeted at <b>Flash 6</b> (sadly!)</p>
<p>So this is for maximum compatibility in AS2.0.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Epictive</title>
		<link>http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/comment-page-1/#comment-41</link>
		<dc:creator>Epictive</dc:creator>
		<pubDate>Thu, 20 Apr 2006 17:45:01 +0000</pubDate>
		<guid isPermaLink="false">http://mentalaxis.com/words/2006/04/20/as20-event-based-timer-class/#comment-41</guid>
		<description>You know that setTimeout is actually an undocumented AS function? You can actually use it like you would in JS like:

function calledOnlyOnce(Void):Void {
   trace(&#039;I was called once&#039;);
}

setTimeout(this, &#039;calledOnlyOnce&#039;, 1000);</description>
		<content:encoded><![CDATA[<p>You know that setTimeout is actually an undocumented AS function? You can actually use it like you would in JS like:</p>
<p>function calledOnlyOnce(Void):Void {<br />
   trace(&#8217;I was called once&#8217;);<br />
}</p>
<p>setTimeout(this, &#8216;calledOnlyOnce&#8217;, 1000);</p>
]]></content:encoded>
	</item>
</channel>
</rss>
