<?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: Cool addChild trick! Why don&#8217;t people use the return of addChild?</title>
	<atom:link href="http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/</link>
	<description>At the top of our game in st.Louis</description>
	<lastBuildDate>Sun, 07 Mar 2010 06:15:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: AJ</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-728</link>
		<dc:creator>AJ</dc:creator>
		<pubDate>Wed, 03 Feb 2010 11:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-728</guid>
		<description>Just stumbled on this while trying to find some info on some weird super.method functioning I&#039;m getting with Flex.  Thought I&#039;d give you this bit of code, since I&#039;m here:

( s = addChild(new Sprite()) as Sprite ).x = 100;

Looks ugly, so probably shouldn&#039;t be used unless you&#039;re *REALLY* dependant on every CPU cycle, but there might be a situation where the concept could be useful to someone.</description>
		<content:encoded><![CDATA[<p>Just stumbled on this while trying to find some info on some weird super.method functioning I&#8217;m getting with Flex.  Thought I&#8217;d give you this bit of code, since I&#8217;m here:</p>
<p>( s = addChild(new Sprite()) as Sprite ).x = 100;</p>
<p>Looks ugly, so probably shouldn&#8217;t be used unless you&#8217;re *REALLY* dependant on every CPU cycle, but there might be a situation where the concept could be useful to someone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jon</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-684</link>
		<dc:creator>jon</dc:creator>
		<pubDate>Thu, 14 Jan 2010 15:19:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-684</guid>
		<description>also check this out... end up looking like:

var s:Sprite = Sprite( mainSprite.addChild(create(Class, {x:0, y:0, rotation:90})));

// Instantiate and Set Properties
function create(obj:Class, props:Object):*
{
	var o:* = new obj();
	for (var p:String in props){
		o[p] = props[p];
	}
	return o;
}</description>
		<content:encoded><![CDATA[<p>also check this out&#8230; end up looking like:</p>
<p>var s:Sprite = Sprite( mainSprite.addChild(create(Class, {x:0, y:0, rotation:90})));</p>
<p>// Instantiate and Set Properties<br />
function create(obj:Class, props:Object):*<br />
{<br />
	var o:* = new obj();<br />
	for (var p:String in props){<br />
		o[p] = props[p];<br />
	}<br />
	return o;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spender</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-98</link>
		<dc:creator>spender</dc:creator>
		<pubDate>Thu, 04 Sep 2008 22:45:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-98</guid>
		<description>I know constructs like this:

array.push(addChild(_mc))

and this:

var s:Sprite = addChild(new Sprite);
s.x = 100;

look cool, but unless there&#039;s a real speed benefit in a portion of code that needs optimization, I think it&#039;s better to keep things separated. Ultimately, the code is more readable this way which carries a far greater benefit than a snappy way of doing 2 things in a single line.</description>
		<content:encoded><![CDATA[<p>I know constructs like this:</p>
<p>array.push(addChild(_mc))</p>
<p>and this:</p>
<p>var s:Sprite = addChild(new Sprite);<br />
s.x = 100;</p>
<p>look cool, but unless there&#8217;s a real speed benefit in a portion of code that needs optimization, I think it&#8217;s better to keep things separated. Ultimately, the code is more readable this way which carries a far greater benefit than a snappy way of doing 2 things in a single line.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aestheticsData</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-82</link>
		<dc:creator>aestheticsData</dc:creator>
		<pubDate>Wed, 27 Aug 2008 09:37:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-82</guid>
		<description>here is some performance test

1st method:
----------
for(var i:int = 0 ; i &lt; NB ; i += 1) {
	var s:Sprite = addChild( new Sprite ) as Sprite;
}


2nd method:
-----------
for( var k:int = 0 ; k &lt; NB ; k += 1) {

	var s2:Sprite = new Sprite;
	addChild( s2 );
}

average time:
---------------------------------------
NB              &#124; 0.5K  1K   2K   4K   6K   8K   10K   12K
2nd / 1st ratio &#124; 1.3   1.6  2.1  2.7  5    9.3  9.4   9.4

we can see that when there is fewer than 500 Sprite both methods are almost equivalent. But beyond 2K Sprites 1st method is a lot more shorther than 2nd. And around 8K and beyond the difference is big, but stable when NB increase over 8K</description>
		<content:encoded><![CDATA[<p>here is some performance test</p>
<p>1st method:<br />
&#8212;&#8212;&#8212;-<br />
for(var i:int = 0 ; i &lt; NB ; i += 1) {<br />
	var s:Sprite = addChild( new Sprite ) as Sprite;<br />
}</p>
<p>2nd method:<br />
&#8212;&#8212;&#8212;&#8211;<br />
for( var k:int = 0 ; k &lt; NB ; k += 1) {</p>
<p>	var s2:Sprite = new Sprite;<br />
	addChild( s2 );<br />
}</p>
<p>average time:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
NB              | 0.5K  1K   2K   4K   6K   8K   10K   12K<br />
2nd / 1st ratio | 1.3   1.6  2.1  2.7  5    9.3  9.4   9.4</p>
<p>we can see that when there is fewer than 500 Sprite both methods are almost equivalent. But beyond 2K Sprites 1st method is a lot more shorther than 2nd. And around 8K and beyond the difference is big, but stable when NB increase over 8K</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aestheticsData</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-81</link>
		<dc:creator>aestheticsData</dc:creator>
		<pubDate>Wed, 27 Aug 2008 09:00:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-81</guid>
		<description>&quot; var s:Sprite = addChild( new Sprite );
  s.x = 100; &quot;

it doesn&#039;t work. addChild returns a DisplayObject and not a Sprite. So to make it work :

var s:Sprite = addChild( new Sprite ) as Sprite;</description>
		<content:encoded><![CDATA[<p>&#8221; var s:Sprite = addChild( new Sprite );<br />
  s.x = 100; &#8221;</p>
<p>it doesn&#8217;t work. addChild returns a DisplayObject and not a Sprite. So to make it work :</p>
<p>var s:Sprite = addChild( new Sprite ) as Sprite;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Chernoff</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-78</link>
		<dc:creator>Josh Chernoff</dc:creator>
		<pubDate>Tue, 19 Aug 2008 15:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-78</guid>
		<description>well here is a small example.

var someArray:Array = new Array();
function someFunction():void{
     //make a bunch of sprites
     var sprite:Sprite = new Sprite();
     someArray.push(addChild(sprite));
}
//now what if I want to access the sprites?
//Do I use the array or getChildAt()?

removeChild(someArray[someIndex]);
vs.
removeChild(getChildByName(&quot;hadINamedItThisMightwork&quot;));
vs.
removeChildAt(getChildAt(someIndex)); 
//if I know the index of the child then this might work.

get the point yet?</description>
		<content:encoded><![CDATA[<p>well here is a small example.</p>
<p>var someArray:Array = new Array();<br />
function someFunction():void{<br />
     //make a bunch of sprites<br />
     var sprite:Sprite = new Sprite();<br />
     someArray.push(addChild(sprite));<br />
}<br />
//now what if I want to access the sprites?<br />
//Do I use the array or getChildAt()?</p>
<p>removeChild(someArray[someIndex]);<br />
vs.<br />
removeChild(getChildByName(&#8220;hadINamedItThisMightwork&#8221;));<br />
vs.<br />
removeChildAt(getChildAt(someIndex));<br />
//if I know the index of the child then this might work.</p>
<p>get the point yet?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: radekg</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-77</link>
		<dc:creator>radekg</dc:creator>
		<pubDate>Tue, 19 Aug 2008 15:15:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-77</guid>
		<description>What is the point of storing child items in separate array apart of making GC confused? If child items are in its parent why to access them with separate array?</description>
		<content:encoded><![CDATA[<p>What is the point of storing child items in separate array apart of making GC confused? If child items are in its parent why to access them with separate array?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martha</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-68</link>
		<dc:creator>Martha</dc:creator>
		<pubDate>Thu, 14 Aug 2008 17:06:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-68</guid>
		<description>Nice!

I thought I was all alone. I&#039;ve been routinely gathering all my children generated in loops into an easy to grab array like this:

addChild(art);
artList.push(art);

I like your system -- short and to the point.</description>
		<content:encoded><![CDATA[<p>Nice!</p>
<p>I thought I was all alone. I&#8217;ve been routinely gathering all my children generated in loops into an easy to grab array like this:</p>
<p>addChild(art);<br />
artList.push(art);</p>
<p>I like your system &#8212; short and to the point.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MLohrman</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-67</link>
		<dc:creator>MLohrman</dc:creator>
		<pubDate>Thu, 14 Aug 2008 13:14:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-67</guid>
		<description>Is there any benefit to this besides slightly leaner code?</description>
		<content:encoded><![CDATA[<p>Is there any benefit to this besides slightly leaner code?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Chernoff</title>
		<link>http://www.as3apex.com/as3/cool-addchild-trick-why-dont-people-not-use-the-return-of-addchild/comment-page-1/#comment-64</link>
		<dc:creator>Josh Chernoff</dc:creator>
		<pubDate>Thu, 14 Aug 2008 06:44:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3apex.com/?p=38#comment-64</guid>
		<description>np:

our forum is new so not much people in there &quot;yet&quot; but still feel free to post. 

http://as3apex.com/forums

also there is 
http://actionscript.org
http://kirupa.com
http://flashkit.com

any one of them should be more then helpful.</description>
		<content:encoded><![CDATA[<p>np:</p>
<p>our forum is new so not much people in there &#8220;yet&#8221; but still feel free to post. </p>
<p><a href="http://as3apex.com/forums" rel="nofollow">http://as3apex.com/forums</a></p>
<p>also there is<br />
<a href="http://actionscript.org" rel="nofollow">http://actionscript.org</a><br />
<a href="http://kirupa.com" rel="nofollow">http://kirupa.com</a><br />
<a href="http://flashkit.com" rel="nofollow">http://flashkit.com</a></p>
<p>any one of them should be more then helpful.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
