<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Flex and Flash Developer - Jesse Warden dot Kizz-ohm</title>
	
	<link>http://jessewarden.com</link>
	<description>A blog on software development, technology, games &amp; movies.</description>
	<lastBuildDate>Thu, 25 Jun 2009 18:56:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/jessewarden" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Flash Player 11: Gaming Platform?</title>
		<link>http://feedproxy.google.com/~r/jessewarden/~3/vhL8k7mPL68/flash-player-11-gaming-platform.html</link>
		<comments>http://jessewarden.com/2009/06/flash-player-11-gaming-platform.html#comments</comments>
		<pubDate>Thu, 25 Jun 2009 16:46:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://jessewarden.com/?p=1687</guid>
		<description><![CDATA[When Director was being overtaken by Flash, you could see the signs by what they were teaching at local colleges, what jobs were hiring for, and activity centers online based more around Flash&#8217; growth vs. Director.  The same happened with Flex; Macromedia employee&#8217;s typically involved on the Flashcoders email list started to go quiet [...]]]></description>
			<content:encoded><![CDATA[<p>When <a href="http://www.adobe.com/products/director/">Director</a> was being overtaken by <a href="http://www.adobe.com/products/flash/">Flash</a>, you could see the signs by what they were teaching at local colleges, what jobs were hiring for, and activity centers online based more around Flash&#8217; growth vs. Director.  The same happened with <a href="http://www.adobe.com/products/flex/">Flex</a>; Macromedia employee&#8217;s typically involved on the Flashcoders email list started to go quiet and a significant amount of new blood, and old, popped up on the Flexcoders email list.  Product strategies favored new features for the Flex component set and not Flash.</p>
<p><span id="more-1687"></span>Now, while we&#8217;ve reached a point where while there is still room for innovation + needed features, the Flex &amp; Flash community is losing developers.  <strong>EDIT for </strong><strong><a href="http://blogs.adobe.com/jd/">JD</a></strong>: <strong>*** </strong>Not en-masse; the Flex community is growing continuously, I&#8217;m speaking specifically about a small, yet influential group of developers I follow on Twitter.  <strong>***</strong> This isn&#8217;t a wholesale abandonment like it was for Director to Flash.  There are still many developers who utilize multiple technologies on a variety of projects.  I&#8217;m speaking specifically about the variety of developers in the Flex &amp; Flash community who&#8217;ve publicly shifted their focus to talk more about iPhone &amp; Unity development then 100% Flash/Flex.  Keith Peters, a prominent Flash Developer, has been doing a significant amount of Objective-C development for iPhone apps.  While not 100%, he <a href="http://twitter.com/bit101/status/2224446857">hasn&#8217;t coded AS3 in 6 weeks</a>.  I&#8217;ve read about many others on Twitter who typically brand themselves as Flash/Flex developers who have started doing iPhone development, some professionally.  If you&#8217;re getting paid to create applications for the iPhone, you&#8217;re not getting paid to utilize the Flash Player.</p>
<p>Others have, at a minimum, been really impressed with <a href="http://unity3d.com/">Unity3D&#8217;s</a> offering: a wonderful gaming platform for the web with many features Flash Player has, and many important gaming specific ones it does not.  Additionally, it has other devices it can run on that Flash Player cannot, specifically iPhone.  Others have thrown their entire being at Unity3D as opposed to Flash/Flex, even if Flash/Flex still pay&#8217;s their bills.</p>
<p>The above, combined with some recent discussions on Twitter from Mike Chambers (<a href="http://twitter.com/mesh/status/2290501716">1</a>, <a href="http://twitter.com/mesh/status/2299303438">2</a>, <a href="http://twitter.com/mesh/status/2296536428">3</a>, <a href="http://twitter.com/mesh/status/2296370932">4</a>, <a href="http://twitter.com/mesh/status/2291551870">5</a>, <a href="http://twitter.com/mesh/status/2290875655">6</a>, <a href="http://twitter.com/mesh/status/2299877560">7</a>, <a href="http://twitter.com/mesh/status/2300009843">8</a>, <a href="http://twitter.com/mesh/status/2300641621">9</a>, <a href="http://twitter.com/mesh/status/2300663143">10</a>, <a href="http://twitter.com/mesh/status/2300706738">11</a>, <a href="http://twitter.com/mesh/status/2300742486">12</a>, <a href="http://twitter.com/mesh/status/2300875178">13</a>, <a href="http://twitter.com/mesh/status/2318413678">14</a>, <a href="http://twitter.com/mesh/status/2323530484">15</a>) and Ted Patrick (<a href="http://twitter.com/adobeted/status/2297499987">1</a>, <a href="http://twitter.com/adobeted/status/2301768522">2</a>, <a href="http://twitter.com/adobeted/status/2301779283">3</a>) from Adobe, are starting to show yet another shift in Adobe&#8217;s direction, one that appears towards supporting gaming more formally.  To be clear, Flash Player has always been a wonderful gaming platform for both web and desktop, for both indie and bigger companies.  From the simple/addictive/viral/spawned many clones <a href="http://www.funrestarea.com/pages/penguin_baseball.shtml">Penguin Baseball</a> to the French MMORPG <a href="http://www.dofus.com/en">Dofus</a>. Alien Hominid, which started as a <a href="http://www.newgrounds.com/portal/view/59593">Flash game</a>, became so popular it evolved into a <a href="http://www.gamespot.com/xbox/action/alienhominid/index.html">platform game</a>.  The reverse has happened as well with indie games being built around alternative themes for existing brands such as <a href="http://starcraft2.pro/">Starcraft Tower Defense</a>, and Half Life&#8217;s <a href="http://en.wikipedia.org/wiki/Codename_Gordon">Codename: Gordon</a>.  Some really show off the power of the Flash Player&#8217;s performance such as my favorite, <a href="http://www.pictogame.com/en/play/game/q3UKbPAZAW8C_raidenx">Raiden X</a>.</p>
<p>Why games?  In 2007, according to an <a href="http://en.wikipedia.org/wiki/Entertainment_Software_Association">ESA</a> report, it was a $9.5 billion dollar industry.  With the exclusion of films like Titanic, Spiderman, and Batman: The Dark Knight, many game profits exceed movie profits.  The budgets for creating games has already surpassed what it costs to make some movies.</p>
<p>Games also have a significant impact on user&#8217;s time spent on the site as well as the frequency they return the the site.  This increases the chance for higher advertising conversion rates.  This is used a lot in sites such as MySpace &amp; Facebook, as well as other larger brand properties who utilize games to enable incentive for users to come back while the community grows.</p>
<p>In short, a good business opportunity to spend resources to support that industry in adding features for it into Flash Player 11.</p>
<p>The challenge with Flash games, however, has been piracy.  SWF&#8217;s are notoriously hard to make domain specific; meaning it can only run from a certain website.  The SWF format is open enough, therefore decompilers make it easy to remove whatever protections were there.  Being just another web asset, countless sites either link to other sites with the games, host on theirs, and profit from the ads. This happens a lot on Flash Lite mobile portals as well.  Some services such as a <a href="http://mochiads.com/">MochiAds</a> have helped game creators track their content, know where it&#8217;s being used, and profit from it.</p>
<p>Bottom line, though, SWF&#8217;s are really easy to hack around and most games that I&#8217;ve seen are just that; easy to work around/defeat their protections.  This is mainly due to it being, as I said, easy to decompile.  Additionally, it&#8217;s hard for the developer to protect his/her content.</p>
<p>So what is Adobe planning?  Based on what I&#8217;m reading, here are my inferences:</p>
<ol>
<li><strong>True </strong><a href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/200906/060209AdobeandNvidia.html"><strong>hardware acceleration for GPU</strong></a>.  If a system doesn&#8217;t support it because of the challenging nature of supporting various hardware, you can still fallback to Flash Player 10 which has the <a href="http://www.kaourantin.net/2008/05/what-does-gpu-acceleration-mean.html">hybrid software GPU renderer</a>.  Having to learn how to optimize AS3 is an oxymoron; you should just have a well performing language that allows you to utilize normal gaming development API&#8217;s.  Doing this will allow a larger audience to tap into the hardware that&#8217;s already there, and thus enabling a large gaming developer audience more opportunities.</li>
<li><strong>Improved API for gaming interactio</strong><strong>ns</strong>.  While DisplayObject.hitTest is nice, PixelBender and/or BitmapData.hitTest can often be better.  You&#8217;re sometimes forced to make design changes, such as using meta-tiles (coordinates of the screen that, if objects are in, qualify for hit tests vs. all objects on screen) for large number of targets.  Wouldn&#8217;t it be better if you could just use native API&#8217;s that run at C speed vs. having to &#8220;work around platform limitations&#8221;?  This goes beyond just hit testing objects, basically anything you need to create games as well as powerful lower-level API&#8217;s for linking phyiscs and the existing 3D boilerplate code that Flash Player 10 offers.  The strategy from Adobe since Flash Player 9 has been to offer powerful, low-level API&#8217;s which allows both Adobe and the community to build libraries on top of it vs. burdening the player&#8217;s backwards compatibility when new versions are to be released.  An example is Flash Player 10&#8217;s latest 3D apis that allow 3D engines to be built on top of it vs. forcing a particular one upon us.</li>
<li><strong>New Sound AP</strong>I: If you&#8217;ve used the AS3 one, enough said. Whack API with old <a href="http://www.kennybunch.com/blog/2009/01/bug-as3-soundisbuffering/">b|</a><a href="http://www.stevensacks.net/2008/08/07/bug-with-sound-channel-position-and-mp3s-less-than-128kbps/">u|</a><a href="http://www.stevensacks.net/2008/08/07/as3-sound-bug-with-channelpan/">g|</a><a href="http://www.stevensacks.net/2008/08/07/as3-sound-channel-bug/">s</a>.  Granted, you can create <a href="http://www.hobnox.com/index.1056.de.html">magic</a>, but we shouldn&#8217;t have to be a group of geniuses to create great audio experiences.</li>
<li><strong>DRM solution for content</strong>.  Adobe already has a server and client one in place for video.  When large brands want to put video online, they are often concerned about misuse of their content.  Utilizing both the encrypted RTMP protocol as well as the DRM API&#8217;s in the Adobe AIR runtime, video content is already being protected &amp; controlled this way for video content creators.  This would help application developers as well, not just game developers.</li>
</ol>
<p>If you&#8217;ve played any <a href="http://starwars.lego.com/en-US/funandgames/play.aspx">Unity3D games</a>, read the <a href="http://rockonflash.wordpress.com/2008/12/23/unity3d-ms-adobe-should-buy-them/">raves by Flash industry celebrities</a>, or read into why Apple would suggest you build all iPhone apps to be resolution independent and then <a href="http://www.destructoid.com/apple-hires-xbox-senior-director-of-strategy-130864.phtml">hire XBox&#8217; former Senior Director of Strategy</a>&#8230; you can see why there is competition for gaming developers.  If you can&#8217;t get on the iPhone because it violates the terms of use and Apple would prefer you purchase a Mac to develop in Objective-C anyway, and you don&#8217;t have the hardware horsepower to compete with Unity3D, it seems a good strategy to find a way to compete with Unity3D &amp; iPhone&#8217;s gaming future is to get on as many devices as possible with a powerful gaming runtime alternative.  That appears to be what Adobe is doing.</p>
<img src="http://feeds.feedburner.com/~r/jessewarden/~4/vhL8k7mPL68" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jessewarden.com/2009/06/flash-player-11-gaming-platform.html/feed</wfw:commentRss>
		<slash:comments>26</slash:comments>
		<feedburner:origLink>http://jessewarden.com/2009/06/flash-player-11-gaming-platform.html</feedburner:origLink></item>
		<item>
		<title>Job: Python Software Engineer</title>
		<link>http://feedproxy.google.com/~r/jessewarden/~3/JOaqUCIP7YE/job-python-software-engineer.html</link>
		<comments>http://jessewarden.com/2009/06/job-python-software-engineer.html#comments</comments>
		<pubDate>Wed, 17 Jun 2009 16:04:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Jobs]]></category>

		<guid isPermaLink="false">http://jessewarden.com/?p=1682</guid>
		<description><![CDATA[VIAAS is seeking a Python Software Engineer. The engineer will be a member of a small, dynamic development team. This is a challenging position that requires in-depth knowledge of LAMP technologies, and a seasoned grasp of how to create, communicate about, and design for scalability of Web 2.0 technologies.The engineer needs to be comfortable working in [...]]]></description>
			<content:encoded><![CDATA[<p><strong>VIAAS</strong> is seeking a <strong>Python Software Engineer</strong>. The engineer will be a member of a small, dynamic development team. This is a challenging position that requires in-depth knowledge of LAMP technologies, and a seasoned grasp of how to create, communicate about, and design for scalability of Web 2.0 technologies.The engineer needs to be comfortable working in a fluid environment, handling a variety of assignments and technologies. We have a very sharp, passionate, and fast-moving development team that prides itself on technical excellence and innovation. People who are used to staid corporate environments or a heads-down focus on one thing will not be happy here; people who thrive on learning new technologies, defining their jobs, and having a direct contribution to the success of the business will love it here.</p>
<p><span id="more-1682"></span><strong>Overall responsibilities</strong></p>
<ul>
<li>Contribute to the design, architecture, development, and deployment of all web/server development projects.</li>
<li>Ensure that a best-practices approach is taken regarding all stages and aspects of technology projects.</li>
<li>Assist in making high-level, technology decisions, with a keen eye towards innovation and scalability.</li>
</ul>
<p><strong>Qualifications</strong></p>
<ul>
<li>Seven plus years experience in software development (with at least five years in web/lamp server application development), with exposure to the full development life-cycle required.</li>
<li>Expert-level proficiency in object-oriented LAMP-stack environment. Specific expertise in Python is desired. Experience with Django is a strong plus.</li>
<li>Experience with FLASH / FLEX desired.</li>
<li>Experience setting up web based storefront desired. Experience with Satchmo a plus.</li>
<li>Experience contributing to enterprise class software projects a must.</li>
<li>Proficiency in AJAX and Web 2.0 development methodologies.</li>
<li>Demonstrable working knowledge of Javascript.</li>
<li>Development experience with the MySQL and/or Postgres database. Historical use of federated databases a plus.</li>
<li>Solid understanding of Apache 1.3.x and 2.x operations and integration in a Linux/Unix environment.</li>
<li>Experience working with open source tools and applications, with prior participation and contribution in open source projects a plus.</li>
<li>Experience with MPEG 4, h.264, and open source video manipulation tools a plus.</li>
<li>Ability to work independently with no hand-holding.</li>
<li>Ability to work in a rapidly changing environment and exhibit grace under pressure.</li>
<li>Experience with cloud computing a plus.</li>
<li>Experience with the entire software life-cycle – analysis, design, implementation, quality assurance, deployment, and maintenance.</li>
<li>Strong organizational, problem-solving and communications skills (must be able to do basic technical writing in English).</li>
</ul>
<p>While the ideal candidate will be located in the the South Bay Area, working remotely will be considered if skills and experience and location warrant it.</p>
<p><strong>Instructions</strong></p>
<p><strong></strong>To apply for this position, submit your resume, in plain text, HTML, Doc or PDF (PDF preferred), to <a href="mailto:staffing@viaas.com?subject=Python%20Software%20Engineer%20%20(los%20gatos)" target="_blank">staffing@viaas.com</a>.<br />
VIAAS is an Equal Opportunity Employer and does not unlawfully discriminate on the basis of any status or condition protected by applicable federal or state law.</p>
<img src="http://feeds.feedburner.com/~r/jessewarden/~4/JOaqUCIP7YE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jessewarden.com/2009/06/job-python-software-engineer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jessewarden.com/2009/06/job-python-software-engineer.html</feedburner:origLink></item>
		<item>
		<title>Error Handling in ActionScript 3: Don’t Make Grenades (or how to not crash Safari)</title>
		<link>http://feedproxy.google.com/~r/jessewarden/~3/ZjMwlYvw6XQ/error-handling-in-actionscript-3-dont-make-grenades-or-how-to-not-crash-safari.html</link>
		<comments>http://jessewarden.com/2009/06/error-handling-in-actionscript-3-dont-make-grenades-or-how-to-not-crash-safari.html#comments</comments>
		<pubDate>Thu, 11 Jun 2009 01:30:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://jessewarden.com/?p=1650</guid>
		<description><![CDATA[Preface
At the latest WWDC it was announced that the #1 reason Safari crashes for users is because of Flash, hence the new plug-in sequestering (i.e. if Flash blows up real good, it&#8217;ll do so in a way that won&#8217;t negatively affect the browser).  I agree.  If you&#8217;ve ever surfed the web using the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Preface</strong></p>
<p>At the latest <a href="http://developer.apple.com/WWDC/">WWDC</a> it was announced that the #1 reason Safari crashes for users is because of Flash, hence the new plug-in sequestering (i.e. if Flash <a href="http://www.youtube.com/watch?v=30BvoBbrTxM">blows up real good</a>, it&#8217;ll do so in a way that won&#8217;t negatively affect the browser).  I agree.  If you&#8217;ve ever surfed the web using the debug Flash Player, Safari 3 and 4 explode all the time.  I don&#8217;t know the true cause, but I do know when it&#8217;ll happen most often: when you get an error dialogue.  These are shown only if you have the debug Flash Player installed, and an error that wasn&#8217;t &#8220;caught&#8221; happens.  Sometimes hitting the &#8220;Continue&#8221; button vs. the &#8220;Dismiss All&#8221; button will work&#8230; but not always&#8230; BOOM!  Thank God for History &gt; Reopen All Windows from Last Session.  Here&#8217;s how you can help prevent Flash&#8217;s bad name from getting worse (that and until Adobe makes it more stable).</p>
<p><span id="more-1650"></span><strong>Introduction</strong></p>
<p>I&#8217;ve <a href="http://jessewarden.com/2007/11/your-mom-is-null-throws-exception-ot-ot-ot-or-learning-exception-handling-in-actionscript.html">written about errors</a> in the past, but wanted to write a more recent, basic, and thorough example since now more than ever, I&#8217;m seeing errors all over the web with Flash content nowadays.</p>
<p>Flash Player 9 and 10 have errors.  These are like Java&#8217;s unchecked <a href="http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html?page=1">exceptions</a>.  There are 2 types of errors: synchronous and asynchronous meaning &#8220;immediately happening while your code is running&#8221; and &#8220;sometime later when our code is chilling&#8221;.  Errors occur when your code does something it&#8217;s not allowed, or can&#8217;t, do.  In the past, you couldn&#8217;t catch these errors nor attempt to recover from them.  Try/catch did exist in a primitive form in AS2/AS1 but didn&#8217;t cover all conditions, and sometimes if used would abort entire blocks of code without you knowing where.  Errors are a feature of the new ActionScript virtual machine in Flash Player 9 and 10, and are thus really good.</p>
<p>The best way to prevent errors from getting in your code is a good compiler.  The Flash CS3/CS4, and the Flex SDK&#8217;s mxmlc compiler do a very good job of spotting errors before they happen.  The #1 error most of us faced in AS1 was capitalization; if you mispelled a variable, and attempted to access in your code, it obviously wouldn&#8217;t work; i.e person.firstName vs. person.firstname; 2 different variables in AS1 (only in the Flash Player 7, 6 was case insensitive). The compiler didn&#8217;t see it because there was no strong-typing; anything you typed in a dynamic language is valid because the language is&#8230; dynamic.  In ActionScript 2, they mostly fixed this problem, but the #2 problem, null values, were really hard to track down.  This is when your code attempts to access a property of something, say a MovieClip&#8217;s x position&#8230; but the MovieClip variable is actually null.  In AS2, things just wouldn&#8217;t work, and you&#8217;d be like, &#8220;<a href="http://www.albinoblacksheep.com/flash/end">WTF, mate?</a>&#8220;.</p>
<p>Now we have a great complier, and a great runtime that will actually show a dialogue of these errors with where they actually occurred, and why.  The problem is, unhandled errors can cause your program to stop working, and cause the browser (*cough* Safari) to crash.</p>
<p><strong>The Error Dialogue</strong></p>
<p>The error dialogue will show whenever a synchronous or asynchronous error occurs and you don&#8217;t catch it (aka handle it).  This code will show a null pointer exception/error:</p>
<pre><span class="keyword">import</span> flash.display.<span class="identifier2">MovieClip</span>;
<span class="keyword">var</span> mcMasterKilla:<span class="identifier2">MovieClip</span>;
<span class="identifier2">trace</span>(mcMasterKilla.x);</pre>
<p><img class="alignnone size-full wp-image-1661" title="error-window1" src="http://jessewarden.com/wp-content/uploads/2009/06/error-window1.jpg" alt="error-window1" width="470" height="242" /></p>
<p>This is because while I defined the MovieClip variable, I didn&#8217;t actually create it yet, so I&#8217;m attempting to access an x position of a MovieClip that doesn&#8217;t exist.  BOOM!</p>
<p>The error dialogue (when running in a browser, not the Flash IDE) will pause your Flash movie&#8217;s code execution, and wait for you to dismiss the dialogue by clicking Dismiss All or Continue.  By default, Continue is what your code does when the SWF is run in the regular Flash Player (non debug).  Continue &#8220;does its best&#8221; to continue running the code after/around the bad stuff.  A lot of times the offending code won&#8217;t run again.  Other times, Flash Player will make a miraculous recovery.</p>
<p>You can create this dialogue as well via a synchronous exception:</p>
<pre><span class="keyword">throw</span> <span class="keyword">new</span> <span class="identifier">Error</span>(<span class="string">"BOOM, boom, boom shake the room!"</span>);</pre>
<p>A throw is a special keyword in ActionScript that you use with the Error class.  Flash Player has it&#8217;s own set of Error&#8217;s with codes, and some classes even extend this class.  It must be used with throw, and only Error classes should be printed to the error dialogue in this way.  You can use others, but that&#8217;s just crazy talk.</p>
<p>You can also show the error dialogue yourself via an asynchronous exception (in this case, we&#8217;re manually doing it as opposed to say, an IOErrorEvent that fires 60 seconds after you make a URLLoader.load call because your interwebs connection went down):</p>
<pre>dispatchEvent(<span class="keyword">new</span> ErrorEvent(<span class="string">"splosion"</span>, <span class="identifier">true</span>, <span class="identifier">false</span>, <span class="string">"Boom, chakka-lakka..."</span>));</pre>
<p>When you dispatch events in the Flash Player via dispatchEvent, you don&#8217;t get an error dialogue.  A special class exists, like Error, for handling asynchronous errors, the ones that occur &#8220;later&#8221; / &#8220;in another frame&#8221; / &#8220;in another thread&#8221; / &#8220;separate from your current stack block&#8221; / &#8220;as an event&#8221;.  It&#8217;s called ErrorEvent (which extends flash.events.Event).  If you dispatch an ErrorEvent, or a class that extends ErrorEvent, you&#8217;ll trigger the error dialogue.  Both will show the dialogue regardless of where they are executed.</p>
<p><strong>Catching Errors</strong></p>
<p>It is wonderful that Adobe has given us this error facility in Flash Player for both errors and error events.  What our compiler doesn&#8217;t find, the Flash Player will point out to us at runtime.  This is helpful, and makes our code work better, and expedites the time we can get things done correctly.</p>
<p>Sadly, most people do not proactively catch these errors as evident by both the WWDC statement this week (based on my experience of error dialogues always preceding a Safari explosion), and a casual trip around the internets using the debug version of the Flash Player.  There are a variety of reasons for this including, but not limited to:</p>
<ul>
<li>not knowing how errors work</li>
<li>deadline crunch</li>
<li>laziness</li>
<li>arrogance, &#8220;This condition won&#8217;t ever happen, so&#8230;&#8221;</li>
<li>apathy, &#8220;If the back-end goes down, we&#8217;re screwed anyway, so&#8230;&#8221;</li>
</ul>
<p>I can&#8217;t fix them all, but I can hopefully fix the first.</p>
<p>You can prevent the error dialogue 2 ways.  To prevent it from showing via synchronous errors (aka throw new Error), you need to catch &#8216;em.  Unlike catching a cold, this is something proactive you need to do.  You use what&#8217;s called a &#8220;try / catch block&#8221;.  It tries to run the code inside the try portion, and if it fails, it&#8217;ll run the error portion, passing you the error that occurred.  Let&#8217;s take the same code above, and wrap the potential explosion with a try catch block:</p>
<pre><span class="keyword">import</span> flash.display.<span class="identifier2">MovieClip</span>;
<span class="keyword">var</span> mcMastaKilla:<span class="identifier2">MovieClip</span>;
<span class="keyword">try</span>
{
        <span class="identifier2">trace</span>(mcMastaKilla.x);
}
<span class="keyword">catch</span>(err:<span class="identifier">Error</span>)
{
        <span class="identifier2">trace</span>(<span class="string">"Splosion prevented: "</span> + err.<span class="identifier2">message</span>);
}</pre>
<p>Now, we&#8217;ve caught it.  We&#8217;ve prevented the error dialogue from showing, prevented our code from breaking unexpectedly, and taking a proactive opportunity to log the error (in a debug window, a trace, or whatever you use for logging/showing errors).</p>
<p>The thing to note about the catch part is that it will catch ALL errors that occur.  If you want to catch all errors, and don&#8217;t care about the type of error that happened, you can use the code I just showed you.  Sometimes this is the best way because as your code increases in size, you don&#8217;t know who &#8220;underneath&#8221; is throwing errors that will bubble up to your code (yes, Error&#8217;s bubble  like MouseEvent&#8217;s do by default, except they aren&#8217;t really events so you have to use a catch).</p>
<p>Here&#8217;s an example that catches every possible error that URLLoader.load can throw:</p>
<pre><span class="keyword">import</span> flash.net.*;
<span class="keyword">var</span> loader:URLLoader = <span class="keyword">new</span> URLLoader();
<span class="keyword">try</span>
{
        loader.<span class="identifier2">load</span>(<span class="keyword">new</span> URLRequest(<span class="string">"someurl"</span>));
}
<span class="keyword">catch</span>(argErr:ArgumentError)
{
        <span class="identifier2">trace</span>(<span class="string">"Bad headerz"</span>);
}
<span class="keyword">catch</span>(memErr:MemoryError)
{
        <span class="identifier2">trace</span>(<span class="string">"UTF-8 parsing error... or just not enough RAM for your POST data."</span>);
}
<span class="keyword">catch</span>(securityErr:SecurityError)
{
        <span class="identifier2">trace</span>(<span class="string">"Either you're local-networking, or hitting a no-no port."</span>);
}
<span class="keyword">catch</span>(typeErr:TypeError)
{
        <span class="identifier2">trace</span>(<span class="string">"t3h URL is t3h null"</span>);
}</pre>
<p>Insane, right?  One connotation that exception handling talks about is &#8220;recovering from an error&#8221;.  If your MovieClip is null, then instantiate it.  &#8230;however, why not just check for null first?  Using try/catch blocks, while a more defensive programming practice, is <strong>slower code</strong>.  So, anytime something may be null, check for null first before accessing it&#8217;s properties and methods vs. using a try/catch block.</p>
<p>&#8230;but how do you recover from the error&#8217;s above?  For most errors there isn&#8217;t much you can do.  What you can ALWAYS do is actually catch most of them, and log them.  That way you at least are aware of the problems, and can solve them (if possible) at a later point.  Even if you don&#8217;t solve them, at least your app doesn&#8217;t blow up, nor piss Safari off.</p>
<p>For events, there is no catch all catch.  Since Event type&#8217;s are magic strings, you have to manually add an event listener for each error event that can occur.  Most do not bubble, so just by adding an event listener for it, you are preventing the error dialogue from showing.</p>
<p><strong>Catch All vs. Catch Specific</strong></p>
<p>In Java, there is a keyword that goes next to functions called &#8220;throws&#8221;.  This lets you know what errors it&#8217;ll possibly throw if you call it.  Thus, you are FORCED to write code that catches those errors.  That&#8217;s why some Java code can have a lot of try/catches everywhere.  The pro, however, is that you know what you&#8217;re dealing with, and the compiler helps you.</p>
<p>We don&#8217;t have this in ActionScript 3.  So, while you can refer to the documentation to see errors URLLoader.load will throw and other boilerplate classes, there is no mechanism for custom classes for errors.  For ErrorEvents, you can utilize the [Event] metadata tag, but those are optional for code hinting.  You can put those tags on an Interface to help document intent, but the compiler doesn&#8217;t force you to write a dispatchEvent with that error event class.</p>
<p>When dealing with code, whether you know the code or not (yours vs. a 3rd party API), you should use try/catch on those methods you know can throw errors.  If you don&#8217;t, and later find methods do actually throw errors (maybe it came with no docs or original developer(s) didn&#8217;t think it&#8217;d throw an error), wrap it in a try/catch.  A default error in the catch is fine.</p>
<p>For events, ensure at the very least you&#8217;ve added event listeners for all the error events.  Just&#8230;</p>
<p><strong>Swallowing Errors</strong></p>
<p>&#8230;don&#8217;t swallow the errors.  Swallowing errors refers to having a catch block that, like<a href="http://mcbaneismesmerized.ytmnd.com/"> zee goggles</a>, does nothing.  The same goes for event listeners for error events that are empty functions.  This means that your program has an error occur, but no one ever knows about it.  Unlike the tree falling in the woods, YES the error actually occurred even though no one heard it.</p>
<p>This is a bad thing to do for 2 reasons.  First, things could be blowing up in your application, and you don&#8217;t know about it.  Like if <a href="http://www.norad.mil/">NORAD</a> suddenly evaporated, yet more death involved.   That&#8217;s like going back to AS1.  If you don&#8217;t know about an error, you cannot fix it, nor attempt to recover from it if it cannot be fixed.</p>
<p>Here&#8217;s 2 examples:</p>
<pre><span class="keyword">import</span> flash.net.*;
<span class="keyword">var</span> loader:URLLoader = <span class="keyword">new</span> URLLoader();
loader.<span class="identifier2">addEventListener</span>(IOErrorEvent.IO_ERROR, onError);
<span class="keyword">try</span>
{
        loader.<span class="identifier2">load</span>(<span class="keyword">new</span> URLRequest(<span class="string">"someurl"</span>));
}
<span class="keyword">catch</span>(err:<span class="identifier">Error</span>)
{
        <span class="linecomment">// I am...
</span>}

<span class="keyword">function</span> onError(<span class="identifier2">event</span>:IOErrorEvent)
{
        <span class="linecomment">// ... a slack bastard
</span>        <span class="linecomment">// TODO: get motivation to fix this
</span>}</pre>
<p><strong>Recovering From Errors</strong></p>
<p>Secondly, not recovering from errors usually leaves the user confused on what the heck just happened.  The app appears to be not working.  You should view catch blocks as your opportunity to provide the user with a meaningful dialogue on what happened, and/or what they can do to continue.  To say it another way, you can offload the error handling to those whose job it truly is: The Designers.  Whether IA/UX/Visual Designer&#8230; doesn&#8217;t matter.  If something breaks, what do I do?  A lot of time it&#8217;s easy.  Those crayon pushers will get a sarcastic smirk on their face when asked, &#8220;What if their internet has gone down and we try to save their work to the server?&#8221; &#8220;Dude, tell them to re-connect!&#8221;.</p>
<p>Seriously, a lot of things can go wrong in software, and this is an opportunity for you to provide a gracious error handling strategy in your app, even if it&#8217;s just showing an Alert dialogue with, &#8220;Set Sail for Fail&#8221;&#8230; that&#8217;s a cop-out though.  Again, do your best to think about why the error could occur, and what you would expect to be able to do as a user.  A lot of times you may feel like you&#8217;ll reach the inevitable conclusion, &#8220;they&#8217;re screwed&#8221;.  If you do, think harder.  Ask the designer.  You&#8217;re using a runtime capable of providing rich feedback to the user; make use of it.</p>
<p><strong>Exception to the Exceptions</strong></p>
<p>The exception to the above rules is NetStream.close().  I&#8217;m not sure why it throws an exception, but I don&#8217;t really care if it doesn&#8217;t close.  This is the one time where I always have an empty catch block; nothing negative happens if a NetStream doesn&#8217;t close, nor is there anything you can do.  I usually create new instances of NetStreams anyway.</p>
<p><strong>Error Handling Process</strong></p>
<p>There are 3 types of errors in a project.  The ones you know about, the ones you don&#8217;t, and null pointers.  The ones you know about are easy; they are in the ActionScript documentation.  Just add try/catch blocks around those methods or addEventListeners for the error events.  The ones you don&#8217;t know are from your own code throwing errors during development.  This is ok as well because you&#8217;ll find them as you develop, and even with a little QA.</p>
<p>The null pointers, however, are a separate breed.  Yes, you don&#8217;t know about them because if you did, you wouldn&#8217;t have them.  However, null pointers are notorious for sneaking by compilers.  Additionally, real-world data (hitting a production ready web service vs. the one you&#8217;ve been using for development, local XML vs. real, user entered data vs. developer entered data, etc.) has a knack for going into a system in a way the original developer didn&#8217;t expect.  That, and when real users start using it, you start having more people test more areas.  This greater area of coverage has a high probability of finding areas you and your team couldn&#8217;t find on their own based on just sheer man hours of using the app.</p>
<p>So, the errors you know and don&#8217;t know are fine; that&#8217;s the point of this article.  Catch &#8216;em, and log &#8216;em at a bare minimum.  For the null pointers, even with massive amounts of if (someVar) won&#8217;t suffice.  Just do the best you can and know post launch most of the errors you&#8217;ll get (assuming you follow my next advice) will be null pointers.</p>
<p><strong>Cure the Disease, Don&#8217;t Treat the Symptoms</strong></p>
<p>In my experience, the #1 cause of errors in AS3 based projects is bad data.  Garbage in, garbage out.  If you have data going into your code from an outside source, this is the weakest link in the chain, and is also the most often cause of problems.  If you are parsing XML into ValueObjects, and building View&#8217;s around those ValueObjects, and your View looks funny, often times it&#8217;s the parsing code.  You may think it&#8217;s a problem with your GUI code, or perhaps the Controller (code used to have Model/data passed to View/GUI controls) fubarred it during transfer.  Often, however, it&#8217;s the bloody Factories; classes or just functions responsible for parsing the data.</p>
<p>One way to prevent having to write a lot of try/catch blocks, if null tests, and adding event listeners for error events is to ensure your service layer is tight.  This means writing unit tests on all the data that gets into your system.  If you&#8217;re building a photo slideshow from external XML, write code to ensure once parsed, the Array&#8217;s of images you actually created are full of yummy Strings vs. null values.  Nothing should leave a Factory class that hasn&#8217;t been validated via quality control; in this case either if null for properties at a minimum or unit tests at the ideal level.</p>
<p>Good data in your system means most of your errors are known errors.  The more proactive you are here, the less reactive you&#8217;ll need to be later on.</p>
<p><strong>Finally</strong></p>
<p>Finally is another keyword you can put after the catch.  It will run regardless of the try or catch running.  It&#8217;s typically used for clean up.  I never use it because your code execution in a catch once complete will continue running the rest of the original function it&#8217;s in.  Additionally, I sometimes put return statements in my catches when I know I&#8217;m royally screwed, ensuring the finally will never run.</p>
<p><strong>Don&#8217;t Create Explosions: Anti-Custom Errors</strong></p>
<p>When first researching error handling in the Java world to see how they handled it, I came upon an article that explained how you SHOULD do it.  Java has been around for a long time, and they&#8217;ve already solved a lot of problems we as ActionScript developers had.  So I knew I&#8217;d probably find the answer if I did a lot of digging, and I was right.</p>
<p>The article talked about how try/catch/finally blocks make Java code very unreadable and un-encapsulated from an OOP perspective.  The first is opinion (which I agree with) and the second is fact.  While Java&#8217;s throws keyword does help you via the compiler recognizing it and ensuring your code handles it&#8230; why are they doing this?  The third is, if an API has a bunch of things that it&#8217;s attempting to handle internally, and something breaks, why is it bubbling up those problems to you as the API consumer?  While it&#8217;s really cool to know during development why at URLLoader.load fails so I can attempt to fix it, during production it&#8217;s useless.  Either it worked or didn&#8217;t; just tell me that, with details I can find if I&#8217;m so inclined.</p>
<p>Take the URLLoader.load example from above.  The ONLY error you can reasonably recover from is the 2nd SecurityError where you&#8217;re hitting a port that&#8217;s reserved or not open.  That&#8217;s it?  The rest of the situations you&#8217;re just f&#8217;ed?  If this were Java, that wouldn&#8217;t be helpful at all.  And that is the point the author makes.  Most errors are un-recoverable.  The best you can do is show a user friendly dialogue, and &#8220;do the best you can&#8221;, whether polling till the Internet is available again, or asking the user to hit a server later if your middle-tier went down (aka Twitter&#8217;s Fail Whale).</p>
<p>Since you&#8217;re effectively screwed, making life worse for the developer by forcing them to write more code to ensure they in fact know they are potentially screwed, yet cannot do much about it is a waste of time.  The author offers an alternative.</p>
<p>His suggestion is to condense errors into 1 generic one with details that those who care about can access if they want to.  Like doing 1 try/catch on URLLoader.load vs. the 4 I showed above.  Whether you get a SecurityError or an MemoryError&#8230; there isn&#8217;t anything you can do to recover in that situation.  So, if you&#8217;re writing a class, and there are a bunch of things that could go wrong, throw a generic Error instead with a public property on it that has what went wrong such as &#8220;lastError&#8221;.  In ActionScript, you can just use the Error class since it already has this for you.  Since most errors are just logged, this makes it really easy to handle.  No matter what goes wrong, your code is concise.</p>
<p>However, in ActionScript 3 I offer 2 different suggestions that I actually practice.</p>
<p>The first is don&#8217;t create explosions.  Don&#8217;t use the throw keyword; don&#8217;t throw errors.  There is no strongly typed way in ActionScript 3 currently to &#8220;know&#8221; if a class throws an error.  You break OOP by using the throw keyword.  Additionally, you leave surprises for the other developer (maybe even you) when using the code since there is no way for them to know it&#8217;ll do that unless they are intimate with it.</p>
<p>The second is to create opt-in errors.  Throws in Java are opt-out; meaning you have to write a try/catch for your code to actually compile, even if you have no intention of doing anything with the error (NetStream.close, don&#8217;t have comps from the designer yet, don&#8217;t know why an error is occuring yet, etc&#8230;).  Throws in ActionScript are opt-out in a worse way; at first they aren&#8217;t handled because you don&#8217;t know about them, and once you do, you may not like having to catch it in a variety of places.</p>
<p>You create opt-in errors by creating a class that extends Event, and has a public property called &#8220;lastError&#8221;.  When an error occurs, you create this event, set the lastError to whatever the message was on the Error, or text on an ErrorEvent, and dispatch it.  Since it doesn&#8217;t extend ErrorEvent, it won&#8217;t show the error dialogue.  This has the following pro&#8217;s:</p>
<ol>
<li>You can strongly-type the event being dispatched via the [Event] metadata tag.</li>
<li>Makes your code not unexpectedly explode.</li>
<li>Gives the developer the option to listen to an error; not forced to write more code.</li>
<li>The error handling code can be written the same way whether it&#8217;s a synchronous or asynchronous error.</li>
<li>You write your error handling code once vs. many times using try/catch around each potential method/property and multiple error events.</li>
</ol>
<p>To create an opt-in error is to create an error that can occur, but won&#8217;t blow up your app if it occurs.  The class that has the issue captures the error, logs it internally, but doesn&#8217;t allow the error to show the error dialogue.  If you give the class to another developer, you are ensuring you aren&#8217;t handing her/him a potential code grenade waiting to explode unknowingly.</p>
<p>For existing systems, or when creating API&#8217;s, you can feel comfortable you&#8217;re not part of the problem.  Your code won&#8217;t explode, and when the developers are ready to handle the errors (if ever), you have provided a simple mechnism for them: 1 event called &#8220;error&#8221;.</p>
<p>Additionally, you are giving her/him the option of handling the error.  This is very important for Flash Developers who are typically put on very tight deadlines.  A lot of times they&#8217;re not hitting a lot of error prone back-ends, their designers haven&#8217;t given a 2nd thought to errors, and/or there is already an existing culture of getting it working &#8220;good enough&#8221; to get it out of the door since agencies are deadline driven.  This may seem trivial, but it&#8217;s not.  To reiterate, in those environments, OOP is a nice to have, but if it threatens the deadline, it&#8217;s not used.  You cannot risk your Flash&#8217;s small part in a larger ad campaign because of your guilt for not following OOP Purism.</p>
<p>This makes error handling in the code more consistent.  Instead of try/catches in some places, and addEventListener&#8217;s in others; it&#8217;s all event driven.  Obviously in the lower-level classes, you&#8217;ll have to write try/catch blocks to create custom error events, but hopefully that&#8217;s abstracted away for others, and you, to not have to worry about.  An event listener is only written once, whereas try/catch around every method can get tedious and violates DRY (don&#8217;t repeat yourself) principles.</p>
<p>Here&#8217;s an example:</p>
<pre><span class="keyword">import</span> flash.net.*;
<span class="keyword">var</span> loader:URLLoader = <span class="keyword">new</span> URLLoader();
loader.<span class="identifier2">addEventListener</span>(IOErrorEvent.IO_ERROR, onError);
<span class="keyword">try</span>
{
        loader.<span class="identifier2">load</span>(<span class="keyword">new</span> URLRequest(<span class="string">"someurl"</span>));
}
<span class="keyword">catch</span>(err:<span class="identifier">Error</span>)
{
        dispatchError(err.<span class="identifier2">message</span>);
}
<span class="keyword">
function</span> onError(<span class="identifier2">event</span>:IOErrorEvent)
{
        dispatchError(<span class="identifier2">event</span>.<span class="identifier2">text</span>);
}
<span class="keyword">
function</span> dispatchError(errorString:<span class="identifier">String</span>)
{
<span class="keyword">        var</span> <span class="identifier2">event</span>:ServiceEvent = <span class="keyword">new</span> ServiceEvent(ServiceEvent.ERROR);
<span class="identifier2">        event</span>.lastError = errorString;
        dispatchEvent(<span class="identifier2">event</span>);
}</pre>
<p><strong>Another Example Opt-in</strong></p>
<p>An example of this technique is the HTTPService that comes with the Flex SDK.  It has an API for doing rest based services, aka anything related to getting dynamic data that is NOT a WebService, SOAP, or Remoting.  If it&#8217;s not those 3, you use HTTPService.  Loading JSON, XML, REST based services (aka URLVariables), text&#8230; it&#8217;s all there.  If you&#8217;ve ever cracked him open, he&#8217;s insanely complex for a class that abstracts URLLoader (there are others, but you get the point).  He only exposes 3 events, 2 of which are the only ones used by most developers: result and fault.  Result for the most part is if your stuff worked.  You may not like the data, but at least you got it (similiar to URLLoader&#8217;s Event.COMPLETE).</p>
<p>Fault, while being 1 event, has a large sub-system of error reporting.  So while you only write 1 event handler for fault, the number of errors is very large.  This makes the code easy to write, and easy to debug.  If you don&#8217;t add an event listener for fault, it doesn&#8217;t blow up in your app.</p>
<p><strong>Conclusions</strong></p>
<p>As you can see, errors are helpful in Flash Player to help you debug your code, but also require more work to handle correctly.  In addition, Safari appears to be made unstable when errors get through (sometimes Firefox), so you have incentive to at least catch them at the very least.  You should at the very least trace the error out vs. swallowing it.  When creating your own errors, make sure you dispatch an event that extends Event instead of ErrorEvent so you don&#8217;t force explosions on those (including yourself) using that code.  If the code you write has the potential for a lot of things to go wrong, make 1 error with a property for finding out more specific information about the error to keep your class encapsulated, yet easy to work with.</p>
<p>There is no global exception handling, unfortunately, so it&#8217;s hard to get all the asynchronous ones.  Additionally, it&#8217;s impossible to catch the &#8220;load never completed&#8221; error&#8230; the one that fires while the SWF is actually loading into the Flash Player itself.  Coincidentally this error is also the one that almost always crashes me Safari.  I always cringe in fear when closing tabs that has a Flash video player.</p>
<p>In the future, hopefully 3 things will happen.  First, Adobe will make it more stable (even though apparently Apple already has, haven&#8217;t tested Safari 4 enough yet&#8230; it&#8217;s still blowing up for me all the time).  Second, we can catch the un-catchable.  Third, there will be some mechnism for global exception handling so we can ship SWF&#8217;s with assurance it won&#8217;t blow up without us knowing.</p>
<p>Don&#8217;t write grenade code, write opt-in errors.</p>
<img src="http://feeds.feedburner.com/~r/jessewarden/~4/ZjMwlYvw6XQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jessewarden.com/2009/06/error-handling-in-actionscript-3-dont-make-grenades-or-how-to-not-crash-safari.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://jessewarden.com/2009/06/error-handling-in-actionscript-3-dont-make-grenades-or-how-to-not-crash-safari.html</feedburner:origLink></item>
		<item>
		<title>Flash Command: Convert to Symbol and Distribute to Layers</title>
		<link>http://feedproxy.google.com/~r/jessewarden/~3/NTCFPwpC-vM/flash-command-convert-to-symbol-and-distribute-to-layers.html</link>
		<comments>http://jessewarden.com/2009/06/flash-command-convert-to-symbol-and-distribute-to-layers.html#comments</comments>
		<pubDate>Mon, 01 Jun 2009 17:11:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://jessewarden.com/?p=1644</guid>
		<description><![CDATA[Josh was bitching on Twitter the other day about how if you select multiple objects in Flash and choose Convert to Symbol, it puts them all on the same layer, regardless of where they were before.  Others agreed that it is frustrating.  I know where he&#8217;s coming from doing production art, so I [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/joshtynjala/status/1941727119">Josh</a> was bitching on Twitter the other day about how if you select multiple objects in Flash and choose Convert to Symbol, it puts them all on the same layer, regardless of where they were before.  Others agreed that it is frustrating.  I know where he&#8217;s coming from doing production art, so I built this quick Command to do just that.  If you save in your Commands folder, and re-boot Flash, you can re-map your F8 key to use this Command instead of the regular Convert to Symbol Command.</p>
<p><span id="more-1644"></span>
<pre>fl.getDocumentDOM().convertToSymbol(<span class='string'>'movie clip'</span>, <span class='string'>''</span>, <span class='string'>'top left'</span>);
fl.getDocumentDOM().enterEditMode(<span class='string'>''</span>);
fl.getDocumentDOM().distributeToLayers();</pre>
<p></p>
<p>Also, you can create simple Commands like this on your own.  Just do what I did, and open up your History Panel via Window > Other Panels.  The top right of the Panel has a menu that allows you to see the JavaScript of your actions.  You can then copy-pasta from there!</p>
<img src="http://feeds.feedburner.com/~r/jessewarden/~4/NTCFPwpC-vM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jessewarden.com/2009/06/flash-command-convert-to-symbol-and-distribute-to-layers.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://jessewarden.com/2009/06/flash-command-convert-to-symbol-and-distribute-to-layers.html</feedburner:origLink></item>
		<item>
		<title>Utilizing Namespaces to Indicate Framework Usage</title>
		<link>http://feedproxy.google.com/~r/jessewarden/~3/pr7Olv0x_Rs/utilizing-namespaces-to-indicate-framework-usage.html</link>
		<comments>http://jessewarden.com/2009/05/utilizing-namespaces-to-indicate-framework-usage.html#comments</comments>
		<pubDate>Fri, 29 May 2009 22:36:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://jessewarden.com/?p=1630</guid>
		<description><![CDATA[When utilizing PureMVC Mediator&#8217;s, there are 2 ways I&#8217;ve seen people write them.  The first way is to have the Mediator call methods on the View, passing data it retrieved from a Proxy.  This can also be done from a Command as well.  The second way is to actually give the Mediator/Command [...]]]></description>
			<content:encoded><![CDATA[<p>When utilizing <a href="http://puremvc.org">PureMVC</a> Mediator&#8217;s, there are 2 ways I&#8217;ve seen people write them.  The first way is to have the Mediator call methods on the View, passing data it retrieved from a Proxy.  This can also be done from a Command as well.  The second way is to actually give the Mediator/Command more responsibility of State management for a particular View, and call more than 1 method on it, doing a lot of code that&#8217;s often done in the View.</p>
<p>Both have the same problem: methods in the View that only PureMVC calls, yet exist for others to inadvertently use because they are public.</p>
<p><span id="more-1630"></span>This is apparent when you&#8217;re in the View, and type in &#8220;this.&#8221;.  In FlexBuilder, <a href="http://fdt.powerflasher.com/">FDT</a>, or <a href="http://www.flashdevelop.org/community/">FlashDevelop</a> you&#8217;ll get a code hint with all the methods and properties you&#8217;re allowed to utilize.  You often don&#8217;t want the PureMVC functions because only PureMVC Mediator&#8217;s will be calling those.  Worse, since these functions have to be public for Mediator&#8217;s to access them, other View&#8217;s and classes can use these functions in inadvertently as well.</p>
<p>It&#8217;s a minor problem when it&#8217;s just you working on the code and you ignore them.  If you work with a team, are handing off the code to others, or just have a LOT of View&#8217;s, namespaces can help ensure it doesn&#8217;t become a bigger problem for others who don&#8217;t know what you do by providing a better API.</p>
<p>For example, in one PureMVC application I have, I utilize a namespace specifically for PureMVC to use.  That way, only he uses it.  Since it&#8217;s called &#8220;puremvc_internal&#8221;, it&#8217;s pretty obvious that it&#8217;s for PureMVC to use vs. &#8220;public&#8221; meaning anyone can.</p>
<p>Here&#8217;s a traditional Mediator making a call on its View component:</p>
<pre><span class="keyword">case</span> ApplicationFacade.SAVE_POWER_FILE_AS_SUCCESS:
	<span class="keyword">var</span> savePowerFileAsProxy:SavePowerFileAsProxy = facade.retrieveProxy(SavePowerFileAsProxy.NAME) as SavePowerFileAsProxy;
	mainView.onSavePowerFileAsSuccess(savePowerFileAsProxy.powerFile);
	<span class="keyword">break</span>;
</pre>
<p>And here&#8217;s the method the View is exposing specifically for this purpose:</p>
<pre><span class="keyword">public</span> <span class="keyword">function</span> onSavePowerFileAsSuccess(powerFile:PowerFileVO):<span class="keyword">void</span>
{
        removeCreateWindow();
        openPowerWindow(powerFile);
}</pre>
<p>Being public, both the View itself, and others can access this method even though you most likely don&#8217;t want anyone except PureMVC accessing it.  Creating a PureMVC specific namespace, you can not only ensure this, but also document who the method is for.</p>
<p>Four steps, ready?</p>
<p>First, create a namespace, and save it like any other class:</p>
<pre>package com.jxl.powerz.puremvc
{
        <span class="keyword">public</span> namespace puremvc_internal = <span class='string'>"http://jessewarden.com/dougmccunehasnicetatas/2009/puremvc/"</span>;
}</pre>
<p>Second, use this namespace in your Mediator/Command class:</p>
<pre><span class="keyword">import</span> com.jxl.powerz.puremvc.puremvc_internal;

use namespace puremvc_internal;

<span class="keyword">public</span> <span class="keyword">class</span> MainViewMediator <span class="keyword">extends</span> Mediator</pre>
<p>Third, call the method using the PureMVC namespace instead of the public one:</p>
<pre><span class="keyword">case</span> ApplicationFacade.SAVE_POWER_FILE_AS_SUCCESS:
	<span class="keyword">var</span> savePowerFileAsProxy:SavePowerFileAsProxy = facade.retrieveProxy(SavePowerFileAsProxy.NAME) as SavePowerFileAsProxy;
	mainView.puremvc_internal::onSavePowerFileAsSuccess(savePowerFileAsProxy.powerFile);
	<span class="keyword">break</span>;</pre>
<p>Finally, define the method using the PureMVC namespace instead of the public one:</p>
<pre><span class="keyword">import</span> com.jxl.powerz.puremvc.puremvc_internal;

use namespace puremvc_internal;

puremvc_internal <span class="keyword">function</span> onSavePowerFileAsSuccess(powerFile:PowerFileVO):<span class="keyword">void</span>
{
        removeCreateWindow();
        openPowerWindow(powerFile);
}</pre>
<p>You can also utilize this technique using <a href="http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm">Cairngorm</a> and the <a href="http://code.google.com/p/flexcairngorm/">Universal Mind Cairngorm Extensions</a>.  Just modify the <a href="http://code.google.com/p/flexcairngorm/source/browse/trunk/code/src/com/universalmind/cairngorm/events/Callbacks.as">Callbacks.as</a> file to call the resultHandler and faultHandler functions in the correct namespace, and you should be  good to go.</p>
<img src="http://feeds.feedburner.com/~r/jessewarden/~4/pr7Olv0x_Rs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jessewarden.com/2009/05/utilizing-namespaces-to-indicate-framework-usage.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://jessewarden.com/2009/05/utilizing-namespaces-to-indicate-framework-usage.html</feedburner:origLink></item>
	</channel>
</rss>
