<?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: extending MovieClip</title>
	<atom:link href="http://blog.aboutme.be/2006/09/20/extending-movieclip/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=extending-movieclip</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 02:22:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: rossisen</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-13771</link>
		<dc:creator>rossisen</dc:creator>
		<pubDate>Tue, 30 Sep 2008 19:49:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-13771</guid>
		<description>We have been having some trouble with having Array properties of a class.  We have been getting one instance changing the values of another instances&#039; array.  Here is an example boiled down to its most basic:

The .as file

class edu.clips.ArrayTester extends MovieClip {
	static var symbolName:String = &quot;__Packages.edu.clips.ArrayTester&quot;;
	static var symbolOwner:Function = ArrayTester;
	static var symbolLinked = Object.registerClass(symbolName, symbolOwner);

	//private var Shapes:Array; //can be used with the commented line below
	private var Shapes:Array = new Array();
	private var num:Number = new Number();
	private var initShapes:Array;

	public static function create(container:MovieClip, instanceName:String, initObj:Object) {

		container.attachMovie(symbolName,instanceName,container.getNextHighestDepth(),initObj);
		return ArrayTester(container[instanceName]);
	}
	public function ArrayTester(target:Object) {
		//this line is necessary or the various instances use the same Array - how weird is that
		//Shapes = new Array();
		for (var ii = 0; ii&lt;initShapes.length; ii++) {
			trace(&quot;setting &quot;+ii);
			this.Shapes[initShapes[ii]] = ii*ii;
			num=initShapes[ii];
		}
	}

	public function traceArray():Void {
		trace(&quot;Shapes &quot;+this.Shapes);
		trace(&quot;initShapes &quot;+initShapes);
		trace(&quot;num &quot;+num);
	}
}

The calling .fla

import edu.clips.ArrayTester;

ArrayTester.create(this,&quot;at1_mc&quot;,{initShapes:[1,7,9]});
at1_mc.traceArray();
ArrayTester.create(this,&quot;at2_mc&quot;,{initShapes:[2,3,10]});
at1_mc.traceArray();

and the output:

setting 0
setting 1
setting 2
Shapes undefined,0,undefined,undefined,undefined,undefined,undefined,1,undefined,4
initShapes 1,7,9
num 9
setting 0
setting 1
setting 2
Shapes undefined,0,0,1,undefined,undefined,undefined,1,undefined,4,4
initShapes 1,7,9
num 9

