<?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/"
	>

<channel>
	<title>dispatchEvent() Blog™ &#187; AS3</title>
	<atom:link href="http://dispatchevent.org/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://dispatchevent.org</link>
	<description>Collective thoughts on the Flash Platform, iOS, Unity, and any other technology we use.</description>
	<lastBuildDate>Wed, 14 Jul 2010 15:06:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>IDisplayObject? &#8211; Getting around the lack of an interface for the DisplayObject in Flash</title>
		<link>http://dispatchevent.org/mims/idisplayobject/</link>
		<comments>http://dispatchevent.org/mims/idisplayobject/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 02:27:22 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[displayobject]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[idisplayobject]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=838</guid>
		<description><![CDATA[Interfaces are amazing things. When I was young and green, I didn&#8217;t understand their purpose, but after working with them for a while, I will defend their use to the end. I try to create lots of interfaces early on &#8230; <a href="http://dispatchevent.org/mims/idisplayobject/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://dispatchevent.org/wp-content/uploads/2010/03/DisplayObject_subclasses.png"><img class="alignnone size-medium wp-image-840" title="DisplayObject_subclasses" src="http://dispatchevent.org/wp-content/uploads/2010/03/DisplayObject_subclasses-300x156.png" alt="" width="300" height="156" /></a></p>
<p>Interfaces are amazing things.  When I was young and green, I didn&#8217;t understand their purpose, but after working with them for a while, I will defend their use to the end. I try to create lots of interfaces early on in my projects and I find that by keeping things flexible, it saves more time despite the extra typing, pardon the double entendre.</p>
<p>But this is not an article about why interfaces are so great. No, this is an article about the mysterious gap in the Flash Player API with regards to an interface for DisplayObjects. If you have a class typed as something like <code>IView</code>, there&#8217;s no way to enure that <code>IView</code> can be a parameter of display list functions like <code> addChild()</code>.</p>
<p><span id="more-838"></span>Why can&#8217;t we guarantee that something is a DisplayObject through interfaces? There is a practical answer. The inner workings of the Flash Player are slowing unfolding to us with each version. We now have low level access to sound, byte streams, and text rendering. However, the display list still relies exclusively on one of the only truly abstract classes in ActionScript 3.0, the DisplayObject. Because a low-level drawing engine is not exposed to AS3 programmers, we don&#8217;t know how it works and we cannot guarantee through an interface that an arbitrary class can be drawn.</p>
<p>Fortunately, there are some workarounds that can help, each with their own strengths and weaknesses. Personally, I think #2 is the way to go. It&#8217;s practically dripping with polymorphic goodness.</p>
<ol>
<li>
<h3>Make your interface inherit from IBitmapDrawable and IEventDispatcher</h3>
<p>DisplayObject is the only class that uses both of these two interfaces so by combining them in your interface, you can sort of be sure you&#8217;re working with a DisplayObject. Still, this is my least favorite solution</p>
<h4>Pros:</h4>
<ul>
<li>Uses interfaces exclusively.</li>
<li>Only a DisplayObject would implement both of these.</li>
</ul>
<h4>Cons:</h4>
<ul>
<li>There&#8217;s nothing to stop you from using this to create a class that isn&#8217;t a DisplayObject and that could cause problems.</li>
<li>You would still have to type cast to DisplayObject to use this as an argument for <code>addChild()</code>.</li>
</ul>
</li>
<li>
<h3>Create an interface that exposes a method to return the object as a DisplayObject</h3>
<p>My personal favorite solution. It not only solves the problem of guaranteeing that a class can go in the display list, it doesn&#8217;t even require that the class be a DisplayObject.</p>
<p>Here&#8217;s an example of what this would look like. <a href="http://gist.github.com/332408">IDisplayObject.as</a></p>
<h4>Pros:</h4>
<ul>
<li>Flexible solution that conforms to good OOD principles.</li>
<li>Uses interfaces exclusively.</li>
<li>Easy to apply. You can usually implement it with a single line of code: <code>return this;</code></li>
</ul>
<h4>Cons:</h4>
<ul>
<li>Requires you to use <code>asDisplayObject()</code> every time you want to use the object as a DisplayObject.</li>
<li>Calling <code>foo.asDisplayObject()</code> would throw an exception if <code>foo</code> was null so additional checks may be necessary.</li>
</ul>
</li>
<li>
<h3>Use an <a href="http://en.wikipedia.org/wiki/Abstract_type">abstract class</a> that inherits from DisplayObject</h3>
<p>Not an ideal solution primarily because Flash doesn&#8217;t have true abstract classes (although <a href="http://dispatchevent.org/mims/abstract-classes-in-as3/">there are workarounds</a>) but still totally valid.</p>
<h4>Pros:</h4>
<ul>
<li>Guarantees that the object is a DisplayObject. No type casting required.</li>
<li>Abstract classes can be treated virtually the same as an interface for practical use.</li>
</ul>
<h4>Cons:</h4>
<ul>
<li>No true abstract classes in Flash.</li>
<li>Not as flexible as an interface-based solution since it forces you to inherit from DisplayObject.</li>
</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/idisplayobject/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Copy text to clipboard in AS3</title>
		<link>http://dispatchevent.org/mims/as3-clipboard/</link>
		<comments>http://dispatchevent.org/mims/as3-clipboard/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 06:27:34 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[clipboard]]></category>
		<category><![CDATA[copypasta]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=825</guid>
		<description><![CDATA[Here&#8217;s how you do it! http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how you do it!<br />
<a href="http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/">http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/as3-clipboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash player 10</title>
		<link>http://dispatchevent.org/calebjohnston/flash-player-10/</link>
		<comments>http://dispatchevent.org/calebjohnston/flash-player-10/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 14:32:25 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=418</guid>
		<description><![CDATA[Its that time again. Time to get into the latest and greatest tech from one of those giant software engineering companies. This time, the tech is Adobe&#8217;s Flash player 10. Step 1: download the Flex 4 SDK and the Flash &#8230; <a href="http://dispatchevent.org/calebjohnston/flash-player-10/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Its that time again. Time to get into the latest and greatest tech from one of those giant software engineering companies. This time, the tech is Adobe&#8217;s Flash player 10.</p>
<p>Step 1: <a title="Adobe Open Source - Flex 4" href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4">download the Flex 4 SDK and the Flash player 10 (debug version).</a></p>
<p>Step 2: Create a fresh config file <a title="target Flash player 10" href="http://opensource.adobe.com/wiki/display/flexsdk/Targeting+Flash+Player+10+Beta">that will target Flash player 10</a>.</p>
<p>Step 3: <a title="compile your swf" href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_13.html">Use MXMLC to compile your Actionscript or MXML file.</a></p>
<p>Step 4: <a title="AS3 with Flash 10" href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/">Explore AS3</a> with <a title="AS3 Flash 10 language reference" href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/index.html">Flash 10!</a></p>
<p>I&#8217;ve only tinkered around a bit at this point. But as soon as I get a chance to build a crazy app, I&#8217;ll have a more thorough write-up. So far, I&#8217;m quite excited at the new features. Be sure to read up on the following:</p>
<p><a title="Vector class" href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Vector.html">new Vector class</a></p>
<p><a title="inverse kinematics!" href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/fl/ik/package-detail.html">The inverse kinematics package</a></p>
<p><a title="new Shader class" href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/Shader.html">The new Shader class</a></p>
<p><a title="Flash 10 text engine" href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/engine/package-detail.html">The all new text engine package</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/flash-player-10/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
