<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

      <title>Comments on: Flash 8 / Actionscript 2.0  How do I draw dynamically in a custom class.</title>
      <link>http://ask.metafilter.com/50737/Flash-8-Actionscript-20-How-do-I-draw-dynamically-in-a-custom-class/</link>
      <description>Comments on Ask MetaFilter post Flash 8 / Actionscript 2.0  How do I draw dynamically in a custom class.</description>
	  	  <pubDate>Sun, 12 Nov 2006 15:10:19 -0800</pubDate>
      <lastBuildDate>Sun, 12 Nov 2006 15:10:19 -0800</lastBuildDate>
      <language>en-us</language>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <ttl>60</ttl>

<item>
  	<title>Question: Flash 8 / Actionscript 2.0 &#8211; How do I draw dynamically in a custom class.</title>
  	<link>http://ask.metafilter.com/50737/Flash-8-Actionscript-20-How-do-I-draw-dynamically-in-a-custom-class</link>	
  	<description>Flash 8 / Actionscript 2.0 &#8211; How do I draw dynamically in a custom class.
 &lt;br /&gt;&lt;br /&gt; First, I&#8217;m pretty new to Actionscript and I&#8217;m getting confused going between tutorials written for different versions.&lt;br&gt;
&lt;br&gt;
I&#8217;d like to create a class that when instantiated draws a shape on the screen and tracks various properties. In an ordinary .fla file I can do something like:&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
this.createEmptyMovieClip(&apos;mybox&apos;,200);&lt;br&gt;
mybox.lineStyle(0,0x00ff00);&lt;br&gt;
mybox.lineTo(50,20);&lt;br&gt;
mybox.lineTo(70,40);&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
So I&#8217;ve got the basics to drawing. So why can&#8217;t I do this:&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
class Thing extends MovieClip{&lt;br&gt;
	function Thing(){&lt;br&gt;
		this.createEmptyMovieClip(&quot;mything&quot;,200);&lt;br&gt;
		mything.lineTo(50,20);&lt;br&gt;
		mything.lineTo(70,40);&lt;br&gt;
	}&lt;br&gt;
}&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
And instantiate it from my .fla movie. My understanding is that since Thing extends MovieClip it is a MovieClip, so I should be able to create an empty movie clip inside and then draw in that.&lt;br&gt;
&lt;br&gt;
But it isn&#8217;t working. Can someone tell me what I&#8217;m doing wrong. I assume my problem is at a deeper level than just syntax, et cetera.&lt;br&gt;
&lt;br&gt;
Note, I don&#8217;t want to create a symbol in the library and attach it. I want to do the whole thing programmatically.</description>
  	<guid isPermaLink="false">post:ask.metafilter.com,2008:site.50737</guid>
  	<pubDate>Sun, 12 Nov 2006 14:51:57 -0800</pubDate>
  	<dc:creator>miniape</dc:creator>
	
	<category>flash</category>
	
	<category>actionscript</category>
	
</item>
<item>
  	<title>By: grumblebee</title>
  	<link>http://ask.metafilter.com/50737/Flash-8-Actionscript-20-How-do-I-draw-dynamically-in-a-custom-class#768716</link>	
  	<description>This will work:&lt;br&gt;
