<?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: Chain: Delayed function calling [updated]</title> <atom:link href="http://blog.stroep.nl/2009/11/delayed-function-calling-chain/feed/" rel="self" type="application/rss+xml" /><link>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/</link> <description>Just a collection of random works - Mark Knol</description> <lastBuildDate>Thu, 02 Feb 2012 00:51:33 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Bertrand Riché</title><link>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/#comment-11895</link> <dc:creator>Bertrand Riché</dc:creator> <pubDate>Thu, 17 Dec 2009 22:45:37 +0000</pubDate> <guid isPermaLink="false">http://blog.stroep.nl/?p=824#comment-11895</guid> <description>For me it was more the delay before the actual function than the delay for the next function call, but I see the point of what you&#039;ve had done.
Maybe this could be added as a parameter for your class, for example true = before, false = after ?After looking at what I&#039;ve modified in your class, I&#039;ve noticed that I&#039;ve made a few mistakes in my coding...
I was forced to recode some parts, here is the code parts I&#039;ve changed (I&#039;ve just done it quickly and there sure is some parts to optimize) :public function play(repeatCount:int = 1):void {
_reversed = false;
_repeatCount = repeatCount;
if (_list.length &gt; 0) {
reset();
_isPlaying = true;
_timer.delay = _list[0].delay;
_timer.repeatCount = 0;
_timer.start();
}
}public function playReversed(repeatCount:int = 1):void {
_reversed = true;
_repeatCount = repeatCount;
if (_list.length &gt; 0) {
reset();
_isPlaying = true;
_timer.delay = _list[_list.length - 1].delay;
_timer.repeatCount = 0;
_timer.start();
}
}protected function execute(index:int):void {
_timer.stop();
var obj:ChainItem = _list[index];
if (obj.func != null) {
obj.func();
}
}protected function launchNewTimer(index:int):void {
var obj:ChainItem = _list[index];
if (_isPlaying) {
_timer.delay = obj.delay;
_timer.repeatCount = 0;
_timer.start();
}
}protected function dispatchComplete():void {
_isPlaying = false;
dispatchEvent( new Event( Event.COMPLETE, false, false) );
}protected function onTimer(e:TimerEvent):void {
_timer.stop();
execute(_currentIndex);
if (!_reversed) {
_currentIndex ++;
if (_currentIndex &gt;= _list.length) {
if (_currentRepeatIndex &lt; _repeatCount - 1) {
_currentRepeatIndex++;
_currentIndex = 0;
launchNewTimer(_currentIndex);
} else {
dispatchComplete();
}
} else {
launchNewTimer(_currentIndex);
}
} else {
_currentIndex --;
if (_currentIndex &lt; 0) {
if (_currentRepeatIndex &lt; _repeatCount - 1) {
_currentRepeatIndex++;
_currentIndex = _list.length - 1;
launchNewTimer(_currentIndex);
} else {
dispatchComplete();
}
} else {
launchNewTimer(_currentIndex);
}
}
}</description> <content:encoded><![CDATA[<p>For me it was more the delay before the actual function than the delay for the next function call, but I see the point of what you&#8217;ve had done.<br /> Maybe this could be added as a parameter for your class, for example true = before, false = after ?</p><p>After looking at what I&#8217;ve modified in your class, I&#8217;ve noticed that I&#8217;ve made a few mistakes in my coding&#8230;<br /> I was forced to recode some parts, here is the code parts I&#8217;ve changed (I&#8217;ve just done it quickly and there sure is some parts to optimize) :</p><p>public function play(repeatCount:int = 1):void {<br /> _reversed = false;<br /> _repeatCount = repeatCount;</p><p> if (_list.length &gt; 0) {<br /> reset();</p><p> _isPlaying = true;<br /> _timer.delay = _list[0].delay;<br /> _timer.repeatCount = 0;<br /> _timer.start();<br /> }<br /> }</p><p>public function playReversed(repeatCount:int = 1):void {<br /> _reversed = true;<br /> _repeatCount = repeatCount;</p><p> if (_list.length &gt; 0) {<br /> reset();</p><p> _isPlaying = true;<br /> _timer.delay = _list[_list.length - 1].delay;<br /> _timer.repeatCount = 0;<br /> _timer.start();<br /> }<br /> }</p><p>protected function execute(index:int):void {<br /> _timer.stop();</p><p> var obj:ChainItem = _list[index];<br /> if (obj.func != null) {<br /> obj.func();<br /> }<br /> }</p><p>protected function launchNewTimer(index:int):void {<br /> var obj:ChainItem = _list[index];<br /> if (_isPlaying) {<br /> _timer.delay = obj.delay;<br /> _timer.repeatCount = 0;<br /> _timer.start();<br /> }<br /> }</p><p>protected function dispatchComplete():void {<br /> _isPlaying = false;<br /> dispatchEvent( new Event( Event.COMPLETE, false, false) );<br /> }</p><p>protected function onTimer(e:TimerEvent):void {</p><p> _timer.stop();</p><p> execute(_currentIndex);</p><p> if (!_reversed) {<br /> _currentIndex ++;<br /> if (_currentIndex &gt;= _list.length) {<br /> if (_currentRepeatIndex &lt; _repeatCount &#8211; 1) {<br /> _currentRepeatIndex++;<br /> _currentIndex = 0;<br /> launchNewTimer(_currentIndex);<br /> } else {<br /> dispatchComplete();<br /> }<br /> } else {<br /> launchNewTimer(_currentIndex);<br /> }<br /> } else {<br /> _currentIndex &#8211;;<br /> if (_currentIndex &lt; 0) {<br /> if (_currentRepeatIndex &lt; _repeatCount &#8211; 1) {<br /> _currentRepeatIndex++;<br /> _currentIndex = _list.length &#8211; 1;<br /> launchNewTimer(_currentIndex);<br /> } else {<br /> dispatchComplete();<br /> }<br /> } else {<br /> launchNewTimer(_currentIndex);<br /> }<br /> }<br /> }</p> ]]></content:encoded> </item> <item><title>By: Mark</title><link>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/#comment-11868</link> <dc:creator>Mark</dc:creator> <pubDate>Thu, 17 Dec 2009 11:18:59 +0000</pubDate> <guid isPermaLink="false">http://blog.stroep.nl/?p=824#comment-11868</guid> <description>@Riche; the delay value is originally intended to be the delay for the next functioncall. But i think you are right, it maybe sounds more logical to do it like you said. When I have some time I am going to fix it.
Where exactly did you set this value?</description> <content:encoded><![CDATA[<p>@Riche; the delay value is originally intended to be the delay for the next functioncall. But i think you are right, it maybe sounds more logical to do it like you said. When I have some time I am going to fix it.<br /> Where exactly did you set this value?</p> ]]></content:encoded> </item> <item><title>By: Riché Bertrand</title><link>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/#comment-11822</link> <dc:creator>Riché Bertrand</dc:creator> <pubDate>Wed, 16 Dec 2009 15:19:13 +0000</pubDate> <guid isPermaLink="false">http://blog.stroep.nl/?p=824#comment-11822</guid> <description>Hi,
great work, I was looking for a clue on how using such syntax as you use, now I have my answer, thanks for this !But after testing and looking at your class, it seems that there is a mistake in it. In fact, when I use this code :chain.add(one, 5000).add(two, 200).add(three, 10000).play(1);the chain class plays the function &quot;one&quot; immediatly, then the two 5 seconds after, the function three 200 milliseconds after, and finish by dispatching the COMPLETE event 10 seconds after...
Wouldn&#039;t it be :
- wait 5 seconds,
- play &quot;one&quot;,
- wait 200 milliseconds
- play &quot;two&quot;,
- wait 10 sec
- play &quot;three&quot;
- dispatch Complete immediatly ?I&#039;ve managed to do that by using the [index + 1] delay when starting the timer... is this made intentionally or is it just a little mistake ?Anyway this is a great idea, keep it going !</description> <content:encoded><![CDATA[<p>Hi,<br /> great work, I was looking for a clue on how using such syntax as you use, now I have my answer, thanks for this !</p><p>But after testing and looking at your class, it seems that there is a mistake in it. In fact, when I use this code :</p><p>chain.add(one, 5000).add(two, 200).add(three, 10000).play(1);</p><p>the chain class plays the function &#8220;one&#8221; immediatly, then the two 5 seconds after, the function three 200 milliseconds after, and finish by dispatching the COMPLETE event 10 seconds after&#8230;<br /> Wouldn&#8217;t it be :<br /> - wait 5 seconds,<br /> - play &#8220;one&#8221;,<br /> - wait 200 milliseconds<br /> - play &#8220;two&#8221;,<br /> - wait 10 sec<br /> - play &#8220;three&#8221;<br /> - dispatch Complete immediatly ?</p><p>I&#8217;ve managed to do that by using the [index + 1] delay when starting the timer&#8230; is this made intentionally or is it just a little mistake ?</p><p>Anyway this is a great idea, keep it going !</p> ]]></content:encoded> </item> <item><title>By: Mark Knol</title><link>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/#comment-10362</link> <dc:creator>Mark Knol</dc:creator> <pubDate>Sun, 15 Nov 2009 14:11:52 +0000</pubDate> <guid isPermaLink="false">http://blog.stroep.nl/?p=824#comment-10362</guid> <description>Thanks man; great tips! I&#039;ve updated the class+blogpost. I think you are right function should be required. Ive also added Event.COMPLETE, and class is now extending EventDispatcher.</description> <content:encoded><![CDATA[<p>Thanks man; great tips! I&#8217;ve updated the class+blogpost. I think you are right function should be required. Ive also added Event.COMPLETE, and class is now extending EventDispatcher.</p> ]]></content:encoded> </item> <item><title>By: Erwin Verdonk</title><link>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/#comment-10336</link> <dc:creator>Erwin Verdonk</dc:creator> <pubDate>Sat, 14 Nov 2009 19:30:00 +0000</pubDate> <guid isPermaLink="false">http://blog.stroep.nl/?p=824#comment-10336</guid> <description>One more thing: The second argument of the function add() shouldn&#039;t be optional. When there is no second argument, there is really nothing to add.</description> <content:encoded><![CDATA[<p>One more thing: The second argument of the function add() shouldn&#8217;t be optional. When there is no second argument, there is really nothing to add.</p> ]]></content:encoded> </item> <item><title>By: Erwin Verdonk</title><link>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/#comment-10334</link> <dc:creator>Erwin Verdonk</dc:creator> <pubDate>Sat, 14 Nov 2009 17:15:00 +0000</pubDate> <guid isPermaLink="false">http://blog.stroep.nl/?p=824#comment-10334</guid> <description>Nice little utility class when in need of time depended sequences. Two things of advice:1. Make use of the protected namespace instead of private. This makes it easier for other people to extend or fix issues, without changing the existing code.
2. Make use of events instead of callback functions. Its not only better practice in an event driven language like ActionScript 3, but also more flexible and secure (less unnecessary public members).Keep it going, Mark!</description> <content:encoded><![CDATA[<p>Nice little utility class when in need of time depended sequences. Two things of advice:</p><p>1. Make use of the protected namespace instead of private. This makes it easier for other people to extend or fix issues, without changing the existing code.<br /> 2. Make use of events instead of callback functions. Its not only better practice in an event driven language like ActionScript 3, but also more flexible and secure (less unnecessary public members).</p><p>Keep it going, Mark!</p> ]]></content:encoded> </item> </channel> </rss>