Notice that the Shapes Array for at1_mc is different after at2_mc is created.  This is not the case for a similarly treated Number object.  If the commented lines are switched in then this behaviour does not occur.  Is this an expected thing or a bug?</description>
		<content:encoded><![CDATA[<p>We have been having some trouble with having Array properties of a class.  We have been getting one instance changing the values of another instances&#8217; array.  Here is an example boiled down to its most basic:</p>
<p>The .as file</p>
<p>class edu.clips.ArrayTester extends MovieClip {<br />
	static var symbolName:String = &#8220;__Packages.edu.clips.ArrayTester&#8221;;<br />
	static var symbolOwner:Function = ArrayTester;<br />
	static var symbolLinked = Object.registerClass(symbolName, symbolOwner);</p>
<p>	//private var Shapes:Array; //can be used with the commented line below<br />
	private var Shapes:Array = new Array();<br />
	private var num:Number = new Number();<br />
	private var initShapes:Array;</p>
<p>	public static function create(container:MovieClip, instanceName:String, initObj:Object) {</p>
<p>		container.attachMovie(symbolName,instanceName,container.getNextHighestDepth(),initObj);<br />
		return ArrayTester(container[instanceName]);<br />
	}<br />
	public function ArrayTester(target:Object) {<br />
		//this line is necessary or the various instances use the same Array &#8211; how weird is that<br />
		//Shapes = new Array();<br />
		for (var ii = 0; ii&lt;initShapes.length; ii++) {<br />
			trace(&#8220;setting &#8220;+ii);<br />
			this.Shapes[initShapes[ii]] = ii*ii;<br />
			num=initShapes[ii];<br />
		}<br />
	}</p>
<p>	public function traceArray():Void {<br />
		trace(&#8220;Shapes &#8220;+this.Shapes);<br />
		trace(&#8220;initShapes &#8220;+initShapes);<br />
		trace(&#8220;num &#8220;+num);<br />
	}<br />
}</p>
<p>The calling .fla</p>
<p>import edu.clips.ArrayTester;</p>
<p>ArrayTester.create(this,&#8221;at1_mc&#8221;,{initShapes:[1,7,9]});<br />
at1_mc.traceArray();<br />
ArrayTester.create(this,&#8221;at2_mc&#8221;,{initShapes:[2,3,10]});<br />
at1_mc.traceArray();</p>
<p>and the output:</p>
<p>setting 0<br />
setting 1<br />
setting 2<br />
Shapes undefined,0,undefined,undefined,undefined,undefined,undefined,1,undefined,4<br />
initShapes 1,7,9<br />
num 9<br />
setting 0<br />
setting 1<br />
setting 2<br />
Shapes undefined,0,0,1,undefined,undefined,undefined,1,undefined,4,4<br />
initShapes 1,7,9<br />
num 9</p>
<p>Notice that the Shapes Array for at1_mc is different after at2_mc is created.  This is not the case for a similarly treated Number object.  If the commented lines are switched in then this behaviour does not occur.  Is this an expected thing or a bug?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wouter</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-11722</link>
		<dc:creator>wouter</dc:creator>
		<pubDate>Sun, 03 Aug 2008 14:20:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-11722</guid>
		<description>rossisen

1. You could do something like this, but you would have to pass a reference to the movieclip parent through the constructor.

2. This is not a constructor, but a class cast, to indicate to the AS2 compiler that we are working with the correct class type (which is specified as return type in our function definition).</description>
		<content:encoded><![CDATA[<p>rossisen</p>
<p>1. You could do something like this, but you would have to pass a reference to the movieclip parent through the constructor.</p>
<p>2. This is not a constructor, but a class cast, to indicate to the AS2 compiler that we are working with the correct class type (which is specified as return type in our function definition).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rossisen</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-9576</link>
		<dc:creator>rossisen</dc:creator>
		<pubDate>Fri, 27 Jun 2008 18:07:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-9576</guid>
		<description>This was really useful to me and I have been able to create classes using it.  I still have two nagging questions:

1.  Why can&#039;t I use something like 
var newRect:MovieClip = new MyRectangle();
with a parameter maybe?????

instead of

this.attachMovie(MyRectangle.symbolName, &quot;rectangle_mc&quot;, this.getNextHighestDepth());
or the create function (which is what you prefer and I have been implementing)

2.  What does the parameter in the 
return MyRectangle(container[&quot;rectangle_mc&quot;]);

really do - is it a form of the MovieClip constructor?  Your constructor does not take a parameter...

Thanks.</description>
		<content:encoded><![CDATA[<p>This was really useful to me and I have been able to create classes using it.  I still have two nagging questions:</p>
<p>1.  Why can&#8217;t I use something like<br />
var newRect:MovieClip = new MyRectangle();<br />
with a parameter maybe?????</p>
<p>instead of</p>
<p>this.attachMovie(MyRectangle.symbolName, &#8220;rectangle_mc&#8221;, this.getNextHighestDepth());<br />
or the create function (which is what you prefer and I have been implementing)</p>
<p>2.  What does the parameter in the<br />
return MyRectangle(container["rectangle_mc"]);</p>
<p>really do &#8211; is it a form of the MovieClip constructor?  Your constructor does not take a parameter&#8230;</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wouter</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-987</link>
		<dc:creator>wouter</dc:creator>
		<pubDate>Sat, 21 Jul 2007 08:58:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-987</guid>
		<description>Robert,

Sure, you can subclass classes like this. Basic example:

//Top level Shape class:

class MyShape extends MovieClip {
  static var symbolName:String = &quot;__Packages.MyShape&quot;;
  static var symbolOwner:Function = MyShape;
  static var symbolLinked = Object.registerClass(symbolName, symbolOwner);
  public static function create(container:MovieClip, initObj:Object):MyShape{
    container.attachMovie(symbolName, &quot;shape_mc&quot;, container.getNextHighestDepth(), initObj);
    return MyShape(container[&quot;shape_mc&quot;]);
  }
}

//A class extending this Shape:

class MyRedShape extends MyShape {
  static var symbolName:String = &quot;__Packages.MyRedShape&quot;;
  static var symbolOwner:Function = MyRedShape;
  static var symbolLinked = Object.registerClass(symbolName, symbolOwner);
  public static function create(container:MovieClip, initObj:Object):MyRedShape{
    container.attachMovie(symbolName, &quot;shape_mc&quot;, container.getNextHighestDepth(), initObj);
    return MyRedShape(container[&quot;shape_mc&quot;]);
  }
}

The static create function is not necessary, but handy to create instances of our custom class. The thing that does the actual trick is:

static var symbolLinked = Object.registerClass(symbolName, symbolOwner);

With symbolName being the __packages.CLASSNAME and symbolOwner CLASSNAME (without quotes).

Good luck!</description>
		<content:encoded><![CDATA[<p>Robert,</p>
<p>Sure, you can subclass classes like this. Basic example:</p>
<p>//Top level Shape class:</p>
<p>class MyShape extends MovieClip {<br />
  static var symbolName:String = &#8220;__Packages.MyShape&#8221;;<br />
  static var symbolOwner:Function = MyShape;<br />
  static var symbolLinked = Object.registerClass(symbolName, symbolOwner);<br />
  public static function create(container:MovieClip, initObj:Object):MyShape{<br />
    container.attachMovie(symbolName, &#8220;shape_mc&#8221;, container.getNextHighestDepth(), initObj);<br />
    return MyShape(container["shape_mc"]);<br />
  }<br />
}</p>
<p>//A class extending this Shape:</p>
<p>class MyRedShape extends MyShape {<br />
  static var symbolName:String = &#8220;__Packages.MyRedShape&#8221;;<br />
  static var symbolOwner:Function = MyRedShape;<br />
  static var symbolLinked = Object.registerClass(symbolName, symbolOwner);<br />
  public static function create(container:MovieClip, initObj:Object):MyRedShape{<br />
    container.attachMovie(symbolName, &#8220;shape_mc&#8221;, container.getNextHighestDepth(), initObj);<br />
    return MyRedShape(container["shape_mc"]);<br />
  }<br />
}</p>
<p>The static create function is not necessary, but handy to create instances of our custom class. The thing that does the actual trick is:</p>
<p>static var symbolLinked = Object.registerClass(symbolName, symbolOwner);</p>
<p>With symbolName being the __packages.CLASSNAME and symbolOwner CLASSNAME (without quotes).</p>
<p>Good luck!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-981</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Fri, 20 Jul 2007 22:57:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-981</guid>
		<description>Wouter, 

Thanks for the quick reply.... and this code is a wonderful start.. I may use it quite often.. 

Now.... to be honest, not really sure why it did not work when I wrote previous comment.. BUT.. 

I got it to work after much intense trial and error...

Now here is the next question: 
How can this be made to work with subclasses using a dynamic create function? 

Unless I have misunderstood everything here,  one has to change the symbolName, symbolOwner  vars and the create function in order to change the name of this class for subclassing.

This seems to be logical... ie.. make the subclassing require less effort.

I have been trying for a few hours today to create a dynamic create class with no luck.  

I had some things which looked as tho they should work.. but they did not.. 

Any ideas? Am I missing something? 

Mind you, I have been with actionscript for only last few months.. so if I ask a silly question, please be patient.

Thanks again.. 

Robert</description>
		<content:encoded><![CDATA[<p>Wouter, </p>
<p>Thanks for the quick reply&#8230;. and this code is a wonderful start.. I may use it quite often.. </p>
<p>Now&#8230;. to be honest, not really sure why it did not work when I wrote previous comment.. BUT.. </p>
<p>I got it to work after much intense trial and error&#8230;</p>
<p>Now here is the next question:<br />
How can this be made to work with subclasses using a dynamic create function? </p>
<p>Unless I have misunderstood everything here,  one has to change the symbolName, symbolOwner  vars and the create function in order to change the name of this class for subclassing.</p>
<p>This seems to be logical&#8230; ie.. make the subclassing require less effort.</p>
<p>I have been trying for a few hours today to create a dynamic create class with no luck.  </p>
<p>I had some things which looked as tho they should work.. but they did not.. </p>
<p>Any ideas? Am I missing something? </p>
<p>Mind you, I have been with actionscript for only last few months.. so if I ask a silly question, please be patient.</p>
<p>Thanks again.. </p>
<p>Robert</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wouter</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-976</link>
		<dc:creator>Wouter</dc:creator>
		<pubDate>Fri, 20 Jul 2007 17:32:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-976</guid>
		<description>Hey Robert,

Where did you declare your attribute? You didn&#039;t happen to declare a variable outside the class{} braces?</description>
		<content:encoded><![CDATA[<p>Hey Robert,</p>
<p>Where did you declare your attribute? You didn&#8217;t happen to declare a variable outside the class{} braces?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-973</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Fri, 20 Jul 2007 15:20:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-973</guid>
		<description>Say there,  when doing this.. did you have trouble with &quot;Attribute used outside class.&quot;... ? 

thanks</description>
		<content:encoded><![CDATA[<p>Say there,  when doing this.. did you have trouble with &#8220;Attribute used outside class.&#8221;&#8230; ? </p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-958</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Thu, 19 Jul 2007 21:51:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-958</guid>
		<description>hmm... this looks very interesting.. I have yet to try it.. but you are bookmarked.. I too was hating the idea of a library instance to get this done... and no one else had a sample.</description>
		<content:encoded><![CDATA[<p>hmm&#8230; this looks very interesting.. I have yet to try it.. but you are bookmarked.. I too was hating the idea of a library instance to get this done&#8230; and no one else had a sample.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mira</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/comment-page-1/#comment-5</link>
		<dc:creator>mira</dc:creator>
		<pubDate>Fri, 22 Sep 2006 21:48:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/#comment-5</guid>
		<description>waarom zo&#039;n blog? en niet iets meer persoonlijks ... leef niet om te werken .. werk om te leven :)</description>
		<content:encoded><![CDATA[<p>waarom zo&#8217;n blog? en niet iets meer persoonlijks &#8230; leef niet om te werken .. werk om te leven :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