&lt;br&gt;
class Thing extends MovieClip{&lt;br&gt;
&lt;br&gt;
	function Thing(){&lt;br&gt;
&lt;br&gt;
		var mc:MovieClip = new MovieClip();&lt;br&gt;
		mc = this.createEmptyMovieClip(&amp;quot;mything&amp;quot;,200);&lt;br&gt;
		mc.lineStyle(1);&lt;br&gt;
		mc.lineTo(50,20);&lt;br&gt;
		mc.lineTo(70,40);&lt;br&gt;
&lt;br&gt;
	}&lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
Make sure you&apos;re remembering to set the Linkage... properties in the Library for the parent movieclip. Check export for actionscript and enter Thing as the AS 2.0 class.&lt;br&gt;
&lt;br&gt;
The problem with your code was that you weren&apos;t specifying mything&apos;s container object. But this.mything won&apos;t work, since mything isn&apos;t created until runtime. When the file is compiled, it looks at the constructor function and can&apos;t figure out what mything is. But the createEmptyMovieClip method returns an instance of whatever movieclip it creates. My code catches that instance in a variable (mc).</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.50737-768716</guid>
  	<pubDate>Sun, 12 Nov 2006 15:10:19 -0800</pubDate>
  	<dc:creator>grumblebee</dc:creator>
</item>
<item>
  	<title>By: grumblebee</title>
  	<link>http://ask.metafilter.com/50737/Flash-8-Actionscript-20-How-do-I-draw-dynamically-in-a-custom-class#768718</link>	
  	<description>At your leisure, you might want to read up on a OOP principle called Composition. It&apos;s an alternative to Inheritance. Using Composition, you don&apos;t extend MovieClip. Instead, your class creates a movieclip (you&apos;re halfway there, because you do use createEmptyMovieClip, but you&apos;re still subclassing MovieClip).&lt;br&gt;
&lt;br&gt;
Composition has some advantages over Inheritance (not in all cases, but in many). I&apos;m not a big fan of subclassing MovieClip, because there&apos;s no way to link a symbol to your subclass via code. You have to do that stupid linkage thing in the library. Which means you&apos;re tied to a specific class and can&apos;t change it at runtime. Composition solves that problem.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.50737-768718</guid>
  	<pubDate>Sun, 12 Nov 2006 15:13:45 -0800</pubDate>
  	<dc:creator>grumblebee</dc:creator>
</item>
<item>
  	<title>By: miniape</title>
  	<link>http://ask.metafilter.com/50737/Flash-8-Actionscript-20-How-do-I-draw-dynamically-in-a-custom-class#770153</link>	
  	<description>I just got a chance to try this and it still isn&apos;t working.&lt;br&gt;
&lt;br&gt;
This my whole swf file: motes.fla contains on frame one of layer one:&lt;br&gt;
&lt;br&gt;
var m:Mote = new Mote();&lt;br&gt;
stop();&lt;br&gt;
&lt;br&gt;
Mote.as contains this:&lt;br&gt;
&lt;br&gt;
class Mote extends MovieClip{	&lt;br&gt;
		var mc:MovieClip;&lt;br&gt;
		function Mote(){&lt;br&gt;
		mc = this.createEmptyMovieClip(&amp;quot;mymote&amp;quot;,200);	&lt;br&gt;
		mc.lineStyle(1,0x00ff00);&lt;br&gt;
		mc.lineTo(50,20);&lt;br&gt;
		mc.lineTo(70,40);&lt;br&gt;
	}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
I&apos;ve also tried it with the variable declaration inside the constructor. When I trace &apos;this&apos;, I get Object Object. When I trace &apos;mc&apos; I get undefined and nothing happens on the stage.&lt;br&gt;
&lt;br&gt;
I don&apos;t know what else to try. To me, code looks perfectly correct. Any ideas?</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.50737-770153</guid>
  	<pubDate>Mon, 13 Nov 2006 19:46:18 -0800</pubDate>
  	<dc:creator>miniape</dc:creator>
</item>
<item>
  	<title>By: grumblebee</title>
  	<link>http://ask.metafilter.com/50737/Flash-8-Actionscript-20-How-do-I-draw-dynamically-in-a-custom-class#770540</link>	
  	<description>This won&apos;t work because you have a class inside an fla. Classes can&apos;t be inside fla files. They must be in .as files. Since your class is called Mote, it most be is a file called Mote.as, and Mote.as must be saved in a valid classpath. You can define classpath in the Actionscript preferences (click the AS 2.0 button).</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.50737-770540</guid>
  	<pubDate>Tue, 14 Nov 2006 05:46:15 -0800</pubDate>
  	<dc:creator>grumblebee</dc:creator>
</item>

    </channel>
</rss>
