<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>untoldentertainment.com &#187; AS3 Pitfalls</title>
	<atom:link href="http://www.untoldentertainment.com/blog/tag/as3-pitfalls/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.untoldentertainment.com/blog</link>
	<description>We Make Flash Games</description>
	<lastBuildDate>Wed, 01 Feb 2012 15:18:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<copyright>Copyright &#xA9; untoldentertainment.com 2011 </copyright>
	<managingEditor>ryan@untoldentertainment.com (untoldentertainment.com)</managingEditor>
	<webMaster>ryan@untoldentertainment.com (untoldentertainment.com)</webMaster>
	<image>
		<url>http://www.untoldentertainment.com/blog/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
		<title>untoldentertainment.com</title>
		<link>http://www.untoldentertainment.com/blog</link>
		<width>144</width>
		<height>144</height>
	</image>
	<itunes:subtitle></itunes:subtitle>
	<itunes:summary>We Make Flash Games</itunes:summary>
	<itunes:keywords></itunes:keywords>
	<itunes:category text="Society &#38; Culture" />
	<itunes:author>untoldentertainment.com</itunes:author>
	<itunes:owner>
		<itunes:name>untoldentertainment.com</itunes:name>
		<itunes:email>ryan@untoldentertainment.com</itunes:email>
	</itunes:owner>
	<itunes:block>no</itunes:block>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.untoldentertainment.com/blog/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<item>
		<title>AS3 Pitfalls &#8211; SOUND_COMPLETE Event is Not Firing</title>
		<link>http://www.untoldentertainment.com/blog/2009/10/14/as3-pitfalls-sound_complete-event-is-not-firing/</link>
		<comments>http://www.untoldentertainment.com/blog/2009/10/14/as3-pitfalls-sound_complete-event-is-not-firing/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 00:25:22 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Video Games]]></category>

		<guid isPermaLink="false">http://www.untoldentertainment.com/blog/?p=1956</guid>
		<description><![CDATA[PROBLEM: The SOUND_COMPLETE event is not triggered when your sound finishes playing. SOLUTION: There are a few different reasons why this problem may occur, but here&#8217;s how it played out in my project: When you&#8217;re listening for a SOUND_COMPLETE event, you work with two Classes: Sound and SoundChannel. The event listener goes on the SoundChannel [...]]]></description>
			<content:encoded><![CDATA[<p><b>PROBLEM:</b></p>
<p>The SOUND_COMPLETE event is not triggered when your sound finishes playing.</p>
<p><b>SOLUTION:</b></p>
<p>There are a few different reasons why this problem may occur, but here&#8217;s how it played out in my project:</p>
<p>When you&#8217;re listening for a SOUND_COMPLETE event, you work with two Classes: Sound and SoundChannel.  The event listener goes on the SoundChannel instance:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">sound</span>:<span style="color: #0066CC;">Sound</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sound</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;allYouNeedIsLove.mp3&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> soundChannel:SoundChannel = <span style="color: #0066CC;">sound</span>.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
soundChannel.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SOUND_COMPLETE</span>, soundIsFinished<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>In my project, i rigged up a &#8220;Pause&#8221; button.  When the player clicks &#8220;Pause&#8221;, i stop the sound and take note of the Sound&#8217;s position.  When the player clicks &#8220;Pause&#8221; again, i unpause the game and tell the Sound to start playing where we left off.</p>
<p>But whenever you paused and unpaused the game, the SOUND_COMPLETE Event wouldn&#8217;t fire any more.</p>
<p>That&#8217;s because whenever you tell a Sound object to play, <em>it returns a new SoundChannel instance</em>.  The old SoundChannel instance &#8211; the one with the event listener on it &#8211; is no longer relevant, so the event doesn&#8217;t fire.  So to get this to work, when the player unpauses the game, you have to add the SOUND_COMPLETE event listener to the <em>new</em> SoundChannel instance that&#8217;s returned when you call Sound.play();</p>
<p><b>THANKS FOR BAILING ME OUT!</b></p>
<p>BIG thanks to user WearDark on the Kirupa forums for clearing this up, and for saving me from hours and hours of bug testing trying to figure out what was going on!</p>
<p>http://www.kirupa.com/forum/archive/index.php/t-263824.html</p>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F10%2F14%2Fas3-pitfalls-sound_complete-event-is-not-firing%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F10%2F14%2Fas3-pitfalls-sound_complete-event-is-not-firing%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2009/10/14/as3-pitfalls-sound_complete-event-is-not-firing/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=1956&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2009/10/14/as3-pitfalls-sound_complete-event-is-not-firing/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Tutorial: Understanding Classes in AS3 Part 3</title>
		<link>http://www.untoldentertainment.com/blog/2009/09/15/tutorial-understanding-classes-in-as3-part-3/</link>
		<comments>http://www.untoldentertainment.com/blog/2009/09/15/tutorial-understanding-classes-in-as3-part-3/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 13:39:06 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Awesomazing]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Video Games]]></category>

		<guid isPermaLink="false">http://www.untoldentertainment.com/blog/?p=1572</guid>
		<description><![CDATA[In this tutorial, learn how to identify when a chunk of code should be spun off into its own .as Class file. Trial by Flash This series of Understanding Classes tutorials chart my progress through unfamiliar Actionscript 3.0 territory. i am a designer-turned-coder, so everything i understand about code was learned in the School of [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, learn how to identify when a chunk of code should be spun off into its own .as Class file.</p>
<h2>Trial by Flash</h2>
<p>This series of Understanding Classes tutorials chart my progress through unfamiliar Actionscript 3.0 territory. i am a designer-turned-coder, so everything i understand about code was learned in the School of Hard Knocks &#8230; most often while a producer breathed down my neck and i had two weeks to program a game using concepts i didn&#8217;t grok.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_15/grokking.jpg" alt="Sgt. Slaughter"></p>
<p>Grokking is Half the Battle
</p></div>
<p>i had already learned to avoid &#8220;spaghetti code&#8221;, a common newbie Flash developer habit where you stick little bits of code on various MovieClip symbol instances and frames throughout your Flash movie.  The next step was to round up all of those little bits of spaghetti code and confine it all to the first frame of my Flash movie.  </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_15/spaghetti.jpg" alt="Baby w/ spaghetti"></p>
<p>Don&#8217;t spaghetti code. Think of the children.
</p></div>
<p>The next leg of the journey into Actionscript 3.0 was to escape the first frame, and to move all of that first-frame code into its own seprate .as Class file. That&#8217;s where <a href="http://www.untoldentertainment.com/blog/2009/08/25/tutorial-understanding-classes-in-as3-part-1/">Understanding Classes began</a>.  It seemed like a pointless step &#8211; whether the code was in its own frame or in its own Class file seemed like picky Egghead semantics.  </p>
<p>The fuzzy picture came more clearly into focus with the <a href="http://www.untoldentertainment.com/blog/2009/09/09/tutorial-understanding-classes-in-as3-part-2/">next Understanding Classes tutorial</a>, where we learned to write a custom Class to represent symbols in the Flash library.  We used the less-than-helpful example of a Dog Class to explain how to pull this off.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_15/retardedDog.jpg" alt="Retarded Dog"></p>
<p>Thanks for nothing, DOG.
</p></div>
<p>But the time for theory is over.  If we&#8217;re going to finally learn how to take full advantage of Object Oriented Programming, we need to look at some real-world examples.  In this tutorial, we&#8217;ll pick through that glob of code in our Main.as file and find places where it makes sense to group chunks of functionality and split them off into their own Class files.</p>
<h2>It&#8217;s Apparent You&#8217;re A Parent</h2>
<p>In order to understand when and where to create new Classes, you almost have to think like a parent.  All of the methods (things a Class can <em>do</em>) and properties (things a Class <em>is</em>) are your children.  As your children grow older, you want them to learn how to take care of themselves.  You (hopefully) don&#8217;t want to be changing your son&#8217;s diapers when he&#8217;s 17 years old.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_15/babyhuey.jpg" alt="Baby Huey"></p>
<p>Worst. Cartoon character. Evar.
</p></div>
<p>So when you look at that mess of code in your Main.as Class, start asking yourself this question: should this kid, this group of properties and methods, be taking care of himself?  Is this stuff that me, the Main.as Class, should be doing, or is this something that this kid can go off and do by himself?</p>
<h2>Huh?</h2>
<p>Here&#8217;s a real-world example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> myButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #006600;">label_txt</span>.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Play&quot;</span>;
			myButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickMyButton<span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OVER</span>, rollOverMyButton<span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OUT</span>, rollOutMyButton<span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #006600;">mouseChildren</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			addChild<span style="color: #66cc66;">&#40;</span>myButton<span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">150</span>;
			myButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clickMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			playGame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rollOverMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> myButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;highlight&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rollOutMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> myButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;unhighlight&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> playGame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Do some stuff here</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>In this piece of code, the Main.as file adds an instance of the MyButton Class to the stage.  When the player clicks the button, we fire the playGame method.  </p>
<p>There are some things here that the Main.as Class should probably do, and a bunch of things that the LabelButton Class should do for itself.  Let me ask you this: why on God&#8217;s green Earth should Main.as care about how the MyButton Class implements all of its MouseEvent code?  Making the button highlight on rollOver is MyButton&#8217;s responsibility, not Main.as&#8217;s responsibility.  </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_15/rollover.jpg" alt="Rollover"></p>
<p>Take care of your own rollover.
</p></div>
<p>Let&#8217;s imagine a not-too-distant future.  Robots rule the Earth.  Gary Coleman is in the White House.  And you&#8217;re writing a new Actionscript project where you need a MyButton.  The way you&#8217;ve written it here, can you easily pluck your MyButton Class out of this old project, and plunk it into your new project and expect it to work?  No!  That&#8217;s because you have code that is crucial to the functioning of your MyButton class <em>outside</em> your MyButton Class.</p>
<p>Do the clickMyButton, rollOverMyButton, and rollOutMyButton methods <em>belong</em> to Main, or do they belong to MyButton?  Let&#8217;s go back to our semi-useless Dog example.  Do bark, sniff and peeOnLeg belong to Main, or do they belong to Dog?  They belong to Dog.  So let&#8217;s put them in Dog.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_15/fatDog.jpg" alt="Fat Dog"></p>
<p>Stuff everything concerning Dog IN Dog.
</p></div>
<p>Here&#8217;s the above script with the MyButton-specific methods removed:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> myButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #006600;">label_txt</span>.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Play&quot;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>myButton<span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">150</span>;
			myButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Wow!  We really cleaned up our Main Class, didn&#8217;t we?</p>
<p>Here&#8217;s what our MyButton Class looks like.  We&#8217;ve just plucked the methods out of our Main Class and put them where they belong, in MyButton.  <em>MyButton changes its own diapers</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickMyButton<span style="color: #66cc66;">&#41;</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OVER</span>, rollOverMyButton<span style="color: #66cc66;">&#41;</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OUT</span>, rollOutMyButton<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clickMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			playGame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rollOverMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;highlight&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rollOutMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;unhighlight&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> playGame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Do some stuff here</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If you&#8217;re keen-eyed, you&#8217;ll notice that we were even able to cut down the code when we moved it to the MyButton Class.  Instead of saying <b>myButton.addEventListener(MouseEvent.CLICK, clickMyButton);</b>, we can drop the &#8220;myButton&#8221; part and just say <b>addEventListener(MouseEvent.CLICK, clickMyButton);</b>.  That&#8217;s essentially the same as saying <b>this.addEventListener(MouseEvent.CLICK, clickMyButton);</b>.  The &#8220;this&#8221; keyword is like saying &#8220;me&#8221;.  We&#8217;re <em>inside</em> the MyButton world, so we&#8217;re referring to ourselves.  While we are writing code inside the MyButton class, we <em>are</em> MyButton.</p>
<h2>Starting an Argumemt</h2>
<p>Now what about that line in Main.as where we label the button?</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myButton.<span style="color: #006600;">label_txt</span>.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Play&quot;</span>;</pre></div></div>

<p>Is labelling the button a responsibility of Main.as, or a responsibility of MyButton.as?  The answer is slightly tricky.</p>
<p>MyButton might not always be labelled &#8220;Play&#8221;.  We could (and should) think generically, so that MyButton could be labelled &#8220;Play&#8221; or &#8220;New Game&#8221; or &#8220;Change Character&#8221; or whatever.  So Main.as should be responsible for labelling the button, right?</p>
<p>Not exactly.  MyButton should still be responsible for labelling itself. But Main.as should be responsible for deciding what that label says. That way, Main could create buttons that say &#8220;Play&#8221;, &#8220;New Game&#8221; and &#8220;Change Character&#8221;,all using the same MyButton Class.  The MyButton Class takes care of all the logic of actually displaying that text on itself.</p>
<p>To pull this off, we pass a <em>parameter</em> to our MyButton Class from Main.as.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> myButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Play&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Check it out!!!</span>
			addChild<span style="color: #66cc66;">&#40;</span>myButton<span style="color: #66cc66;">&#41;</span>;
			myButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">150</span>;
			myButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Main.as creates a new MyButton instance (stamp, copy), and <em>passes</em> something called a parameter to the MyButton Class.  MyButton grabs that parameter and uses it to label itself.</p>
<p>Note: if you&#8217;re fuzzy on the concept of datatypes (String, Number, Int, Boolean, etc), you may already be in over your head.  Go read a basic tutorial on datatypes, and come on back.</p>
<p>Here&#8217;s the MyButton Class, now modified to grab that parameter from Main.as (or whatever Class instantiates [makes a stamp of, makes a copy of] the MyButton class).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyButton<span style="color: #66cc66;">&#40;</span>labelName:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			label_txt.<span style="color: #0066CC;">text</span> = labelName; <span style="color: #808080; font-style: italic;">// Grab that parameter and label myself!</span>
&nbsp;
			addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickMyButton<span style="color: #66cc66;">&#41;</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OVER</span>, rollOverMyButton<span style="color: #66cc66;">&#41;</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OUT</span>, rollOutMyButton<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clickMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			playGame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rollOverMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;highlight&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rollOutMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;unhighlight&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> playGame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Do some stuff here</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Beautiful!  In this line, we accept a parameter:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyButton<span style="color: #66cc66;">&#40;</span>labelName:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>And in this line, we grab that parameter and use it to label ourselves:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">label_txt.<span style="color: #0066CC;">text</span> = labelName; <span style="color: #808080; font-style: italic;">// Grab that parameter and label myself!</span></pre></div></div>

<h2>Jockeying for Position</h2>
<p>Finally, we&#8217;ll talk about the x/y lines in the Main Class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">150</span>;
myButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;</pre></div></div>

<p>Is that something that Main should be responsible for, or something that MyButton should be responsible for? x and y are properties of MyButton, so MyButton should handle them, right?</p>
<p>Not so fast!  While we <em>could</em> let MyButton position itself, it wouldn&#8217;t make sense to.  The Class that needs a MyButton should decide where on the screen the button should go.  Otherwise, every time we create a new MyButton instance, it&#8217;ll appear in the same place on the screen.  Not so hot.  Main.as should take care of positioning the button instance.</p>
<h2>Real Ultimate Power</h2>
<p>Et voila!  We&#8217;re in good shape now.  We&#8217;ve:</p>
<ol>
<li>Identified a chunk of code that should change its own diapers
<li>Moved that code to its own .as Class file
<li>Thought generically about how an instance (stamp, copy) of that Class should be treated
</ol>
<p>Now, check out the glorious wonderland we can experience and enjoy:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Instantiate a new play button:</span>
			<span style="color: #000000; font-weight: bold;">var</span> myPlayButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Play&quot;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>myPlayButton<span style="color: #66cc66;">&#41;</span>;
			myPlayButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">150</span>;
			myPlayButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Instantiate a new instructions button:</span>
			<span style="color: #000000; font-weight: bold;">var</span> myInstructionsButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Instructions&quot;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>myInstructionsButton<span style="color: #66cc66;">&#41;</span>;
			myInstructionsButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">210</span>;
			myInstructionsButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Instantiate a new credits button:</span>
			<span style="color: #000000; font-weight: bold;">var</span> myCreditsButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Credits&quot;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>myCreditsButton<span style="color: #66cc66;">&#41;</span>;
			myCreditsButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">340</span>;
			myCreditsButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Wowee!  THREE new button instances in half the code it took to have ONE button when we first started out.</p>
<p>We&#8217;re almost out of the woods.  But there&#8217;s one nagging thing remaining.  Notice that we have a method in the MyButton Class that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clickMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	playGame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Should MyButton decide what happens when it gets clicked?  We saw that the Main.as Class can quickly create three instances of MyButton &#8211; a Play button, an Instructions button, and a Credits button.  These three buttons are all going to do different things when the player clicks them.  So the generic MyButton Class cannot possibly define its own click behaviour.  Main.as is going to have to decide.</p>
<p>Let&#8217;s yank that click code right out of the MyButton Class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyButton<span style="color: #66cc66;">&#40;</span>labelName:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			label_txt.<span style="color: #0066CC;">text</span> = labelName; <span style="color: #808080; font-style: italic;">// Grab that parameter and label myself!</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// this is where the MouseEvent.CLICK listener used to be</span>
&nbsp;
			addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OVER</span>, rollOverMyButton<span style="color: #66cc66;">&#41;</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OUT</span>, rollOutMyButton<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rollOverMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;highlight&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rollOutMyButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;unhighlight&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And instead, we&#8217;ll write the listener for each button&#8217;s MouseEvent.CLICK in the Main.as Class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Instantiate a new play button:</span>
			<span style="color: #000000; font-weight: bold;">var</span> myPlayButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Play&quot;</span><span style="color: #66cc66;">&#41;</span>;
			myPlayButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickBtnPlay<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// new line!</span>
			addChild<span style="color: #66cc66;">&#40;</span>myPlayButton<span style="color: #66cc66;">&#41;</span>;
			myPlayButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">150</span>;
			myPlayButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Instantiate a new instructions button:</span>
			<span style="color: #000000; font-weight: bold;">var</span> myInstructionsButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Instructions&quot;</span><span style="color: #66cc66;">&#41;</span>;
			myInstructionsButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickBtnInstructions<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// new line!</span>
			addChild<span style="color: #66cc66;">&#40;</span>myInstructionsButton<span style="color: #66cc66;">&#41;</span>;
			myInstructionsButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">210</span>;
			myInstructionsButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Instantiate a new credits button:</span>
			<span style="color: #000000; font-weight: bold;">var</span> myCreditsButton:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Credits&quot;</span><span style="color: #66cc66;">&#41;</span>;
			myCreditsButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickBtnCredits<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// new line!</span>
			addChild<span style="color: #66cc66;">&#40;</span>myCreditsButton<span style="color: #66cc66;">&#41;</span>;
			myCreditsButton.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">340</span>;
			myCreditsButton.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">89</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clickBtnPlay<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Play the game</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clickBtnInstructions<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Show the instructions</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clickBtnCredits<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Show the credits</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And there you have it.  The MyButton Class takes care of its own diapers.  It labels itself based on a parameter that&#8217;s passed to it.  It handles its own rollOver and rollOut events.  Main.as takes care of creating instances (stamps, copies) of the MyButton Class. Main.as decides:</p>
<ul>
<li>What the button label will say
<li>How the button will be positioned on the screen
<li>What the button does when clicked
</ul>
<h2>The First of Many</h2>
<p>That&#8217;s a real-world example of where and when it makes sense to collect your code in a separate Actionscript Class file.  Of course, this is just one example in an endless sea of possiblilities.  The general rule is that if the code should be changing its own diapers, it should be in its own Class file. And if the code can be written generally so that it can be re-used, you&#8217;re ahead of the game.  </p>
<p>The mystery that springs up from all of this is the OOP rule of Encapsulation, which states that you should write your Classes so that they&#8217;re self-contained and self-reliant. Not only do they change their own diapers, but they rent their own apartment and cook meals for themselves, with no reliance on outside Classes whatsoever to live.  </p>
<p>There are advantages and disadvantages to Encapsulation, which we can look at in our next Understanding Classes tutorial.  The biggest disadvantage is that to create a truly encapsulated Class, you have to write an ASSLOAD of repetetive Actionscript 3 code.  i&#8217;ll show you a cheat that&#8217;ll break the encapsulation rule, but will save you HOURS of coding.  The Eggheads will have my head for it, so let&#8217;s just keep it between you and me.</p>
<p>For more tips, tricks and tutorials on Flash and Actionscript, check out our <a href="http://www.untoldentertainment.com/blog/flash-and-actionscript-911/">Flash and Actionscript 911</a> feature.
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F09%2F15%2Ftutorial-understanding-classes-in-as3-part-3%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F09%2F15%2Ftutorial-understanding-classes-in-as3-part-3%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2009/09/15/tutorial-understanding-classes-in-as3-part-3/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=1572&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2009/09/15/tutorial-understanding-classes-in-as3-part-3/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Saved Game (a Kindisoft secureSWF Review)</title>
		<link>http://www.untoldentertainment.com/blog/2009/09/11/saved-game-a-kindisoft-secureswf-review/</link>
		<comments>http://www.untoldentertainment.com/blog/2009/09/11/saved-game-a-kindisoft-secureswf-review/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 13:59:14 +0000</pubDate>
		<dc:creator>jeff</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Video Games]]></category>

		<guid isPermaLink="false">http://www.untoldentertainment.com/blog/?p=1667</guid>
		<description><![CDATA[Full Disclosure: This is a paid review. We are receiving a free license of Kindisoft secureSWF in exchange for evaluating the product and posting our opinion. This has not necessarily effected a positive or negative review; while a post can be bought, our favourable opinion comes at a higher price. (That price, incidentally, is one [...]]]></description>
			<content:encoded><![CDATA[<p><b>Full Disclosure:</b> This is a paid review.  We are receiving a free license of <a href="http://www.kindisoft.com/">Kindisoft secureSWF</a> in exchange for evaluating the product and posting our opinion.  This has not necessarily effected a positive or negative review; while a post can be bought, our favourable opinion comes at a higher price.  (That price, incidentally, is one large basket of Peek Frean&#8217;s chocolate Bourbon Cream cookies, a variety of points cards for leading video game consoles, a 1-year subscription to <a href="http://www.gamesmagazine-online.com/">Games Magazine</a>,  and a commercial-grade Sno Kone machine.) </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/bourbonCream.jpg" alt="Bourbon Cream Cookies"></p>
<p>i would give WISDOM TOOTH EXTRACTION a positive review for a basket of these babies
</p></div>
<p>What follows is a review by Jeff Gold (<a href="http://www.untoldentertainment.com/boards/memberlist.php?mode=viewprofile&#038;u=55">ue_jeff</a>), our indomitable Game Developer and Keeper of All AS3 Knowledge. </p>
<h2>From the Mouths of Jeffs</h2>
<p>Today I set out to evaluate Kindisoft secureSWF, a product designed to help Flash / Flex developers secure and obscure their flash content from prying eyes. Thanks to several products on the market today (I am going to use <a href="http://www.sothink.com/product/flashdecompiler/">SoThink SWF Decompiler</a> as my point of reference here) it is possible, and quite easy, to open up Flash content found online to view and re-use all of the file&#8217;s source code and art assets. There are many reasons why developers would not want their files being decompiled this way. Theft of ActionScript code, theft of art assets, and hacking of controlled systems are just three.</p>
<p>Log in to the MochiMedia community forums and read <a href="https://www.mochimedia.com/community/forum/topic/game-hacked#0">this post</a> about how one developer&#8217;s game was completely ripped off by someone with a swf opener:</p>
<blockquote><p>psyon<br />
Sep 07, 2009</p>
<p>On of my puzzle games was hacked. The person replaced my site logos, but apparently left my mochibot code in place, so I can see where all the hacked copies are. Anyone familiar with the site OyunKolu.com ?</p></blockquote>
<p>SecureSwf was recommended to us by a number of our Twitter friends, including Chris Hughes from <a href="http://www.flashgamelicense.com/">Flash Game License</a>/<a href="https://www.gamersafe.com/">GamerSafe</a>.  We had been evaluating other encryption software  (most notably <a href="http://www.amayeta.com/software/swfencrypt/">Amayeta SWF Encrypt 6.0</a>) and were not entirely impressed with the Actionscript 3 code obfuscation. With Amayeta&#8217;s product, I found that using anything but the most minimal settings made my swf report many errors.  </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/robot.jpg" alt="Old School Robot"></p>
<p>ERROR!  ERROR!  DOES NOT COMPILE!
</p></div>
<h2>That New Software Smell</h2>
<p>Upon opening SecureSWF I immediately noticed many options compared to the other products we had tried. </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/standard_setup.jpg" alt="secureSWF standard setup"></p>
</div>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/simple_app.jpg" alt="A simple charting app that we used in Interrupting Cow Trivia"></p>
<p>Our first victim: a pie chart swf that we use in <b><a href="http://www.untoldentertainment.com/blog/2009/06/19/interrupting-cow-trivia-alpha/">Interrupting Cow Trivia</a></b>
</div>
<p>Being momentarily overwhelmed by all the panels in front of me I decided to just try out the default configuration. On the first simple swf I tried to encrypt, the default configuration worked quite well causing no errors while running the swf.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/default_settings.jpg" alt="secureSWF default settings"></p>
<p>secureSWF&#8217;s default settings
</p></div>
<p>Immediately after encrypting my first swf with Swf Encrypt, I busted out my swf decompiler to see the results. Decompiling the swf was still possible ( I think this will be the case with any swf encryption ) , but inspecting the extracted code I could see a fair deal of obfuscation had occurred. (<em>Obfuscation</em> Translation: Code is EFFED-UP.  &#8211; Ryan)  With the default settings, Class names, function names, and class variables are obscured to things such as &#8220;_-V&#8221; or &#8220;_-02&#8243;, making the code very hard &#8211; but not impossible &#8211; to follow. I did notice immediately that variables scoped in functions were not obscured , but were left as var _loc_1 , var _loc_2 etc. as the compiler defines them (which I suppose is already obscure). </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/code_none.jpg" alt="before secureSWF"></p>
<p>Before secureSWF &#8230;
</p></div>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/code_default.jpg" alt="before secureSWF"></p>
<p>&#8230; After secureSWF.
</p></div>
<h2>Giving It Some Welly</h2>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/upTo11.jpg" alt="This one goes to 11"></p>
</div>
<p>My next step was to crank up the security settings on the same simple swf. This time around I went to protection options and checked &#8220;Statement-level Randomization&#8221;, Maxed out &#8220;Control Flow Obfuscation&#8221; and &#8220;Dynamic Code Wrapping&#8221;, and checked &#8220;Break function Calls&#8221;.  Honestly I am not 100% sure what all these things are doing, but I just went for overkill settings.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/cranked_settings.jpg" alt="secureSWF cranked settings"></p>
<p>Overkill settings.
</p></div>
<p>The swf still managed to run without any errors, and like last time I was still able to decompile the swf. Taking a look at the code again I immediately noticed quite a bit more obfuscation at the function level, and the code seemed more verbose and harder to follow. </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/code_none.jpg" alt="before secureSWF"></p>
<p>Again, the same code before secureSWF &#8230;
</p></div>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/code_max.jpg" alt="secureSWF max settings"></p>
<p>.. and after, with settings cranked to the max.
</p></div>
<h2>Enter the Cow</h2>
<p>So after my successful runs on a simple application, I tried to run a complex application through the process (<b><a href="http://www.untoldentertainment.com/blog/2009/06/19/interrupting-cow-trivia-alpha/">Interrupting Cow Trivia</a></b>, our real-time multiplayer trivia game) once again with default settings. At first the swf seemed to work with no errors, but after doing some stress testing I did notice few issues.  After about 20 minutes of tinkering with the many settings available I figured out the culprit: &#8220;Control Flow Obfuscation&#8221;. Turning this one option off and then cranking all the other options managed to produce a 100% functional swf for me, and after decompiling I could not discern much difference from with the option on.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_10/cow.jpg" alt="Spot the difference"</p>
<p>Spot the difference.
</p></div>
<p>secureSWF has some other interesting features that I had not seen in other products (but, to be fair, I haven’t tried <em>every</em> competing product).  These features include &#8220;Encrypted domain locking&#8221; and &#8220;Literal String Encryption&#8221;. I am not sure how the encrypted domain locking works , but it is a nice option and saves you from having to setup your own site locking in ActionScript each time. (Site-locking prevents your swf from being played on any domain other than the one[s] you specify.)</p>
<p>Literal String Encryption is another nice feature as it allows you to encrypt potentially sensitive text in your code. By default, strings will not be encrypted and will be perfectly readable when the code is decompiled. I am sure this process could be reverse engineered by digging through the code, but either way it just adds another barrier to the hacker to keep him from messing with your work.</p>
<p>Overall, Kindisoft secureSWF seems to be a solid product with lots of customizable features &#8211; far more than its competitors &#8211; that we plan to take advantage of for current and future projects.</p>
<h2>End Jeff Transmission</h2>
<p><b>Ryan:</b> Of course, swf encryption is just one side of the story.  If you have a game that posts information to your server to store high score data, to save games, etc, it&#8217;s important to know that all that stuff is wide open.  Just grab <a href="http://fiddler2.com/fiddler/version.asp">Fiddler</a>, a &#8220;web debugging proxy&#8221;, and run it while you play any game that makes server calls.  With an unprotected game, you&#8217;ll be able to sniff out the exact asp or php page where scores are being posted, and you can use that info to trick the server into posting a high score for you.  You can also use an app called <a href="http://cheatengine.org/">Cheat Engine</a> to wreak serious havoc with an online game, Flash or otherwise.  Here&#8217;s how:</p>
<p><center><br />
<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/dLO2s7SDHJo&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/dLO2s7SDHJo&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object><br />
</center></p>
<p>You may be wondering why, for the love of all that is Holy, we would be linking to movies and products about how to hack Flash games in a review of encryption software.  It&#8217;s to illustrate the point that no protection solution is 100% effective (which is also why i have two children running around my house).  Another saying i really like is &#8220;locks keep the honest people out&#8221;.</p>
<p>You&#8217;ll never make your game immune to hacking, but you can throw so many locks and contrivances in the way that it might take some serious skill to unlock them &#8230; and it follows that anyone with enough haxxor skillz to get through all those locks has something better to do with his considerable talents than to post a high score to your free-to-play Escape the Room game.  </p>
<h2>Win a Copy of secureSWF</h2>
<p>Kindisoft is offering a 25% discount on secureSWF through various Flash game development sites, including <a href="http://www.flashgamelicense.com/sponsor_pages/kindisoft.php">FlashGameLicense</a>.</p>
<p>For more articles about Flash and Actionscript, check out our <a href="http://www.untoldentertainment.com/blog/flash-and-actionscript-911/">Flash and Actionscript 911</a> feature.</p>
<p>Moo.</p>
<p><center><br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_blog_promo_bar_423131868"
			class="flashmovie"
			width="545"
			height="185">
	<param name="movie" value="http://www.untoldentertainment.com/games/interruptingCowTrivia/img/promo/blog_promo_bar.swf" />
	<param name="wmode" value="transparent" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.untoldentertainment.com/games/interruptingCowTrivia/img/promo/blog_promo_bar.swf"
			name="fm_blog_promo_bar_423131868"
			width="545"
			height="185">
		<param name="wmode" value="transparent" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
</center></p>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F09%2F11%2Fsaved-game-a-kindisoft-secureswf-review%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F09%2F11%2Fsaved-game-a-kindisoft-secureswf-review%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2009/09/11/saved-game-a-kindisoft-secureswf-review/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=1667&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2009/09/11/saved-game-a-kindisoft-secureswf-review/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Tutorial: Understanding Classes in AS3 Part 2</title>
		<link>http://www.untoldentertainment.com/blog/2009/09/09/tutorial-understanding-classes-in-as3-part-2/</link>
		<comments>http://www.untoldentertainment.com/blog/2009/09/09/tutorial-understanding-classes-in-as3-part-2/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 13:42:14 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Awesomazing]]></category>
		<category><![CDATA[CS4]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Video Games]]></category>

		<guid isPermaLink="false">http://www.untoldentertainment.com/blog/?p=1661</guid>
		<description><![CDATA[In our first thrilling look at Understanding Classes in Actionscript 3.0, we talked about how Classes are structured, and how you can make that leap from stashing all your code in the first frame of your Flash movie like an IT chipmunk, to moving your code to its own Class. I promised that in Part [...]]]></description>
			<content:encoded><![CDATA[<p>In our first thrilling look at <a href="http://www.untoldentertainment.com/blog/2009/08/25/tutorial-understanding-classes-in-as3-part-1/">Understanding Classes in Actionscript 3.0</a>, we talked about how Classes are structured, and how you can make that leap from stashing all your code in the first frame of your Flash movie like an IT chipmunk, to moving your code to its own Class.</p>
<p>I promised that in Part 2, we’d learn how to identify chunks of code that should be moved into their own Classes.  But before we do that, it’s important to talk about what a Class <em>is</em>.  And if you haven’t learned how to extend a MovieClip symbol in your library to write a Class around it, this tutorial is for you!</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/egg.jpg" alt="Take THAT, eggheads"></p>
</div>
<p><b>Disclaimer</b> Dear Eggheads: This tutorial is between me, a designer-turned-coder, and readers who want to learn more about Actionscript programming who likely are not Computer Science graduates.  The terminology i use may not be 100% accurate, and some of the things i say may inflame your nerd rage and your unwavering demand for technical accuracy.  But this article is not for you.  Stop reading now. Go write some slash fiction about Captain Kirk totally doing it with the dog from Battlestar Galactica, and leave us alone to learn.</p>
<h2>OOP: There It Is</h2>
<p>A Class is an element of OOP – Object Oriented Programming.  OOP is a flavour of coding where different objects – or <em>things</em> &#8211; interact with each other to solve a problem.  If you’re a game programmer, the problem can be described as “How do i make a fun, functional zombie game?”  The word “object” is synonymous with “Class”.  You could say that Actionscript 3.0 is a <em>Class Oriented Programming</em> language, but the eggheads would stab you in the face.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/nerdRage.jpg" alt="She-Nerd"></p>
<p>She-Nerd SMASH!!
</p></div>
<p>So a Class is a <em>thing</em> &#8211; a chunk, a morsel, a <em>module</em> of code.   By writing your Classes the &#8220;right&#8221; way, you’ll find you can re-use Classes from project to project.  By writing them the &#8220;wrong&#8221; way, you’ll still probably wind up with a project that has nice, well-organized code that makes sense if you re-visit it a year later.  </p>
<p>The three principles or rules to follow if you want to maximize the advantages  of OOP are <b>encapsulation</b>, <b>inheritance</b> and <b>polymorphism</b>.  We’ll be taking a brief, gentle look at <b>inheritance</b> in this tutorial, because i think it’s the easiest to understand when you’re starting out.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/twins.jpg" alt="Inbred Twins"></p>
<p>Herbert n&#8217; Zed inherit their genes from their paw n&#8217; their sis
</p></div>
<p>Classes contain methods and properties.  (Another word for &#8220;method&#8221; is &#8220;function&#8221; or &#8220;behaviour&#8221;.  Another word for &#8220;property&#8221; is &#8220;field&#8221;.)  A method is something a Class can <em>do</em>.  A property is something a Class <em>is</em>.<br />
Let’s explain this somewhat better by using a crappy example that a lot of OOP tutorials use.  You have a Class called “Dog”.   Methods of Dog – things that Dog can <em>do</em> &#8211; include:</p>
<ul>
<li>bark
<li>sniff
<li>humpLeg
</ul>
<p>Properties of Dog &#8211; things that dog <em>is</em> &#8211; include:</p>
<ul>
<li>color
<li>breed
<li>favouriteTreat
</ul>
<p>Another way to think of it is that methods are verbs, and properties are adjectives.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/uglyDog.jpg" alt="Ugly Dog"></p>
<p>The OOP Dog example rears its ugly head
</p></div>
<h2>Let&#8217;s Get Real</h2>
<p>The Dog example is almost entirely useless to us as programmers. In all my years of experience, i have never written a Dog Class.  But i HAVE written my fair share of music and movie players in Flash.  Let&#8217;s look at the methods and properties of a media player.</p>
<p>Methods of our MediaPlayer Class &#8211; things that a media player can <em>do</em> &#8211; include:</p>
<ul>
<li>play
<li>pause
<li>stop
<li>scrub
<li>changeVolume
<li>loadMedia
</ul>
<p>Properties of our MediaPlayer Class &#8211; things that a media player <em>is</em>, or things that describe its <em>state</em> &#8211; include:</p>
<ul>
<li>isPaused
<li>songDuration (or movieDuration)
<li>isFullScreen
<li>volume
</ul>
<p>Note that the <em>method</em> &#8220;changeVolume&#8221; probably changes the <em>property</em> &#8220;volume&#8221;.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/snowths.jpg" alt="Snowths"></p>
<p>We&#8217;re gonna need a method called &#8220;turnVolumeWayWayUp&#8221;
</p></div>
<h2>You&#8217;re Already an Expert</h2>
<p>The good news is that as a Flash developer, you’ve been using Classes this whole time, though you may not have known it.  A MovieClip is a Class.  It has methods and properties.  Let&#8217;s look at some of the methods of a MovieClip &#8211; things a MovieClip can <em>do</em>:</p>
<ul>
<li>gotoAndPlay
<li>stop
<li>hitTestPoint (determine whether a point is colliding with me)
</ul>
<p>And some properties of a MovieClip &#8211; things a MovieClip <em>is</em> (or things that describe its <em>state</em>):</p>
<ul>
<li>x and y
<li>alpha
<li>rotation
</ul>
<p>Eggheads: Are you still reading this?  i told you to take a hike. Don&#8217;t jump down my throat.  i know that a few of these methods and properties actually belong to Classes that MovieClip <em>inherits</em> from, but we&#8217;re just learning, alright?  Leave us alone.  Go out and LARP or something.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/larp.jpg" alt="LARP"></p>
</div>
<h2>No Pain, No Awesome</h2>
<p>Just as you can make the leap from stowing all your code in the first frame of your movie to putting it in an .as Class file, you can (and should) make the leap from having all of your MovieClip instances &#8220;physically&#8221; present on your stage, to keeping them in the library and drawing them to the stage using code.  There are many advantages to using a code-only approach which probably won&#8217;t become clear to you until you go through the excrutiating growing pains of &#8220;WHY THE HELL AM I DOING IT THIS WAY??&#8221; like i did.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/growingPains.jpg" alt="Growing Pains"></p>
<p>Growing Pains: excrutiating
</p></div>
<p>So create a MovieClip in your library.  NOTE: If you don&#8217;t know how to do this, you may already be in over your head.  Go check out a beginner Flash tutorial and come on back.</p>
<p>In order for you to make the MovieClip available to you through code, you need to give it a linkage name. Here&#8217;s how:</p>
<ol>
<li>Open your Library (CTRL+L)
<li>Right-click the MovieClip symbol
<li>In Flash CS3, choose &#8220;Linkage&#8221;.  In Flash CS4, choose &#8220;Propeties&#8221;.
<li>Check the box that says &#8220;Export for ActionScript&#8221;
<li>In the &#8220;Class:&#8221; field, type a logical name for your MovieClip.  It&#8217;s best practice to start this name with a capital letter.  Don&#8217;t use any spaces &#8211; capitalize each new word SoThatItLooksLikeThis.  (This is called &#8220;Pascal case&#8221;)
<li>Click &#8220;OK&#8221;
<li>If you are a Mac user, and you&#8217;re saying &#8220;What&#8217;s a CTRL??  What&#8217;s a right mouse button?? i&#8217;m freaking OUT, man!&#8221;, go buy a PC  ;)
</ol>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/linkageCS3.jpg" alt="Linkage CS3"></p>
<p>Setting linkage for a library item in Flash CS3 &#8230;
</p></div>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/linkageCS4.jpg" alt="Linkage CS4"></p>
<p>&#8230; and in Flash CS4.
</p></div>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/linkageName.jpg" alt="Linkage Name"></p>
<p>Choosing a linkage name
</p></div>
<p>Did you notice, before you hit OK, that there was a field labelled &#8220;Base Class:&#8221; that said &#8220;flash.display.MovieClip&#8221;?  If this is your first time creating a library linkage, or if it&#8217;s old hat and you&#8217;ve never noticed this field, prepare to <em>blow your own mind</em>: you&#8217;ve just used the first principle of OOP &#8211; <em>inheritance</em>.  </p>
<h2>My Mind Done Blow&#8217;d Up</h2>
<p>Here&#8217;s what&#8217;s going on behind the scenes. &#8220;MovieClip&#8221; is a built-in Class that the creators of Actionscript wrote. When you give your library item a linkage name, you are actually subclassing, or <em>inheriting</em>, from the MovieClip Class.  That means that your new Class &#8220;Dog&#8221; or &#8220;MediaPlayer&#8221; or &#8220;EnemySpaceship&#8221; can now do all the stuff that a MovieClip can do.  It can <b>gotoAndPlay</b>, it can <b>stop</b>, it can <b>hitTestPoint</b>, etc.  It also inherits all of MovieClip&#8217;s properties &#8211; <b>x</b> and <b>y</b>, <b>alpha</b>, <b>rotation</b>, etc. &#8211; things that a MovieClip <em>is</em>, things that describe its <em>state</em>.</p>
<p>So now we&#8217;re getting to the point.  When you create a library linkage like this, Flash is automagically creating a new Class (&#8220;Dog&#8221;, &#8220;MediaPlayer&#8221;, whatever).  You don&#8217;t have to write it.  But you CAN write it, if you want to.  And since that&#8217;s what this tutorial is all about, then oh yes &#8211; we want to.</p>
<h2>Oh Yes &#8211; Let&#8217;s</h2>
<p>Start a new .as Class file.  You can do it in the Flash IDE, you can write it with Notepad or Notepad ++ or any other text editor.  i highly recommend Flash Develop.   Remember our <a href="http://www.untoldentertainment.com/blog/2009/08/25/tutorial-understanding-classes-in-as3-part-1/">first Understanding Classes tutorial</a>? Here&#8217;s the structure of a Class:</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/AS3ClassStructure.jpg" alt="AS3 Class Structure"></p>
<p>i chose these colours from Arsenio Hall&#8217;s wardrobe
</p></div>
<p>So here&#8217;s what our empty Class code should look like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>; <span style="color: #808080; font-style: italic;">// Import statement(s)</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Dog <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// Class definition</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> isBarking:<span style="color: #0066CC;">Boolean</span>; <span style="color: #808080; font-style: italic;">// Instance variable(s)</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Dog<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Constructor function</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;i am a dog&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// Other functions</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> bark<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			isBarking = <span style="color: #000000; font-weight: bold;">true</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> stopBarking<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			isBarking = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Let&#8217;s take note of a few important things.</p>
<ol>
<li>i&#8217;m calling my Class &#8220;Dog&#8221;.  That&#8217;s because the linkage name in used in the Flash library was &#8220;Dog&#8221;.  Note: not &#8220;dog&#8221; or &#8220;DogClip&#8221; or anything.  D-o-g.  Same capitalization, exact same name.
<li>And note that the linkage name can be <em>completely different</em> from the library symbol name.  My library symbol could be called &#8220;This is a thing what i created in teh Flashs&#8221;.  Doesn&#8217;t matter.  Actionscript can&#8217;t &#8220;see&#8221; the library item name.  It can only &#8220;see&#8221; the linkage name.
<li>Finally, remember that the Class file name has to be the same as the Class name.  If our Class is called <b>Dog</b>, we save the file as <b>Dog.as</b>.  Pull any other shenanigans, and you&#8217;ll get errors.
</ol>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_09_09/sillyDog.jpg" alt="Silly dog"></p>
<p>i SAID &#8220;no shenanigans&#8221;, DOG
</p></div>
<p>i mentioned mysteriously in the last tutorial that the word &#8220;extends&#8221; is an inheritance word.  When you create a linkage name in the library, Flash automagically writes a Class for you, and automagically <em>extends</em> (inherits from) MovieClip.  Now that we&#8217;re writing the Class ourselves, nothing is automagic.  We have to explicitly say that Dog (or whatever) extends (inherits from) the MovieClip Class.  When this is all done correctly, Flash understands that there is a connection between the linked library Class &#8220;Dog&#8221;, and the &#8220;Dog.as&#8221; Class we just wrote.</p>
<p>You may or may not know the code for dynamically placing a linked library item on the stage.  Here it is, using Dog as the example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> dog:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> Dog<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  <span style="color: #808080; font-style: italic;">// or var dog:Dog = new Dog();</span>
addChild<span style="color: #66cc66;">&#40;</span>dog<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>&#8220;BUT WAIT!&#8221;, you say. &#8220;I THOUGHT DOG HAD TO START WITH A CAPITAL LETTER??&#8221;  Okay, first of all, stop yelling. Lower-case &#8220;dog&#8221; is the name of the variable that contains an instance (a stamp, a copy) of our master Dog Class.  We could use &#8220;dog1&#8243;, &#8220;dog2&#8243;, or even &#8220;thisIsACopyOfDog&#8221;.</p>
<p>When you addChild(dog), you add your instance (stamp, copy) of the Dog Class to the list of things for Flash to draw to the stage (the viewable area that the player sees).</p>
<p>To confirm that your custom library Class is working, test your movie.  You should see the trace action &#8220;i am a dog&#8221; in the Output window. (Press F2 to see the Output window &#8211; the trace action won&#8217;t appear on the stage)</p>
<h2>What&#8217;s the Point?</h2>
<p>You may be wondering why we went through all of this agony.  The easy way is just to draw a dog and make it a MovieClip, and then leave it on the stage.  There are many, many advantages to what we&#8217;ve just done.  Let me list a few:</p>
<ul>
<li>You can now add as many Dogs to the stage as you like <em>dynamically</em>. Until now, you had to add them by hand.  If you needed another dog, you (the creator) had to drag one out of the library.  Now you can create an &#8220;Add Dog&#8221; button. When the player presses it at run-time, your code dynamically places dogs on the stage.  Now the code is doing the work, not you.
<li>We&#8217;re edging closer to the next OOP principle, <em>encapsulation</em>.  Within our Dog class, we can store methods (things that a Dog <em>does</em>) and properties (things that a Dog <em>is</em>).  Every time we initialize (make a stamp or copy of) Dog, Dog can run a bunch of Dog-specific setup routines:  initializeSenseOfSmell, testBarkTone, prepareToChewShoes.  If you do it &#8220;right&#8221;, you&#8217;ve created a self-reliant, self-contained Class.  Now every time you have a project that needs a Dog (or a MediaPlayer, an ImageGallery, a CountdownClock), you can just copy that .as Class file to a new project. If you&#8217;ve done everything &#8220;right&#8221;, it&#8217;ll just <em>work</em>.
<li>The more you start abstracting your thinking, the more you&#8217;ll be able to write generic Classes that do a number of different jobs.  You might not have another project that needs a Dog, but your generic Animal Class would still do the trick.
<li>There&#8217;s a problem that Actionscript 3 introduced where you can&#8217;t always access certain pieces of MovieClips until they&#8217;re drawn to the screen.  Writing a custom Class for your library elements can overcome this problem.
</ul>
<h2>What&#8217;s Next?</h2>
<p>Moving your frame code to an .as Class file was the first step. Learning how to write custom Classes for your linked library items is the next step, since it builds on (hopefully) familiar MovieClip territory and your existing knowledge.  In the next tutorial, we&#8217;ll take a look at that big wad of code in your Main.as file and try to figure out which methods and properties can be logically grouped and moved into their own Classes.</p>
<p>For more tips, tricks and tutorials, check out our <b><a href="http://www.untoldentertainment.com/blog/flash-and-actionscript-911/">Flash and Actionscript 911</a></b> feature.</p>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F09%2F09%2Ftutorial-understanding-classes-in-as3-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F09%2F09%2Ftutorial-understanding-classes-in-as3-part-2%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2009/09/09/tutorial-understanding-classes-in-as3-part-2/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=1661&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2009/09/09/tutorial-understanding-classes-in-as3-part-2/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls &#8211; stop(); Action Ignored on Nested Movieclip</title>
		<link>http://www.untoldentertainment.com/blog/2008/10/23/cs3-pitfalls-stop-action-ignored-on-nested-movieclip/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/10/23/cs3-pitfalls-stop-action-ignored-on-nested-movieclip/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 20:09:42 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/?p=185</guid>
		<description><![CDATA[PROBLEM: You&#8217;ve got a movieclip with a stop action on the first frame. When it appears on-screen, it inexplicably starts playing on frame 2, ignoring frame 1 and your stop action entirely. The movieclip in question is probably embedded into a parent clip that you&#8217;ve dynamically added to the stage from the library using the [...]]]></description>
			<content:encoded><![CDATA[<p><big><strong>PROBLEM:</strong></big></p>
<p>You&#8217;ve got a movieclip with a stop action on the first frame. When it appears on-screen, it inexplicably starts playing on frame 2, ignoring frame 1 and your stop action entirely.</p>
<p>The movieclip in question is probably embedded into a parent clip that you&#8217;ve dynamically added to the stage from the library using the &#8220;new&#8221; keyword and &#8220;addChild&#8221; method.</p>
<p><big><strong>SOLUTION:</strong></big></p>
<p>You&#8217;re not going to like this. This bug is one of many we&#8217;re discovering as we finally make the painful, money-losing transition from AS2 to AS3 for all our future projects. You have two options:</p>
<ol>
<li>Put an extra frame at the beginning of the movieclip, with the stop(); action on frame 2. This solution completely stinks, but welcome to our brave new world where Adobe ignores the needs of designers and caters only to people who code absolutely everything and don&#8217;t use the timeline.</li>
<li>In my case, i was able to stop the clip on frame 1 by making an explicit call from the method that attached the parent clip, like so:</li>
</ol>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> parentClip<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span> = <span style="color: #0033ff; font-weight: bold;">new</span> ParentClip<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>parentClip<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
parentClip<span style="color: #000066; font-weight: bold;">.</span>childClip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">// where childClip is the one that's giving us problems</span></pre></td></tr></table></div>

<p><big><strong>Further Reading:</strong></big></p>
<p>Here are some of the places i hit on my merry way to finding the so-called answer to this problem:</p>
<p><a href="http://board.flashkit.com/board/showthread.php?t=762031"><strong>Flashkit:</strong> AS3 stop(); code not working??</a></p>
<p><a href="http://www.actionscript.org/forums/showthread.php3?p=798449"><strong>actionscript.org:</strong> AS# stop(); doesn&#8217;t work</a>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F10%2F23%2Fcs3-pitfalls-stop-action-ignored-on-nested-movieclip%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F10%2F23%2Fcs3-pitfalls-stop-action-ignored-on-nested-movieclip%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/10/23/cs3-pitfalls-stop-action-ignored-on-nested-movieclip/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=185&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/10/23/cs3-pitfalls-stop-action-ignored-on-nested-movieclip/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls &#8211; Cannot Unload Content in Flash Player 9</title>
		<link>http://www.untoldentertainment.com/blog/2008/04/23/as3-pitfalls-cannot-unload-content-in-flash-player-9/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/04/23/as3-pitfalls-cannot-unload-content-in-flash-player-9/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 11:17:18 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/04/23/as3-pitfalls-cannot-unload-content-in-flash-player-9/</guid>
		<description><![CDATA[PROBLEM: Unloading content (ie external swfs) in AS3 is difficult, if not impossible. SOLUTION: My pal Martin Sieg at marblemedia threw me to an article by Grant Skinner &#8211; Failure to Unload: Flash Player 9&#8242;s Dirty Secret &#8211; where the author discusses a player bug that prevents content unloading. The problem impacts gallery-style projects, and [...]]]></description>
			<content:encoded><![CDATA[<p><big><strong>PROBLEM:</strong></big></p>
<p>Unloading content (ie external swfs) in AS3 is difficult, if not impossible.</p>
<p><big><strong>SOLUTION:</strong></big></p>
<p>My pal Martin Sieg at marblemedia threw me to an article by Grant Skinner &#8211; <a href="http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html">Failure to Unload: Flash Player 9&#8242;s Dirty Secret</a> &#8211; where the author discusses a player bug that prevents content unloading. The problem impacts gallery-style projects, and sites that use embedded advertising.</p>
<p>Apparently there is no real solution, but Skinner is campaigning for a sandbox mode in Flash Player 10 where you can rope off your embedded content, and prevent it from getting its hooks into your main movie.</p>
<p>A noble effort, Grant.  In other news, aid group <a href="http://www.cnn.com/2008/WORLD/europe/04/22/food.program.cutback/?iref=mpstoryview">World Vision announced today</a> that rising food prices have created a shortfall that will prevent them from feeding millions of people.
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F04%2F23%2Fas3-pitfalls-cannot-unload-content-in-flash-player-9%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F04%2F23%2Fas3-pitfalls-cannot-unload-content-in-flash-player-9%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/04/23/as3-pitfalls-cannot-unload-content-in-flash-player-9/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=101&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/04/23/as3-pitfalls-cannot-unload-content-in-flash-player-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls: Keyboard Not Responding</title>
		<link>http://www.untoldentertainment.com/blog/2008/04/06/as3-pitfalls-keyboard-not-responding/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/04/06/as3-pitfalls-keyboard-not-responding/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 12:26:43 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/04/06/as3-pitfalls-keyboard-not-responding/</guid>
		<description><![CDATA[PROBLEM: When i test my movie, it doesn&#8217;t respond to all of the keyboard key presses. Only some keys register. OR Certain text characters do not show up in my Input text field when i type them, even though my font outlines are embedded. SOLUTION: In the Test Movie window (NOT the Flash IDE window), [...]]]></description>
			<content:encoded><![CDATA[<p><big><strong>PROBLEM:</strong></big></p>
<p>When i test my movie, it doesn&#8217;t respond to all of the keyboard key presses.  Only some keys register.</p>
<p><strong>OR</strong></p>
<p>Certain text characters do not show up in my Input text field when i type them, even though my font outlines are embedded.</p>
<p><big><strong>SOLUTION:</strong></big></p>
<p>In the Test Movie window (NOT the Flash IDE window), click on <strong>Control>Disable Keyboard Shortcuts.</strong></p>
<p>This problem is not an AS3 problem.  It&#8217;s a Flash thing, and it gets me every single time i upgrade to a new version of the software.  Since i only upgrade every few years, i always forget about this and i have to scour the Internetz like a dope looking for the solution.  Perhaps you can relate?  :)</p>
<p>It would be wiser for Adobe to disable keyboard shortcuts by default.  If you have the time and energy to do it, and if this problem wasted enough of your time, consider firing them an email or putting the suggestion on their Wishlist.
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F04%2F06%2Fas3-pitfalls-keyboard-not-responding%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F04%2F06%2Fas3-pitfalls-keyboard-not-responding%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/04/06/as3-pitfalls-keyboard-not-responding/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=93&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/04/06/as3-pitfalls-keyboard-not-responding/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls &#8211; Dude, where&#8217;s my _xscale?</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/21/as3-pitfalls-dude-wheres-my-_xscale/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/03/21/as3-pitfalls-dude-wheres-my-_xscale/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 16:45:10 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/21/as3-pitfalls-dude-wheres-my-_xscale/</guid>
		<description><![CDATA[PROBLEM: MovieClip._xscale (or MovieClip.xscale) does not light up as a recognized property in AS3. It&#8217;s not even listed as a property of the MovieClip class in the documentation. What gives? SOLUTION: _xscale and _yscale properties have been replaced by scaleX and scaleY, which are both properties of the DisplayObject class. MovieClip (eventually) extends DisplayObject and [...]]]></description>
			<content:encoded><![CDATA[<p><big><strong>PROBLEM:</strong></big></p>
<p>MovieClip._xscale (or MovieClip.xscale) does not light up as a recognized property in AS3.  It&#8217;s not even listed as a property of the MovieClip class in the documentation.  What gives?</p>
<p><big><strong>SOLUTION:</strong></big></p>
<p>_xscale and _yscale properties have been replaced by scaleX and scaleY, which are both properties of the DisplayObject class.  MovieClip (eventually) extends DisplayObject and inherits these properties.</p>
<p>The second snag is that scaleX and scaleY percentages are now divided by 100.  Whereas before, MovieClip._xscale = 100 displayed the clip at its native width, MovieClip.scaleX = 1.0 is the new hotness.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">MovieClip._xscale = 100; // Displays an object at its full width in Actionscript 2</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleX</span> = <span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// Displays an object at its full width in Actionscript 3</span></pre></td></tr></table></div>

<p>Take care when porting AS2 files to AS3.
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F03%2F21%2Fas3-pitfalls-dude-wheres-my-_xscale%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F03%2F21%2Fas3-pitfalls-dude-wheres-my-_xscale%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/03/21/as3-pitfalls-dude-wheres-my-_xscale/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=87&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/03/21/as3-pitfalls-dude-wheres-my-_xscale/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls &#8211; Error #1009</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/18/as3-pitfalls-error-1009/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/03/18/as3-pitfalls-error-1009/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 14:57:41 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/18/as3-pitfalls-error-1009/</guid>
		<description><![CDATA[PROBLEM: TypeError: Error #1009: Cannot access a property or method of a null object reference. SOLUTION: i don&#8217;t know. Error #1009 seems to be catch-all error that Flash throws whenever you reference something that doesn&#8217;t &#8220;exist&#8221;, or hasn&#8217;t been loaded into memory. A quick Google search shows that the error spans both Flash and Flex, [...]]]></description>
			<content:encoded><![CDATA[<p><big><strong>PROBLEM:</strong></big></p>
<p>TypeError: Error #1009: Cannot access a property or method of a null object reference.</p>
<p><big><strong>SOLUTION:</strong></big></p>
<p>i don&#8217;t know.  </p>
<p>Error #1009 seems to be  catch-all error that Flash throws whenever you reference something that doesn&#8217;t &#8220;exist&#8221;, or hasn&#8217;t been loaded into memory.  A quick Google search shows that the error spans both Flash and Flex, and can crop up in a number of hair-pulling situations.  Here&#8217;s the recipe i followed to produce my very own <strong>Error #1009</strong> while building a multi-user chat application with <a href="http://www.electro-server.com/">ElectroServer 4</a>:</p>
<p><strong>1.</strong> i create a document class called Main.as and linked to it from the Flash IDE.</p>
<p><strong>2.</strong> i set up my Flash swf with two frames. Frame 1 has a Login widget.  </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2008_03_18/frame1.jpg" alt="ElectroServer Simplechat Frame 1"></p>
<p>Frame 1.  Nothing fancy.
</p></div>
<p><strong>3.</strong> Frame 2 has a Chat window, a Send button, and a List component labelled &#8220;Users&#8221;.  The List component&#8217;s instance name was userListClip.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2008_03_18/frame2.jpg" alt="ElectroServer Simplechat Frame 2"></p>
<p>Frame 2.  Note the &#8220;Users&#8221; List component on the right.
</p></div>
<p><strong>4.</strong> Once the player logs in, i tell the swf to gotoAndStop(2);</p>
<p><strong>5.</strong> Now i try to populate my List component, userListClip, with the user names of the people in the chat.  No good &#8211; dreaded Error #1009 rears its ugly head.</p>
<p>After a bit of research, i read somewhere that my code cannot manipulate objects that i&#8217;ve placed on the stage further along the timeline, because those objects have to &#8220;exist&#8221; at the moment my code is compiled.  Huh.  Really?</p>
<p><big><strong>CRUMMY SOLUTION #1 &#8211; Alpha/Siberia</strong></big></p>
<p>One solution is to have that troublesome userListClip instance exist on Frame 1, but drag it off the stage or set it to alpha 0%.  This is a very clunky workaround and i don&#8217;t like it.</p>
<p><big><strong>CRUMMY SOLUTION #2 &#8211; Clunky Listener</strong></big></p>
<p>Someone in a Flash user group suggested i register a listener with Event.ADDED.  Here&#8217;s how that goes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">addListnener<span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED</span><span style="color: #000066; font-weight: bold;">,</span> onAdded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onAdded<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
     <span style="color: #6699cc; font-weight: bold;">var</span> clipName<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">;</span>
     <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>clipName<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
           <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;userListClip&quot;</span><span style="color: #000066; font-weight: bold;">:</span>
                    populateUserList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
           <span style="color: #0033ff; font-weight: bold;">default</span><span style="color: #000066; font-weight: bold;">:</span>
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
     <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">//onAdded()</span></pre></td></tr></table></div>

<p>No WAY.  That <em>can&#8217;t possibly</em> be a respectable solution.  Let&#8217;s just say it&#8217;s &#8220;inelegant&#8221; and leave it at that.  And for some strange reason, my userListClip instance doesn&#8217;t ever show up in this function.  What gives?  Do components not trigger Event.ADDED?</p>
<p><big><strong>CRUMMY SOLUTION #3 &#8211; The Hands-Off Approach</strong></big></p>
<p>Another solution, obviously, is to build the userListClip List component out of code.  i&#8217;m resistant to that because i&#8217;m one of these hands-on designer types who likes to <em>see</em> what he&#8217;s building.  i don&#8217;t like the fact that my whole design exists in this ethereal, unimaginable <em>codespace</em> that exists only in my darkest desires until compile time.  </p>
<p>Not only that, but pure code solutions become a pain to troubleshoot months down the road.  i&#8217;d much rather see something on the stage and click on it to see its instance name, than to pour through pages and pages of code trying to learn the programmer&#8217;s naming convention (even if the programmer is me.  i have a lousy memory).</p>
<p><big><strong>THE BEST SOLUTION</strong></big></p>
<p>If you&#8217;ve generated <strong>Error #1009</strong> and have lived to tell about it, please post your solution!
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F03%2F18%2Fas3-pitfalls-error-1009%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F03%2F18%2Fas3-pitfalls-error-1009%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/03/18/as3-pitfalls-error-1009/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=84&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/03/18/as3-pitfalls-error-1009/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls &#8211; Missing Font Outlines</title>
		<link>http://www.untoldentertainment.com/blog/2008/02/08/as3-pitfalls-missing-font-outlines/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/02/08/as3-pitfalls-missing-font-outlines/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 14:58:00 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/02/08/as3-pitfalls-missing-font-outlines/</guid>
		<description><![CDATA[PROBLEM: Bolded or italicized text doesn&#8217;t appear in my dynamic text box, even though i&#8217;ve included the font outlines. SOLUTION: This is a pitfall that&#8217;s existed in many versions of Flash, and it doesn&#8217;t necessarily have to do with your code. Flash treats bolded and italicized letters as separate outlines. If you have a a [...]]]></description>
			<content:encoded><![CDATA[<p><big><strong>PROBLEM:</strong></big> Bolded or italicized text doesn&#8217;t appear in my dynamic text box, even though i&#8217;ve included the font outlines.</p>
<p><big><strong>SOLUTION:</strong></big> This is a pitfall that&#8217;s existed in many versions of Flash, and it doesn&#8217;t necessarily have to do with your code.  Flash treats bolded and italicized letters as separate outlines.  If you have a a chunk of dynamic text, and have used htmltext or style sheets to bold and italicize certain words, you need to make sure the entire italicized font and the entire bolded font are included in your project. </p>
<p>One fast, lo-fi way to do this is to create two more dynamic text fields and include the bolded and italicized outlines, one set of outlines on each field.  Throw those text fields off the stage, making sure they exist on a frame <em>on or before </em>the frame that holds your important dynamic field &#8211; this way, you can be sure the font outlines are loaded into memory.  If your fonts show up the way you expected, you can work out a more elegant solution.
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F02%2F08%2Fas3-pitfalls-missing-font-outlines%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F02%2F08%2Fas3-pitfalls-missing-font-outlines%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/02/08/as3-pitfalls-missing-font-outlines/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=59&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/02/08/as3-pitfalls-missing-font-outlines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls &#8211; Cross-Domain BitmapData</title>
		<link>http://www.untoldentertainment.com/blog/2008/01/30/as3-pitfalls-cross-domain-bitmapdata/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/01/30/as3-pitfalls-cross-domain-bitmapdata/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 20:54:02 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/01/30/as3-pitfalls-cross-domain-bitmapdata/</guid>
		<description><![CDATA[We&#8217;ve been linked to by a fellow agency called Airtight Interactive on the subject of altering cross-domain bitmap data in Flash. They mention the server-side proxy work-around that i&#8217;ve used, calling it &#8220;prohibitive&#8221; for large-scale apps. That was the concern i raised when a casual games publisher approached me to ditribute Jigsaw! across its extremely [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve been linked to by a fellow agency called Airtight Interactive on the subject of altering cross-domain bitmap data in Flash.  They mention the server-side proxy work-around that i&#8217;ve used, calling it &#8220;prohibitive&#8221; for large-scale apps.  That was the concern i raised when a casual games publisher approached me to ditribute <a href="http://www.untoldentertainment.com/games/jigsaw/game.html"><em>Jigsaw!</em></a> across its extremely high-traffic game portals.  </p>
<p>Untold Entertainment&#8217;s advantage is that we do not bear the bandwidth costs that the jigsaw game&#8217;s Custom image feature may <em>bring down</em> like so much Biblical wrath.  There are ways to mitigate the cost, which i&#8217;ll discuss after posting the solution.</p>
<p>(Click to read about <a href="http://untoldentertainment.com/blog/2007/10/15/cross-domain-bitmap-data-adobe-says-no/">Adobe&#8217;s rationale</a> for preventing cross-domain image manipulation in Flash.)</p>
<p><big><strong>PROBLEM:</strong></big></p>
<p>Images loaded into a Flash swf from another domain (ie www.notMyOwnSite.com), won&#8217;t respond to BitmapData methods like draw().</p>
<p><big><strong>SOLUTION:</strong></big></p>
<p>Flash needs to see that the image comes from your own domain.  To pull this off, you set up a server-side script and pass the image url to it. The script loads the image to your domain, and returns that image to Flash.  Since the image comes from your domain now, you can mess around with it all you like.</p>
<p>The script i use is written in PHP.  Here it is, at its most basic:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$mimetype</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mimetype'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: <span style="color: #006699; font-weight: bold;">$mimetype</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>There are some clear problems with this approach:</p>
<p><strong>1. Since your server has to load the image, you carry the bandwidth cost for trafficking that image.</strong> i consider this the cost of doing business.  If you want to offer a cool feature like custom player-created jigsaw puzzles, you have to pony up the cash.</p>
<p>And then, logically:</p>
<p><strong>2. Some malicious user could set up a script to repeatedly pass enormous images through your server every second of every day, putting you in the poorhouse, or forcing your provider to shut your site down. </strong>  This is best handled by adding limits to the script.  Prevent users from loading images above a certain filesize, and limit the number of script calls per user.</p>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F01%2F30%2Fas3-pitfalls-cross-domain-bitmapdata%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F01%2F30%2Fas3-pitfalls-cross-domain-bitmapdata%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/01/30/as3-pitfalls-cross-domain-bitmapdata/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=57&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/01/30/as3-pitfalls-cross-domain-bitmapdata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls &#8211; TextField.setSelection not working</title>
		<link>http://www.untoldentertainment.com/blog/2008/01/11/as3-pitfalls-textfieldsetselection-not-working/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/01/11/as3-pitfalls-textfieldsetselection-not-working/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 18:50:42 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/01/11/as3-pitfalls-textfieldsetselection-not-working/</guid>
		<description><![CDATA[PROBLEM: TextField.setSelection doesn&#8217;t select any text! SOLUTION: Set the stage.focus property to your TextField object. 1 2 3 4 // Selects all the text in myTextField: myTextField.selectable = true; myTextField.stage.focus = myTextField; myTextField.setSelection&#40;0, myTextField.text.length&#41;; Other search terms: setSelection not working setSelection not responding setSelection broken setSelection bug setSelection buggy DOUBLE_CLICK problem]]></description>
			<content:encoded><![CDATA[<p><big><strong>PROBLEM:</strong></big></p>
<p>TextField.setSelection doesn&#8217;t select any text!</p>
<p><big><strong>SOLUTION:</strong></big></p>
<p>Set the stage.focus property to your TextField object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Selects all the text in myTextField:</span>
myTextField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">selectable</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
myTextField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">focus</span> = myTextField<span style="color: #000066; font-weight: bold;">;</span>
myTextField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setSelection</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> myTextField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p><small>Other search terms:<br />
setSelection not working<br />
setSelection not responding<br />
setSelection broken<br />
setSelection bug<br />
setSelection buggy<br />
DOUBLE_CLICK problem<br />
</small>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F01%2F11%2Fas3-pitfalls-textfieldsetselection-not-working%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F01%2F11%2Fas3-pitfalls-textfieldsetselection-not-working%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/01/11/as3-pitfalls-textfieldsetselection-not-working/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=53&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/01/11/as3-pitfalls-textfieldsetselection-not-working/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>AS3 Pitfalls &#8211; MouseEvent.DOUBLE_CLICK</title>
		<link>http://www.untoldentertainment.com/blog/2008/01/11/as3-pitfalls-mouseeventdouble_click/</link>
		<comments>http://www.untoldentertainment.com/blog/2008/01/11/as3-pitfalls-mouseeventdouble_click/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 16:04:26 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AS3 Pitfalls]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/01/11/as3-pitfalls-mouseeventdouble_click/</guid>
		<description><![CDATA[PROBLEM: MouseEvent.DOUBLE_CLICK doesn&#8217;t work! SOLUTION: Set the object&#8217;s doubleClickEnabled flag to true 1 2 myBtn.doubleClickEnabled = true; myBtn.addEventListener&#40;MouseEvent.DOUBLE_CLICK, double_click&#41;; Other search terms: DOUBLE_CLICK not working DOUBLE_CLICK not responding DOUBLE_CLICK broken DOUBLE_CLICK bug DOUBLE_CLICK buggy DOUBLE_CLICK problem]]></description>
			<content:encoded><![CDATA[<p><big><strong>PROBLEM:</strong></big></p>
<p>MouseEvent.DOUBLE_CLICK doesn&#8217;t work!</p>
<p><big><strong>SOLUTION:</strong></big></p>
<p>Set the object&#8217;s doubleClickEnabled flag to true</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">myBtn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">doubleClickEnabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
myBtn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DOUBLE_CLICK</span><span style="color: #000066; font-weight: bold;">,</span> double_click<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p><small>Other search terms:<br />
DOUBLE_CLICK not working<br />
DOUBLE_CLICK not responding<br />
DOUBLE_CLICK broken<br />
DOUBLE_CLICK bug<br />
DOUBLE_CLICK buggy<br />
DOUBLE_CLICK problem<br />
</small>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F01%2F11%2Fas3-pitfalls-mouseeventdouble_click%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2008%2F01%2F11%2Fas3-pitfalls-mouseeventdouble_click%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2008/01/11/as3-pitfalls-mouseeventdouble_click/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=51&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2008/01/11/as3-pitfalls-mouseeventdouble_click/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

