<?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"
	>
<channel>
	<title>Comments on: Creating a True MovieClip Sub-Class</title>
	<atom:link href="http://www.plasticstare.com/plains/2005/12/21/creating-a-true-movieclip-sub-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.plasticstare.com/plains/2005/12/21/creating-a-true-movieclip-sub-class/</link>
	<description></description>
	<pubDate>Tue, 18 Nov 2008 15:32:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: ryan</title>
		<link>http://www.plasticstare.com/plains/2005/12/21/creating-a-true-movieclip-sub-class/#comment-420</link>
		<dc:creator>ryan</dc:creator>
		<pubDate>Wed, 08 Nov 2006 16:59:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.plasticstare.com/plains_wp/?p=64#comment-420</guid>
		<description>Cool, thanks, good catch. Hadn't looked at that in a long while...knew there was room for improvement though...</description>
		<content:encoded><![CDATA[<p>Cool, thanks, good catch. Hadn&#8217;t looked at that in a long while&#8230;knew there was room for improvement though&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eden</title>
		<link>http://www.plasticstare.com/plains/2005/12/21/creating-a-true-movieclip-sub-class/#comment-416</link>
		<dc:creator>eden</dc:creator>
		<pubDate>Wed, 08 Nov 2006 10:20:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.plasticstare.com/plains_wp/?p=64#comment-416</guid>
		<description>Woops, ignore the paragraph that starts with "To fix this...".  The real fix is to do mc.constructor.call(mc) which replaces the default "this" in the constructor with the empty movie clip instance.</description>
		<content:encoded><![CDATA[<p>Woops, ignore the paragraph that starts with &#8220;To fix this&#8230;&#8221;.  The real fix is to do mc.constructor.call(mc) which replaces the default &#8220;this&#8221; in the constructor with the empty movie clip instance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eden</title>
		<link>http://www.plasticstare.com/plains/2005/12/21/creating-a-true-movieclip-sub-class/#comment-415</link>
		<dc:creator>eden</dc:creator>
		<pubDate>Wed, 08 Nov 2006 10:18:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.plasticstare.com/plains_wp/?p=64#comment-415</guid>
		<description>Finally!  I've been looking around for a way to get my MovieClip subclasses onto the stage without going through the Flash IDE.

I tried using and I discovered that in SpaceInvader's constructor (for eg), "this" points to a dead MovieClip that will never be put onto the stage.  That means you can't do anything really useful in your constructor.

To fix this, you can simply replace new _constructor() with _constructor.apply(mc).  Also, you don't need to copy every property if you assign to __proto__.

Here's another version that addresses these issues:

&lt;code&gt;
function createExtendedMovieClip(klass:Function) {
	var parent = arguments[1] &#124;&#124; _root;
	var depth = arguments[2] &#124;&#124; parent.getNextHighestDepth();
	var inst = parent._name + "_clip_" + depth;
	var mc:MovieClip = parent.createEmptyMovieClip(inst, depth);
	mc.constructor = klass;
	mc.__proto__ = klass.prototype;
	mc.constructor.call(mc);
	return mc;
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Finally!  I&#8217;ve been looking around for a way to get my MovieClip subclasses onto the stage without going through the Flash IDE.</p>
<p>I tried using and I discovered that in SpaceInvader&#8217;s constructor (for eg), &#8220;this&#8221; points to a dead MovieClip that will never be put onto the stage.  That means you can&#8217;t do anything really useful in your constructor.</p>
<p>To fix this, you can simply replace new _constructor() with _constructor.apply(mc).  Also, you don&#8217;t need to copy every property if you assign to __proto__.</p>
<p>Here&#8217;s another version that addresses these issues:</p>
<p><code><br />
function createExtendedMovieClip(klass:Function) {<br />
	var parent = arguments[1] || _root;<br />
	var depth = arguments[2] || parent.getNextHighestDepth();<br />
	var inst = parent._name + &#8220;_clip_&#8221; + depth;<br />
	var mc:MovieClip = parent.createEmptyMovieClip(inst, depth);<br />
	mc.constructor = klass;<br />
	mc.__proto__ = klass.prototype;<br />
	mc.constructor.call(mc);<br />
	return mc;<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
