<?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: AS3 Best Practice for Callback Evals</title>
	<atom:link href="http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/</link>
	<description>Programming, Visualization and Game Development Theory</description>
	<lastBuildDate>Sun, 22 Jan 2012 22:20:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: John Kanding</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-297</link>
		<dc:creator>John Kanding</dc:creator>
		<pubDate>Fri, 19 Mar 2010 23:27:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-297</guid>
		<description>Hmmm, I&#039;m a bit confused as to why use a callback in the above situation. It seems not to wait for doing anything, just runs through the code. So why not just have

private function gameEnded():void {
 saveScore(10);
 onSave()
}
But anyway callBacks are nice and it&#039;s good way it&#039;s shown above. Never thought of it like passing a function directly... doooh!

I often do it like this:

One object is using another object and needs to be called back when that object is done:

myObj1.mLoadImage(&quot;pic.png&quot;, this, &quot;mImDoneLoading&quot;)

The mLoadImage function looks like this:

public function mLoadImage(image:String, cbObj:Object, cbMethod:String){

 pCallBackObj = cbObj
 pCallBackMethod = cbMethod

}

Whenever the image is loaded and everything is fine, it calls pCallBackObj[pCallBackMethod]()

This can be in a totally different function within that object.</description>
		<content:encoded><![CDATA[<p>Hmmm, I&#8217;m a bit confused as to why use a callback in the above situation. It seems not to wait for doing anything, just runs through the code. So why not just have</p>
<p>private function gameEnded():void {<br />
 saveScore(10);<br />
 onSave()<br />
}<br />
But anyway callBacks are nice and it&#8217;s good way it&#8217;s shown above. Never thought of it like passing a function directly&#8230; doooh!</p>
<p>I often do it like this:</p>
<p>One object is using another object and needs to be called back when that object is done:</p>
<p>myObj1.mLoadImage(&#8220;pic.png&#8221;, this, &#8220;mImDoneLoading&#8221;)</p>
<p>The mLoadImage function looks like this:</p>
<p>public function mLoadImage(image:String, cbObj:Object, cbMethod:String){</p>
<p> pCallBackObj = cbObj<br />
 pCallBackMethod = cbMethod</p>
<p>}</p>
<p>Whenever the image is loaded and everything is fine, it calls pCallBackObj[pCallBackMethod]()</p>
<p>This can be in a totally different function within that object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ayu</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-273</link>
		<dc:creator>ayu</dc:creator>
		<pubDate>Sun, 07 Feb 2010 18:00:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-273</guid>
		<description>callbacks are 4x-8x times faster than event listeners in performance. event listeners creates unnecessary object, each time it creates it bogs down the CPU,</description>
		<content:encoded><![CDATA[<p>callbacks are 4x-8x times faster than event listeners in performance. event listeners creates unnecessary object, each time it creates it bogs down the CPU,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny Miller</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-129</link>
		<dc:creator>Danny Miller</dc:creator>
		<pubDate>Sat, 28 Feb 2009 00:37:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-129</guid>
		<description>Callbacks are fine but sort of the old way to do things... You should really use event listeners as that supports multiple &quot;call backs&quot; for a specific object.</description>
		<content:encoded><![CDATA[<p>Callbacks are fine but sort of the old way to do things&#8230; You should really use event listeners as that supports multiple &#8220;call backs&#8221; for a specific object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tyler Wright</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-117</link>
		<dc:creator>Tyler Wright</dc:creator>
		<pubDate>Sat, 14 Feb 2009 16:08:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-117</guid>
		<description>The most common way to handle this type of comparison:

&lt;code&gt;if(onSaveCallback != null) onSaveCallback()&lt;/code&gt;

...just a little easier.</description>
		<content:encoded><![CDATA[<p>The most common way to handle this type of comparison:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">if(onSaveCallback != null) onSaveCallback()</div></div>
<p>&#8230;just a little easier.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pleclech</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-116</link>
		<dc:creator>pleclech</dc:creator>
		<pubDate>Sat, 14 Feb 2009 14:42:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-116</guid>
		<description>Hello,

First sorry for my bad English...

My 2 cents, it seems a bit overkill just to test nullity of a function, since the short way make flash compiler complained, try the explicit way:

function foo(bar:Function=null):void{
 if (bar!=null)
  bar();
}

It will be faster than cast to an object and then compare to a string.

Regards.</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>First sorry for my bad English&#8230;</p>
<p>My 2 cents, it seems a bit overkill just to test nullity of a function, since the short way make flash compiler complained, try the explicit way:</p>
<p>function foo(bar:Function=null):void{<br />
 if (bar!=null)<br />
  bar();<br />
}</p>
<p>It will be faster than cast to an object and then compare to a string.</p>
<p>Regards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antoine</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-115</link>
		<dc:creator>Antoine</dc:creator>
		<pubDate>Sat, 14 Feb 2009 13:06:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-115</guid>
		<description>Why not just do this test :

if(onSaveCallback != null) onSaveCallback();</description>
		<content:encoded><![CDATA[<p>Why not just do this test :</p>
<p>if(onSaveCallback != null) onSaveCallback();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Al</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-114</link>
		<dc:creator>Al</dc:creator>
		<pubDate>Sat, 14 Feb 2009 12:17:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-114</guid>
		<description>How about using &#039;is&#039;:

 if(onSaveCallback is Function) onSaveCallback();

Can&#039;t help thinking a custom event is even cleaner...</description>
		<content:encoded><![CDATA[<p>How about using &#8216;is&#8217;:</p>
<p> if(onSaveCallback is Function) onSaveCallback();</p>
<p>Can&#8217;t help thinking a custom event is even cleaner&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mije</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-112</link>
		<dc:creator>Mije</dc:creator>
		<pubDate>Sat, 14 Feb 2009 08:33:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-112</guid>
		<description>Hm. Why not do this simple check?

if(onSaveCallback !== null) onSaveCallback();</description>
		<content:encoded><![CDATA[<p>Hm. Why not do this simple check?</p>
<p>if(onSaveCallback !== null) onSaveCallback();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Theo Denovan</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-111</link>
		<dc:creator>Theo Denovan</dc:creator>
		<pubDate>Sat, 14 Feb 2009 08:09:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-111</guid>
		<description>I believe the following also works:

if( functionArg is Function )</description>
		<content:encoded><![CDATA[<p>I believe the following also works:</p>
<p>if( functionArg is Function )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Schneble</title>
		<link>http://www.jadbox.com/2009/02/as3-optional-callback-method-warning/comment-page-1/#comment-110</link>
		<dc:creator>Nick Schneble</dc:creator>
		<pubDate>Sat, 14 Feb 2009 07:09:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.jadbox.com/?p=882#comment-110</guid>
		<description>There&#039;s actually an easier solution-

Instead of:
if(onSaveCallback) onSaveCallback();

Do this:
if(onSaveCallback != null) onSaveCallback();</description>
		<content:encoded><![CDATA[<p>There&#8217;s actually an easier solution-</p>
<p>Instead of:<br />
if(onSaveCallback) onSaveCallback();</p>
<p>Do this:<br />
if(onSaveCallback != null) onSaveCallback();</p>
]]></content:encoded>
	</item>
</channel>
</rss>

