<?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>Vivisecting Media &#187; Flex Development</title>
	<atom:link href="http://blog.vivisectingmedia.com/category/ria/flex-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vivisectingmedia.com</link>
	<description>Looking at the world of media: from music to RIA.</description>
	<lastBuildDate>Fri, 09 Oct 2009 15:29:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Announcing DevelopmentArcâ„¢ Core Release Version 0.5</title>
		<link>http://blog.vivisectingmedia.com/2009/02/announcing-developmentarc%e2%84%a2-core-release-version-05/</link>
		<comments>http://blog.vivisectingmedia.com/2009/02/announcing-developmentarc%e2%84%a2-core-release-version-05/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 18:37:47 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web integration]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/?p=169</guid>
		<description><![CDATA[The newest release of DevelopmentArc Core is now available on the Google Code Repository.  This release is the first release of the library under the new Core moniker.  Previously the library was released under the Vivisecting Media Code Library, which has been now been deprecated since Core is publicly available.  All updates [...]]]></description>
			<content:encoded><![CDATA[<p>The newest release of <a title="Read more about DevelopmentArc Core" href="http://www.developmentarc.com/site/software/" target="_self">DevelopmentArc Core</a> is now available on the <a title="Read the Wiki and download the library" href="http://code.google.com/p/developmentarc-core/" target="_blank">Google Code Repository</a>.  This release is the first release of the library under the new Core moniker.  Previously the library was released under the Vivisecting Media Code Library, which has been now been deprecated since Core is publicly available.  All updates and new features will be added to the Core system moving forward.</p>

<p>From the code depot you can download a compiled SWC or a ZIP file that contains all the source and ASDoc generated files.  We have posted the <a title="DevelopmentArc Core ASDoc Files" href="http://www.developmentarc.com/core_asdoc/" target="_blank">ADoc files on-line</a> so that you can easily access them if you do not download them.  Currently, we have 219 unit tests running and passing for the library, which are all available from the source tree if you wish to access them.</p>

<p>The current release of Core contains the following functionality.  We have marked new and updated features that have been changed from the Vivisecting Media Library to the new Core Library:
<ul>
    <li><strong>Task Management System</strong> <span style="color: #ff6600;">new!</span> &#8211; The Task system is a priority queuing system that enables an application to execute specific bundles of business and/or server logic in a specific order leveraging priority and the ability to override previously queued bundles. These bundles are encapsulated inside of Task objects, which can be then bundled Task Group objects. Tasks and task groups have the ability to take priority over other Tasks or Task Groups inside of the queue, as well as replace existing tasks in the queue based on a set of overrides an individual task can define.</li>
    <li><strong>Command Action Delegation System (CAD)</strong> <span style="color: #ff6600;">new!</span> &#8211; Provides a pre-built solution for implementing the Command Pattern within ActionScript/Flex/AIR applications. The command / action system allows for commands to be dispatched to the ActionDelegate which then executes any assigned functionality via an Action.</li>
    <li><strong>Selection Management System</strong><span style="color: #008000;"> updated!</span> &#8211; The Selection Management system enables any kind of object to become selectable and treated as part of a Selection group. In most cases this would be a UI Component that should behave similarly to a radio button group, where only one item can be selected at one time. This system also allows for multi-select and deselection of items that are members of a selection group.</li>
    <li><strong>Local Connection Management</strong> <span style="color: #008000;">updated!</span> &#8211; The Local Connection manager is a helper class to quickly establish and manage local connection instances within an application. The Local Connection manager also supports the ability to maintain strong class types when the data object is passed over the local connection instance.</li>
    <li><strong>Event Broker Utility</strong> &#8211; The Event Broker is a utility class that acts as a router for specified events. The Event Broker is a single point of contact that any object can broadcast to or subscribe to. This functionality is intended to be the focal point for implementing the mediator pattern within the application.</li>
    <li><strong>Instance Factory Utility</strong> <span style="color: #ff6600;">new!</span> &#8211; The Instance Factory allows for the ability to make sure there is only one instance of a specified class within the instance of the factory. This is useful for using in Locators that handle generating a new instance on the first request but then making sure the original instance of the requested item is returned on subsequent requests.</li>
    <li><strong>Singleton Factory Utility</strong> <span style="color: #ff6600;">new!</span> &#8211; Similar to the Instance Factory, the Singleton Factory verifies that there is only one instance of a requested item, but instead of being limited to the instance of the factory, the Singleton Factory verifies there is only one instance of the requested item in the entire application.</li>
    <li><strong>Adjustable Date Utility</strong> <span style="color: #ff6600;">new!</span> &#8211; The adjustable date wraps a Flash Date object and provides a series of helper methods to adjust time and dates quickly and easily. Example uses included the ability to adjust a date by a specific number of days forward or backwards, making sure that the number of days in the month and Leap Years are respected during the adjustment.</li>
    <li><strong>Queue Data Structures </strong><span style="color: #008000;">updated!</span> &#8211; The Queue system allows for items to be stored in either a LIFO or FIFO based queue order or in a priority queue order and then retrieved from the data structure depending on how the items are ordered.</li>
    <li><strong>Hash Table Data Structure</strong> &#8211; The Hash Table is key/value that allows any value or object to be used as a reference key to another value or object item. The Hash Table is similar to Flex&#8217;s ArrayCollection in how items can be referenced but unlike the collection, this is ActionScript independent, is not intended for data pagination and is focused on performance for larger data sets.</li>
    <li><strong>Browser Location Utility</strong> <span style="color: #ff6600;">new!</span> &#8211; Utility class used to query the current url in the application. The class provides static properties for each piece of the application url.</li>
</ul>
I am really proud of all the work DevelopmentArc has put into Core so far.  We are currently working on the version 0.9 release roadmap which includes multiple new systems, helpers and utilities.  <em>FYI</em> &#8211; the 0.5 release number is used to announce the step from the 0.4 release of Vivisecting Medias to the Core name.  The 0.9 release will contain all of the target features for the 1.0 release of Core.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2009/02/announcing-developmentarc%e2%84%a2-core-release-version-05/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe MAX 2008: The Future of Flex Builder (Part Two)</title>
		<link>http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-two/</link>
		<comments>http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-two/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 18:45:53 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[MAX 2008]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[web integration]]></category>
		<category><![CDATA[adobe max]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[Gumbo]]></category>
		<category><![CDATA[max]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-two/</guid>
		<description><![CDATA[In my previous post, I introduced the &#8220;Future of Flex Builder&#8221; session I attended at Adobe MAX North America, how the Flex Builder team is approaching new feature development and looked at the two main Design Fidelity features they are adding to Flex Builder.

Adobe MAX 2008: The Future of Flex Builder (Part One)

In this post [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post, I introduced the &#8220;Future of Flex Builder&#8221; session I attended at Adobe MAX North America, how the Flex Builder team is approaching new feature development and looked at the two main Design Fidelity features they are adding to Flex Builder.</p>

<p><a href="http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-one/" title="Adobe MAX 2008: The Future of Flex Builder (Part One)">Adobe MAX 2008: The Future of Flex Builder (Part One)</a></p>

<p>In this post I will be delving deeper into the new/updated feature set that focuses on the aspect of the &#8220;Test &amp; Tune&#8221; workflow.  Test &amp; tune is the day-to-day development workflow that we are all used to: Navigating our projects, creating new code, documenting, re-factoring, debugging and testing.  A lot of these features may seem small but they provide a lot of power and can drastically improve development time and ease frustration that we experience during the development cycle.</p>

<p><span id="more-168"></span>
<strong>Package Explorer</strong></p>

<p>The first test &amp; tune feature I want to examine is the new Package Explorer.  Some of you may be thinking to yourself that Flex Builder already has a Package Explorer and wondering why this is a new feature.  Well, to be exact, Flex Builder 3 does not have a true Package Explorer, what it has is the &#8220;Flex Navigator&#8221; which is really just a folder browser.  When we use the Flex Navigator we often treat it like a package explorer since ActionScript packages are just folder hierarchies and this is what is represented within the Flex Navigator.  The new Package Explorer merges the functionality of the Flex Code Outline panel and the Flex Navigator into one view.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/package-explorer.png" alt="Package Explorer" /></p>

<p>Take a look at the screen cap, first you will notice that the MXML root file is now in a <em>(default package)</em> node within the explorer.  From there you can then expand the MXML file data to look at the Classes contained and the properties of the class.  Next, you can see that the default view makes the hierarchy a flat layout.  For example, the package &#8220;com.developmentarc.test&#8221; is listed all in one line which means you don&#8217;t have to expand to view the structure to access a deep package like you would in the Flex Navigator.  If you don&#8217;t like the flat layout you can change the settings of the Package Explorer to create the more traditional parent/child structure.  </p>

<p>Finally, look at the Flex 4 SWC package in the screen cap.  The Flex SDK version for the project is now shown in the Package Explorer.  Not only is it shown but you can expand the SWCs to see the content structure, classes and properties contained within.  In the screen cap I am exploring the Array in the playerglobal.swc file.  This SWC exploration also works with 3rd party SWCs, not just the Flex 4 SDK. These all may seem like small changes, but it makes exploration, creation and modification of existing projects much easier. This also allows for Java Eclipse users to experience a much more familiar view when developing Flex Applications.  Good stuff.</p>

<p><strong>Event Auto-generation</strong></p>

<p>During development, creating event bindings and method handlers such as the Mouse click event, is a common task.  The event auto-generation is a short cut feature in Design View that allows a developer to quickly generate an event handler for a component.  The example they used in the session was adding an event handler for a Button&#8217;s click event.  From design view the developer would click on the generate handler button next to the on click event field:</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/event-creator.png" alt="Event Creator" /></p>

<p>When the user clicks this button, the handler function is generated in an &lt;Script&gt; block within the MXML file and the method is then assigned to the Button&#8217;s click property.  My personal feelings about this feature is that it is helpful for initial development and/or learning of the Flex event handling model, but for complex development I am hesitant to see this as a go to feature.  For one, the feature automatically adds the script to the current MXML file.  On larger projects I typically avoid having scripts in MXML, this is especially true when <a href="http://blog.vivisectingmedia.com/2008/04/the-flex-code-behind-pattern/" title="The Code Behind Pattern">following the code-behind pattern</a>.  I also feel this is going against the proposed workflow model that Adobe is pushing for Flash Catalyst and Flex Builder integration since your MXML is becoming more layout-centric with Classes for logic.</p>

<p>Overall, its a helpful feature and it makes prototyping, initial development and demoing a lot easier.  We will see how this feature matures and how it is adopted by developers in the future.</p>

<p><strong>ASDoc</strong></p>

<p>ASDoc-ing is the process of adding specially formatted comments to your code that enables the ASDoc tool to generate documentation from the code and formatted comments.  ASDoc is just like JavaDoc and has been evolving and maturing the the first release of Flex. One feature that has been part of Eclipse&#8217;s Java development suite is the ability to see inline contextual JavaDoc notes for specific Classes, properties and/or methods.  The next version of Flex Builder supports the same kind of in-context doc hinting for code that has been properly ASDoc-ed.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/asdoc-example.png" alt="Asdoc Example" /></p>

<p>When a user hovers over a method, property or class in either ActionScript or MXML the ASDoc tooltip will display showing the contextual docs for the specified attribute.  In the screenshot above, I am hovering over the &#8220;left&#8221; attribute of an &lt;FxButton&gt; tag.  Notice that the displayed doc notes are only for the &#8220;left&#8221; property.  If I rolled over &lt;FxButton portion of the tag you would see the ASDoc content for just FxButton. Not only can you view content inline, there is now a ASDoc panel that can be added to you workspace layout.  This panel automatically updates when you click on a property, method, class, tag or attribute.  This way you can have the view up and accessing ASDoc content without having to wait for the rollover event.</p>

<p>The ASDoc feature also works within your own code.  For example, if you are developing a custom Class and provide properly formatted ASDocs in the Class, the ASDoc window/tooltip will show your ASDoc notes whenever you reference your Class in the application.  The Flex team is also working on a new SWC format nicknamed &#8220;Fat SWC&#8221;.  This Fat SWC will now include all ASDoc notes that are provided in the source code for the SWC compilation.  This means that when you use a &#8220;Fat SWC&#8221; in your project, you will get ASDoc hints for any of the Classes, properties, methods, tags or tag attributes that are contained within the SWC.</p>

<p><strong>New Re-factoring Features</strong></p>

<p>There are two new re-factoring features that were demonstrated during the session, both of which help automate tasks that developers do on a weekly, if not daily basis.  The first feature is the ability to auto-generate a getter/setter pair from an existing property.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/get-set-dialog.png" alt="Get Set Dialog" /></p>

<p>To use this feature you first select, or apply cursor focus, the property that you want to convert to a getter/setter pair.  You can then either <em>right click &gt; source &gt; Generate Getter Setter&#8230;</em> or you can choose the <em>Source &gt; Generate Getter Setter&#8230;</em> menu option.  This brings up the above options dialog where you can decide if the existing property should become private, what the new name of the property should become (it defaults to a single underscore prefix), the name of the exposed get / set method, should it create both the get and set method, or just one or the other and finally where the new methods should be added.</p>

<p>This is one of those at first glance small yet super powerful features.  During development there are many times where you need to convert a basic public property to a get/set pair and this helps write the code quickly and elegantly. One other cool thing to note about this feature is its ability to remember your preferred prefix.  As I mentioned earlier, the default is a single underscore prefix for the private method.  I personally prefer a double underscore prefix for my get/set value properties and when I added that additional underscore Flex Builder remembered this and kept the double underscore when I used the re-factor function again.  Very, very cool.</p>

<p>The second re-factoring feature, isn&#8217;t really new, its just a lot more complete.  When re-factoring the code-base, one of the biggest challenges is the process of moving Classes around to new packages.  This may occur for all kinds of different reasons: better project organization, company name changes, project changes, etc. etc.  Eclipse (which Flex Builder is built upon) supports the move option, yet in the current release this would just move the resource to the new folder and not update the Class&#8217; package structure and linkage throughout the workspace.  If you used the rename function, Flex Builder would handle all the updating for you, so it always felt as if the functionality was half-complete.</p>

<p>Well, now move is finally fully supported.  This is great news for those of us that have had to spend five minutes moving resources and then the next hour fixing the compiler errors.  Typically the process was move the resource, build the project, look for errors, updating bad references, re-build the project, looking for bad references, rinse and repeat.  This can get really ugly when you have 800+ classes (which I have had in the past) and you are doing a massive project re-structure.  Not fun, let me tell ya.  When you choose to move an asset you get to choose what package to move it to and Flex Builder handles updating all the linkage references and package declarations.  </p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/move-example.png" alt="Move Example" /></p>

<p>One thing to note, in the current preview build of Flex Builder the package has to exist before you move the resource to it.  If I recall, David Zuckerman mentioned that this will change in the future.  Even if it doesn&#8217;t this is a great feature, one that I want NOW. It would have been soooo nice yesterday when I had to move a ton of MXML classes around and re-link them throughout the project, oh well.</p>

<p><strong>Code Templates</strong></p>

<p>Code templates are more or less self exactly what they sound like.  A code template is similar to an email signature in that it provides the ability to auto-fill predefined content when a new MXML, ActionScript or CSS file is created.  In a way, we have already been using Code Templates when we generate a new ActionScript class.  The provided package structure, class declaration and constructor are all generated by the Code Template engine.  The difference is that in the next version of Flex Builder this will all be exposed to you and fully modifiable.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/code-templates.png" alt="Code Templates" /></p>

<p>Are you working on a MIT or other licensed project? You can now add the license block to the template code and any new file will have the proper structure.  You can predefine code blocks, ASDoc blocks, code layout and preferred structures all within the code templates.  You can also use variables that set time, file path, names, etc. into the template.  On top of that you can export your created templates, pass them around and have others import the template into their Flex Builder.  This is great if you work with multiple developers and want to create better coding standards or if you want to create company or open source project specific structures.  Again, a simple yet very powerful feature that is being exposed to us.</p>

<p><strong>Code Navigation</strong></p>

<p>The last Test &amp; Tune feature I am going to talk about in this post is code navigation.  Code navigation shows a developer in code view what methods are overrides and implementations of interfaces. It also allows for quick navigation up to the parent reference when the triangle icon is clicked.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/code-navigation.png" alt="Code Navigation" /></p>

<p>This is a nice feature because in the past you had to look at the Interface itself to determine what methods are implemented in the current class related.  Overriding was generally easy to see at a glance because of the override keyword but getting to the parent method instance was not so easy.  This feature enables both code readability and better navigation within the application.</p>

<p>Well, that is all for now.  I have three more topics to write about, two more test &amp; tune and then a look at the new Data service support.  I will save those for the final post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-two/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe MAX 2008: The Future of Flex Builder (Part One)</title>
		<link>http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-one/</link>
		<comments>http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-one/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 19:12:38 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[MAX 2008]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web integration]]></category>
		<category><![CDATA[adobe max]]></category>
		<category><![CDATA[Flash Catalyst]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[Gumbo]]></category>
		<category><![CDATA[max]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-one/</guid>
		<description><![CDATA[One of the more interesting sessions at MAX this year was the Future of Flex Builder.  The session was presented by Rob Brambley III, Tim Buntel, Tom Lane, David Zuckerman of the Flex Builder team.  Tim Buntel, product manager for Flex Builder, started the session by first talking about how most users approach [...]]]></description>
			<content:encoded><![CDATA[<p>One of the more interesting sessions at MAX this year was the Future of Flex Builder.  The session was presented by Rob Brambley III, Tim Buntel, Tom Lane, <a href="http://davidzuckerman.com/adobe/" title="David Zuckerman - Flex Builder Engineer">David Zuckerman</a> of the Flex Builder team.  Tim Buntel, product manager for Flex Builder, started the session by first talking about how most users approach Flex Builder and how the development team is focusing on new features to make these user approaches easier.  From Adobe&#8217;s research, most Flex Builder users approach using Flex Builder from two main entry points:</p>

<ul>
<li>Design Fidelity / UI Creation</li>
<li>Data / Service Management</li>
</ul>

<p>Design Fidelity / UI creation is focused around a Flex developer that is responsible for bringing in the initial design for that application and making it a reality.  This process includes layout, skinning, styling, animation and effects creation with the core goal of meeting the required design fidelity for the final product.  The second entry point is for the developer that is responsible for the Data / Services management aspect of the application.  This process includes creating data services, data model creation and loading management.  To be clear, these two separate approaches do not mean they are handled by different developers, this is just a way at looking at how developers approach their Flex development duties.</p>

<p>Because there are the two main entry points for most developers, the Flex Builder team is first working on new and improved features that focus on these two areas.  There is also a general initiative to work on improving general day-to-day use in Flex Builder, re-factoring management and debugging of Flex applications (they called this process &#8220;Test &amp; Tune&#8221;).  This general initiative covers both the design and the data aspect of application development.</p>

<p>I am going to be breaking this article into three separate posts.  This first post will cover the workflow and new features added to Flex Builder for the Design Fidelity aspect of development.  Post two will cover the overall day-to-day use features that are being updated/added and how the Flex Builder team is improving the &#8220;Test &amp; Tune&#8221; workflow.  The third post will look at the data services features that are being added to the Flex Builder 4 (Gumbo).  One thing to note is that this session was a mini sneak-peek of Flex Builder, and there is a chance (albeit very small) that some of the features discussed in the post may not see the light of day (or change drastically).  Also, all the screen caps in the posts are from the MAX Preview release, so there is always a chance that the UI and functionality shown will change.  Okay, let&#8217;s get to it!</p>

<p><span id="more-160"></span>
<strong><em>Design Fidelity Features</em></strong></p>

<p><strong>Theme Management</strong>
The first new feature they examined is Flex Theme management and installation.  Themes are not a new concept, they have been around since at least Flex 2 (I can&#8217;t recall if Flex 1/1.5 supported them, I think they did). A Theme contains style and skins assets for every Flex SDK component and is applied to your application during the compile process.  The idea behind a theme is that you can apply a unified style across your application without having to go in and skin each component yourself.  If you are familiar with WordPress, its the same concept as their themes; all the functionality stays the same but the look and feel can be drastically different.</p>

<p>The <a href="http://www.scalenine.com/gallery/" title="ScaleNine: Flex Themes">Theme market for Flex appears to be growing</a>, but adding a theme to an app requires <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=styles_12.html" title="Using Themes in Flex / Flex Builder">making compiler argument changes</a> to make sure the theme&#8217;s assets are loaded and compiled into the generated SWF or AIR application.  This means that the Flex Builder developer has to configure the project properties in the tool to make sure the Theme is applied. I have personally not used Themes in my applications due to the fact that all of the projects I have worked on have design teams and/or unique design requirements, but I have played around with themes in the past.</p>

<p>The Flex Builder team has seen the growing popularity of Themes and they want to make Theme installation a much easier process.  Themes are packaged as SWC files that contain all the CSS and style assets.  When a user downloads the SWC file to their machine they can then choose to install the theme into Flex Builder.  To install a Theme, the user chooses the Import Theme&#8230; option which allows the user to point to the Theme file.  The theme is then imported into Flex Builder and it can be selected from the new Theme management dialog.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/11/flex-builder-4-preview-release-theme-manager.png" alt="Flex Builder 4 Preview Release Theme Manager" /></p>

<p>You can access the theme management dialog by clicking on the &#8220;Manage Themes&#8221; link above the UI component panel in Design View.  This dialog shows all the currently installed themes and a thumbnail of what the theme looks like.  You then select what theme you want to apply and this updates the complier options for you and rebuilds Design view using the new theme.  It also sounds like they are working on streamlining theme creation and how they are distributed to make theme use easier and more popular.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/11/flex-builder-4-preview-theme-manager.png" alt="Flex Builder 4 Preview Theme Manager" /></p>

<p><strong>Catalyst and FXP Support</strong></p>

<p>The next Design Fidelity workflow feature is the ability to handle importing and exporting of <a href="http://labs.adobe.com/technologies/flashcatalyst/" title="Adobe Flash Catalyst on Labs">Flash Catalyst</a> project files.  Flash Catalyst is a new design/development tool by Adobe that is centered around creating and styling Flex applications. One of the most challenging processes of Flex development is applying complex custom UIs into your final application.  The goal of Catalyst is to allow a designer or developer to import assorted creative asset formats, such as Photoshop files, Illustrator files and Fireworks files and then quickly build Flex UIs using the creative assets&#8217; contents (layers, symbols, etc.). Once the layout / styling is done the Catalyst user can save their Catalyst built application as an FXP file and pass this on to a Flex developer to wire it up to data services and functionality. The FXP file created by Catalyst is a zipped version of a Flex Builder project which means that a Catalyst user can share their work with a Flex Builder developer or visa versa.  This gets us into the new FXP feature and workflow being added to Flex Builder 4.</p>

<p>Flex Builder 4 has the ability to import an FXP file and then create a project within Flex Builder from the FXP file.  This imported project has all the structure and content that was created inside Catalyst.  From there the Flex Builder user can begin adding functionality to the Catalyst generated project, such as data binding and data service management.  As the project moves along there will come a time where the UI will need to be modified.  At this point the Flex Builder user can export the Flex Project back into the FXP file format and pass this to the Catalyst user.  The Catalyst user can then open the FXP file, make the UI additions and then hand the FXP back to the Flex Builder user.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/import-fxp-dialog.png" alt="Import FXP Dialog" /></p>

<p>At this point, when the Flex Builder user imports the updated FXP it recognizes that the project already exists and provides the option to allow the user to merge the Catalyst changes into the existing project. When the user selects merge, the project conflicts are then highlighted in red within the project view and the user can then right click on the conflicted files to show a merge tool view that enables the user to determine what changes to bring into the project.  This current workflow is in its very early stages and I assume that it will be both improved and changed as development/testing/feedback is provided.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/12/conflict-and-merge-view.png" alt="Conflict and Merge View" /></p>

<p>The focus of the FXP support within Flex Builder is to help create a better streamlined workflow between the design and development aspect of Flex. My example above assumes that your Catalyst and Flex Builder user are different people, but this workflow can be used by a single person going between Flex Builder and Flash Catalyst. As both of these products move forward in development I expect to see a lot of discussions around integration, workflow and best practices for planning and structuring your Flex projects.</p>

<p>That&#8217;s all for now&#8230; The next post for this article will cover the new Test and Tune features that are being added to Flex Builder.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/12/adobe-max-2008-the-future-of-flex-builder-part-one/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Turkey Day Travels</title>
		<link>http://blog.vivisectingmedia.com/2008/11/turkey-day-travels/</link>
		<comments>http://blog.vivisectingmedia.com/2008/11/turkey-day-travels/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 15:49:52 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[General Media / Stuff]]></category>
		<category><![CDATA[MAX 2008]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[degrafa]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[milan]]></category>
		<category><![CDATA[travel]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/11/turkey-day-travels/</guid>
		<description><![CDATA[Its the day before Thanksgiving, Turkey&#8217;s eve I guess, the most glorious of American gluttony-days, uh I mean holidays. A wonderful day full of family, football and of course food. Oh the food!  I am only being semi-facetious, I really do love the three F&#8217;s of the holiday.  This year, the travel is [...]]]></description>
			<content:encoded><![CDATA[<p>Its the day before Thanksgiving, Turkey&#8217;s eve I guess, the most glorious of American gluttony-days, uh I mean holidays. A wonderful day full of family, football and of course food. Oh the food!  I am only being semi-facetious, I really do love the three F&#8217;s of the holiday.  This year, the travel is crazy.  I am flying down to Southern California to spend the holiday with my fiancÃ©e&#8217;s family and then I fly back home Friday night to pack and then Aaron and I head out to Milan for the Adobe MAX EU the next evening.</p>

<p>Aaron and I have a TON of notes and thoughts that are being worked on, all thanks to MAX North America.  I am sure we will have even more coming from MAX EU. We will both be working on a ton of new posts over the coming few weeks and at the same time we are in the process of getting our <a href="http://www.developmentarc.com/">DevelopmentArc site</a> proper (don&#8217;t forget client work and other assorted projects we are working on too!).  More to come on that later.  So, for those of you in/from the States that celebrate T-day, enjoy!  For those of you that don&#8217;t, no worries, you can laugh at us as we Americans stumble around in a triptiphane induced food coma.</p>

<p>Oh, and for those of you that read this blog for Flex/Flash/Technology info, read up on my newest obsession while I am away: <a href="http://www.degrafa.org/" title="Degrafa Framework Website: Download, Docs and Examples">Degrafa</a>. Degrafa is short for &#8220;<strong>De</strong>clarative <strong>Gra</strong>phics <strong>F</strong>r<strong>a</strong>mework&#8221; and it is a set of Classes that enable you to create simple to complex graphical content using MXML instead of having to write a bunch of ActionScript graphics calls.  But that is just the tip of the iceberg, you can actually make <a href="http://www.jamesward.com/wordpress/2008/04/15/flex-3-skin-transitions-with-degrafa-and-animatecolor/" title="James Ward's post on skinning a component, best example using states">component skins (states and all!)</a> using their framework.  Its rare for me to get this excited about a new framework, I am usually super hesitant about jumping in, but after a demo at the MAX Birds of a Feather, and now getting my hands dirty in it, I am super impressed.  Good work guys!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/11/turkey-day-travels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binding Source for Flex 4 in Flex Builder 3</title>
		<link>http://blog.vivisectingmedia.com/2008/08/binding-source-for-flex-4-in-flex-builder-3/</link>
		<comments>http://blog.vivisectingmedia.com/2008/08/binding-source-for-flex-4-in-flex-builder-3/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 22:48:50 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[mxml]]></category>
		<category><![CDATA[mxmlstates]]></category>
		<category><![CDATA[specs]]></category>
		<category><![CDATA[states]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/08/binding-source-for-flex-4-in-flex-builder-3/</guid>
		<description><![CDATA[Yesterday, I sat down and started playing around with trying to get the daily build of the Flex 4 SDK inside Flex Builder 3.  After a bit of digging I finally got it all running and compiling as expected.  I started off using Multimediacollege&#8217;s blog post on getting the SDK in place and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-105" style="float: left; margin-top: 5px; margin-bottom: 5px; margin-left: 10px; margin-right: 10px;" title="flex_logo" src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/04/flex.png" alt="Flex Logo" width="60" height="60" />Yesterday, I sat down and started playing around with trying to get the daily build of the Flex 4 SDK inside Flex Builder 3.  After a bit of digging I finally got it all running and compiling as expected.  I started off using <a href="http://blog.multimediacollege.be/2008/07/how-to-create-your-first-application-in-flex-4-using-flex-builder-3/" title="How to create your first application in Flex 4 using Flex Builder 3">Multimediacollege&#8217;s blog post on getting the SDK in place</a> and I also used <a href="http://sherifabdou.com/2008/07/if-you-are-trying-to-compile-gumbo-flex-4-and-getting-a-verify-error/" title="If you are Trying to Compile Gumbo (Flex 4) and getting a Verify Error">Sherif Abdou&#8217;s post to help troubleshoot a runtime error</a> in the player.</p>

<p>My goal was to take these two posts, summarize them and show how to get the current source and check it in.  Just as I sat down to write this all up, <a href="http://www.mikechambers.com/blog/" title="Mike Chambers">Mike Chambers</a> comes in and scoops me.  Figures.  Anyway, I yelled at Mike via IM for stealing my thoughts and then mentioned that I figured out how to bind the Flex 4 source to the SWC in Flex Builder so that you can F3 / CTRL+Click you way to the code.  So, I am going to post that aspect of the process and refer back to Mike&#8217;s straightforward post on <a href="http://www.mikechambers.com/blog/2008/08/28/getting-started-with-flex-4-fxg-and-flex-builder-3/" title="Getting started with Flex 4 FXG and Flex Builder 3">how to get the SDK compiling and running</a>.</p>

<p><strong>Check Out The Source</strong><br/>
The first step of linking the Flex 4 source to Flex Builder, is to download the code from Adobe&#8217;s Open Source website.  Adobe and the Flex team are using Subversion to manage the code base so you will need to use SVN to checkout the source.  I already had Subversion installed so I was able to jump right in and checkout the code. If you don&#8217;t have Subversion, or want to learn more about how Adobe has the SVN configured, then make sure to read <a href="http://opensource.adobe.com/wiki/display/flexsdk/Get+Source+Code" title="Get source code">how to check out from Adobe&#8217;s code base</a>.  If you have Subversion installed, then here is the short and sweet version.</p>

<p>First, I didn&#8217;t want to download the entire SDK SVN trunk, so I found the direct path the Flex 4 Framework code using their web browser interface:</p>

<p><em>http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/flex4/src/</em></p>

<p>Next, I picked a location to keep the source.  I personally chose to put it inside the flex 4 SDK folder under a new subfolder called <em>src</em>.  You can put this folder anywhere you want, I just chose this location on a whim. To get the source, I opened up my terminal, <em>cd</em>&#8216;d to the new <em>src</em> folder and then ran the following command to download the source:</p>

<p><em>svn checkout http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/flex4/src/ ./</em></p>

<p>You don&#8217;t technically have to <em>cd</em> to the new folder but I hate having to fit it all in one command line.  Whatever, I can do what I want!  Once you run this command, Subversion will download all the ActionScript source for the framework into your new directory.  The last step is to inform Flex Builder that you have source for it.</p>

<p><strong>Get Flex Builder Into The Know</strong><br/>
To do this, right click (CMD+Click) on your project in Flex Builder and choose <em>Properties > Flex Build Path > Library Path</em>.  Expand the Flex 4 SDK tree and then expand Flex4.SWC so that you see the <em>Source Attachment:</em> option.  Double click <em>Source Attachment:</em> and then browse to the folder that holds the source you just downloaded.  Choose Okay, and there you have it, source is now bound to your SDK and you can F3 to your hearts content.</p>

<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/08/setting-sdk-source-for-flex-builder.png" alt="Setting SDK Source For Flex Builder" /></p>

<p>One thing to note, if you only use the default namespace, then hinting will not follow through in FB3.  I recommend binding the gumbo library for this to work:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;library:adobe/flex/halo&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:gumbo</span>=<span style="color: #ff0000;">&quot;library:adobe/flex/gumbo&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gumbo:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;hello world&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gumbo:Group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gumbo:content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gumbo:Ellipse</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gumbo:fill<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:SolidColor</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#FF0000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gumbo:fill<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gumbo:Ellipse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gumbo:content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gumbo:Group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<p>This tells FB where to start looking for the source and enables it to open properly.  If you know of a way to bind the namespace to the source, please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/08/binding-source-for-flex-4-in-flex-builder-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>VivMedia Code Library: Version 0.03 released</title>
		<link>http://blog.vivisectingmedia.com/2008/07/vivmedia-code-library-version-003-released/</link>
		<comments>http://blog.vivisectingmedia.com/2008/07/vivmedia-code-library-version-003-released/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 18:13:25 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Distribution]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[Self Reference]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web integration]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[unittest]]></category>
		<category><![CDATA[vivmedia code depot]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/07/vivmedia-code-library-version-003-released/</guid>
		<description><![CDATA[I pushed a new version of the library yesterday to Google Code.  This is a relatively small release, which was not really my intention for version 0.03.  Originally, I was planning on adding the first of a series of really powerful features but due to unit testing the new Queue (48 new tests), [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2007/10/rune_flash.gif" alt="rune_flash.gif" align="left" border="0" hspace="10" vspace="5" />I pushed a <a href="http://code.google.com/p/vivisectingmedia-as3/downloads/list" title="Vivisecting Media Code Library version 0.03">new version of the library yesterday to Google Code</a>.  This is a relatively small release, which was not really my intention for version 0.03.  Originally, I was planning on adding the first of a series of really powerful features but due to unit testing the new Queue (48 new tests), this kind of slowed down progress.  Oh, that and a TON of client deadlines.  Anyway, there are two updates in this version: The Queue and new source code licensing.</p>

<p>I read a great <a href="http://www.gskinner.com/blog/archives/2008/07/source_code_lic_1.html" title="gSkinner: Source Code Licenses">analysis article by Grant Skinner, talking about the different Open Source licenses</a> and how they can affect you and your client.  I originally licensed the code library under the Mozilla Public License (MPL) due to its popularity, its freedom to allow developers to build on top of the code base for any purpose (free or for charge) and only requires code modification submission if the developer changed the original code in the library.  My goal with VivMedia is to help developers build great applications, and the last thing I wanted to do is limit them, yet I do want to encourage people to submit changes and updates.  That is why I went with MPL at first.</p>

<p>The issue with MPL (as Grant points out) is that when you use MPL code there are certain steps you need to take to release your project.  In most cases this is not a big deal and it very rarely impacts the project but it may cause some developers or their clients a bit of grief.  In all honesty, I just want to create a library that myself and others can use without having to jump through hoops with our clients.  This lead me to change all the code license to MIT, which is very permissive of all forms of development. All you need to do is keep the MIT license headers in the source.  You don&#8217;t have to submit changes (all thought I would be very happy if you did) and you don&#8217;t have to jump through any other legal hoops when deploying. So, if you are using the library already, update to the new version and know that the door is now wide open and you don&#8217;t have to fret about how you or your clients release the work.</p>

<p>The other addition to this version is the new Queue data structure.  The Queue allows you to add and remove items is in a linear fashion.  You can define the Queue as either Last in First Out (LIFO) or First in First Out (FIFO).  What that means is when you add() item A and item B to the Queue and then call next(), the item returned is dependent if the queue is set to LIFO or FIFO.  A LIFO Queue returns item B, since it was the last item added.  A FIFO Queue returns item A since it was the first item added.  As always, a full tutorial will be posted soon on how to use the Queue in your code.</p>

<p>The Queue is a building block for a lot of new functionality that I am starting to plan out.  There will probably be variations of the Queue going forward too.  For example a version that is designed to help solve Asynchronous issues in a Synchronous fashion, without you having to write a lot of logic around the actions.  Right now, its all about what time permits&#8230; and as I said in the last post, vacation is nearly here!  So, update/download the library, check out the ASDocs in the source (I always update them for each release) and let me know what you all think.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/07/vivmedia-code-library-version-003-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VivMedia Code: Selection Controller</title>
		<link>http://blog.vivisectingmedia.com/2008/07/vivmedia-code-selection-controller/</link>
		<comments>http://blog.vivisectingmedia.com/2008/07/vivmedia-code-selection-controller/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 21:34:02 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[ISelectable]]></category>
		<category><![CDATA[multiselect]]></category>
		<category><![CDATA[SelectionController]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vivisecting media code depot]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/07/vivmedia-code-selection-controller/</guid>
		<description><![CDATA[With the previous release of version 0.02 of the code base I added a new class called the SelectionController that enables you to treat items that implement the ISelectable interface as a selection group.  As promised, this is the tutorial/indepth examples of the SelectionController and how to use it within your applications.



Overview
The SelectionController allows [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2007/10/rune_flash.gif" alt="rune_flash.gif" align="left" border="0" hspace="10" vspace="5" />With the previous <a href="http://blog.vivisectingmedia.com/2008/06/vivmedia-code-library-version-002-released/" title="VivMedia Code update">release of version 0.02 of the code base</a> I added a new class called the SelectionController that enables you to treat items that implement the ISelectable interface as a selection group.  As promised, this is the tutorial/indepth examples of the SelectionController and how to use it within your applications.</p>

<p><span id="more-132"></span></p>

<p><strong>Overview</strong><br/>
The SelectionController allows you to group items similarly to how a radio group works in both HTML and Flex.  The general principle with a radio group is that when one radio button is selected, any of the other radio buttons in the group are then deselected.  This kind of selection occurs in Lists, DataGrids, etc.</p>

<p>The challenge is that in a highly stylized Flash/Flex applications we often need to treat custom components as a group.  One example is my <a href="http://blog.vivisectingmedia.com/2008/03/sxsw-2008-hot-freaks-party-and-dr-dog-photos/" title="PhotoSlider">Wordpress PhotoSlider</a>.  When a user selects a thumbnail, the selected thumbnail is highlighted and the previously highlighted thumbnail is deselected.</p>

<p>A typical solution is to make the parent container smart enough to understand when an item is selected and then let the parent change the highlight state.  This approach can get tricky when you have items that are deeply nested and don&#8217;t share an easily accessible common parent or if you have complex selection/deselection requirements that may span across multiple containers or even have selected children that are currently off the display stack.</p>

<p>To solve the easiest issues to the most complex selection challenges I developed a SelectionController that is a Singleton instance that manages selection of content for you.  Items first need to implement the ISelectable interface and then they can be added to a selection group.  When you want to select or deselect a group you can either pass in the group ID or you can pass in one of the items in the group to handle selection.</p>

<p><strong>Examples</strong><br/>
First, lets look at our item that we want to be selectable and then we will look at how you can select/deselect the item.</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">vivisectingmedia</span>.<span style="color: #006600;">tutorial</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">vivisectingmedia</span>.<span style="color: #006600;">framework</span>.<span style="color: #006600;">controllers</span>.<span style="color: #006600;">SelectionController</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">vivisectingmedia</span>.<span style="color: #006600;">framework</span>.<span style="color: #006600;">controllers</span>.<span style="color: #006600;">interfaces</span>.<span style="color: #006600;">ISelectable</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #0066CC;">Button</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MySelectionButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Button</span> <span style="color: #0066CC;">implements</span> ISelectable
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// constructor</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MySelectionButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * The default method for when a Button is clicked.
		 * We override this method so that when a user clicks
		 * on this Button we select this item and deselect
		 * all the other Buttons in the group.
		 * 
		 * @param event Click event.
		 * 
		 */</span>
		override protected <span style="color: #000000; font-weight: bold;">function</span> clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span>.<span style="color: #006600;">clickHandler</span><span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// this item is now selected</span>
			SelectionController.<span style="color: #006600;">selectItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * This setter is called when the SeletionController
		 * changes the Button's selection state.  Technically,
		 * we do not have to override this method because the Button
		 * Class already supports the selected getter/setter signature
		 * required by the ISelectable interface.
		 *  
		 * @param value True is selected, false is deselected.
		 * 
		 */</span>		
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> selected<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Boolean</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;">// store the private reference</span>
			<span style="color: #0066CC;">super</span>.<span style="color: #006600;">selected</span> = value;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> selected<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">super</span>.<span style="color: #006600;">selected</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>A couple of notes about the above code.  As I mentioned in the comments, we don&#8217;t really need to override the get/set method for selected.  The Button Class already meets the ISelectable interface requirement, but you will still need to extend the Button class to add the ISelectable interface so that it works with the SelectionController.  I overrode the code just to show you how you would need to implement this in a component that does not already support selection states.  What I really want you to focus on is <em>implements ISelectable</em> and the <em>clickHandler()</em> method.</p>

<p>In the clickHandler() call we pass up the super.clickHandler() and then we call the SelectionController.selectItem() passing the component instance reference in as the argument.  What this is telling the SelectionController to do is first, see if the passed item is in a selection group, if so, select the item by setting selected to true, and then set selected value to false on any other item in the selection group.  The SelectionController is friendly enough that if the item passed in is not in a selection group, then the item is still selected and nothing else happens.</p>

<p>So how do you leverage the selection object?  Let&#8217;s look at some examples:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// create some selectable items</span>
<span style="color: #000000; font-weight: bold;">var</span> buttonOne:MySelectionButton = <span style="color: #000000; font-weight: bold;">new</span> MySelectionButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> buttonTwo:MySelectionButton = <span style="color: #000000; font-weight: bold;">new</span> MySelectionButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> buttonThree:MySelectionButton = <span style="color: #000000; font-weight: bold;">new</span> MySelectionButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// generate an group id to assign them to</span>
<span style="color: #000000; font-weight: bold;">var</span> groupOne:<span style="color: #0066CC;">int</span> = SelectionController.<span style="color: #006600;">generateNewId</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// assign the items to the group</span>
SelectionController.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>buttonOne, groupOne<span style="color: #66cc66;">&#41;</span>;
SelectionController.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>buttonTwo, groupOne<span style="color: #66cc66;">&#41;</span>;
SelectionController.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>buttonThree, groupOne<span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p>This is the basic use case for grouping items.  First, we use a helper method to generate a new group ID.  The ID is an int and it must be unique for each group.  The generateNewId() returns the next ID number not in use.  Once you have an ID you can then add items to the SelectionController using the addItem() method.  This stores the reference of the item and pairs it with the group.</p>

<p>Because the MySelectionButton is built with the SelectionController in mind we don&#8217;t have to do anything else if we want these three buttons to behave as a group.  When a user clicks one of the buttons in the group, the clickHandler calls the SelectionController and the SelectionController will then select the clicked button and deselect the rest.</p>

<p>What happens when you want to programatically select one item, or all of the items in the group or deselect all the items in the group? The SelectionController provides methods to handle these tasks:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// select one item</span>
SelectionController.<span style="color: #006600;">selectItem</span><span style="color: #66cc66;">&#40;</span>buttonTwo<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// select all the items, first get the group if</span>
<span style="color: #808080; font-style: italic;">// you don't know it</span>
<span style="color: #000000; font-weight: bold;">var</span> currentGroup:<span style="color: #0066CC;">int</span> = SelectionController.<span style="color: #006600;">getItemGroup</span><span style="color: #66cc66;">&#40;</span>buttonOne<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// now select the group</span>
SelectionController.<span style="color: #006600;">selectAll</span><span style="color: #66cc66;">&#40;</span>currentGroup<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// or you can deselect them all</span>
SelectionController.<span style="color: #006600;">deselectAll</span><span style="color: #66cc66;">&#40;</span>currentGroup<span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p><strong>Considerations and Gotchas</strong><br/>
As with all my tutorials, lets talk about things you should consider/know about the SelectionController that may cause you some trouble if you attempt to do certain things.</p>

<p><em>One group to an item.</em>  Selectable items can not be members of multiple groups and when a new group is applied the item is removed from the original group. For example:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// create a new group</span>
<span style="color: #000000; font-weight: bold;">var</span> groupTwo:<span style="color: #0066CC;">int</span> = SelectionController.<span style="color: #006600;">generateNewId</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// apply the group to ButtonTwo</span>
SelectionController.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>buttonTwo, groupTwo<span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p>Doing the above would remove ButtonTwo from groupOne and when you call selectAll() on groupOne only buttonOne and buttonThree would be selected.</p>

<p><em>Items are Strong referenced.</em>  When an item is added to a group it is strong referenced in memory.  This means that if you want to delete the item so that Garbage Collection can be applied you need to remove the item form the SelectionController by calling removeItem().  This removes the item from the SelectionController and Garbage Collection can be applied when the next pass occurs.</p>

<p><em>Multi-Select is supported by not built in by default.</em>  If you want to create a multi-selectable grouping you can use the SelectionController for this kind of functionality, but you will need to add more logic to you selectable items.  For example, we want our MySelectionButton&#8217;s to be multi-selectable when a user has the Control/Command key down.  To do this in our example you would modify the clickHandler() like so:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">override protected <span style="color: #000000; font-weight: bold;">function</span> clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">super</span>.<span style="color: #006600;">clickHandler</span><span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">ctrlKey</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// do not select using the controller</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">selected</span> = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// do select using the controller</span>
		SelectionController.<span style="color: #006600;">selectItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>The above example determines if the user is multi-selecting by checking the ctrlKey value in the MouseEvent.  The MouseEvent passes true if the key is down and false if the key is up. In the case when the key is down we want the object selected but we don&#8217;t want the Controller to deselect the rest of the items in the group.  Otherwise, we do want the rest of the items to be deselected, so use then use the Controller.</p>

<p>That is the basics of the SelectionController, play around with it and let me know if you need more examples, find any issues or have any questions with the Controller.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/07/vivmedia-code-selection-controller/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Adobe Edge Article: Coding Standards</title>
		<link>http://blog.vivisectingmedia.com/2008/06/adobe-edge-article-coding-standards/</link>
		<comments>http://blog.vivisectingmedia.com/2008/06/adobe-edge-article-coding-standards/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 20:50:41 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[General Media / Stuff]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[Self Reference]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web integration]]></category>
		<category><![CDATA[adobe edge]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[code conventions]]></category>
		<category><![CDATA[code standards]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/06/adobe-edge-article-coding-standards/</guid>
		<description><![CDATA[A few months ago I was asked to write an article for the Adobe Edge Newsletter on a topic of my choosing.  After spending a bit of time thinking about what moved me at the moment, I decided to sit down and write about the need for RIA and web app developers to invest [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2008/06/adobe-edge.png" alt="Adobe Edge" align="left" border="0" hspace="10" vspace="5" />A few months ago I was asked to write an article for the <a href="http://www.adobe.com/newsletters/edge/" title="Adobe Edge Newsletter">Adobe Edge Newsletter</a> on a topic of my choosing.  After spending a bit of time thinking about what moved me at the moment, I decided to sit down and write about the need for RIA and web app developers to invest time into research, development and adoption of code standards. This week, the article &#8220;<a href="http://www.adobe.com/newsletters/edge/june2008/articles/article6/index.html?trackingid=DEKYJ" title="Adobe Edge Article...">Coding standards: What are they and why should you use them?</a>&#8221; went live and I want to share the link with everyone.</p>

<p>One of the challenges of writing an article like this is first defining your audience and then determining how to cover the topic in the alloted text.  The Edge sets a word count guideline and this limits how deep I could or in this case could not go.  Personally, I fully support the word count guide because this both focuses the topic and generates more digestible articles.  Yet, on a topic as broad and as deep as this one I had to focus more on an introductory guide to coding standards and adoption.</p>

<p>The second challenge is determining your audience.  My goal was to create an article that worked for both readers who have never heard of coding standards, and readers that have been using them for years.  I always try to create a broad stripe across my reader base because I want to inform as many people as possible.  This thought process was kind of beaten into me during my years as a Technical Support rep and team-lead at Macromedia.  There is nothing like having to write Tech-notes and email support to teach you how to write to a broad audience.</p>

<p>The main point I wanted to get across with this article is that coding standards are actually much more then just code formating.  Code formatting, or code conventions, really focus on how you name variables, methods, classes, etc. Yet, this is just the tip of the coding standards iceberg.  One of the least discussed aspects of coding standards is the adoption and implementation practice of code design patterns.  As developers, we need to better understand how adoption of patterns, frameworks and micro-architectures help structure our code.  Not only do they provided rapid development but they also help guide us into a more structured development process.</p>

<p>As RIA and web application development expands we are seeing a demand for much more complex and scalable applications. Scalability is not just about user load but includes further expansion of features <em>and</em> performance over time.  More and more developers are being asked to create applications that have a lifespan longer then just a few months.  Some people may gaffe at that comment, but if you look at a lot of &#8220;rich&#8221; applications up to this point, most have been for marketing campaigns and advertising.  The nature of these kinds of projects do not focus on lifespan and version updates. Their focus is on making them work in a short time to meet the marketing deadline and then get them out the door.</p>

<p>With the trend of Web 2.0 (which I <em>hate</em> as a term), the web world is quickly being pushed into the long standing Desktop Software model. This is forcing a lot of us to re-evaluate how we design and develop our online enabled applications.  This is a scary yet wonderful time in our industry as we are rapidly adopting and developing new ways of web application design and construction. Due to this push I feel its time to help expose more of us to coding standards. My article is more a call to arms then a definitive guide to coding standards implementation.  If you are interested, take a read and add your thoughts to the comments&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/06/adobe-edge-article-coding-standards/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>VivMedia Code Library: Version 0.02 Released</title>
		<link>http://blog.vivisectingmedia.com/2008/06/vivmedia-code-library-version-002-released/</link>
		<comments>http://blog.vivisectingmedia.com/2008/06/vivmedia-code-library-version-002-released/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 00:15:56 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[unittest]]></category>
		<category><![CDATA[vivmedia code depot]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/06/vivmedia-code-library-version-002-released/</guid>
		<description><![CDATA[Its been a busy few weeks for me (with work and personal projects) but I am happy to say that version 0.02 of the VivMedia library is now available.  This update includes a fully automated Unit Test suite for all the code except the Local Connection Manager.  Trying to automate the LCM is [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2007/10/rune_flash.gif" alt="rune_flash.gif" align="left" border="0" hspace="10" vspace="5" />Its been a busy few weeks for me (with work and personal projects) but I am happy to say that <a href="http://code.google.com/p/vivisectingmedia-as3/downloads/list" title="Vivisecting Media Library version 0.02">version 0.02 of the VivMedia library</a> is now available.  This update includes a fully automated Unit Test suite for all the code except the Local Connection Manager.  Trying to automate the LCM is going to be coding feat in itself, so right now it is being tested the old fashioned way a.k.a. by hand. There are a few minor updates to the existing code such as streamlining how the HashTable clones the internal Array and some other minor updates to support automated testing. As usual the code is fully ASDoced and generated docs are available with the ZIP download.</p>

<p>The big change is this version is the addition of the new SelectionController and ISelectable interface. The SelectionController is a manager that allows you to group any number of items that implement the ISelectable interface and then treat them as a Radio Group or multi-selectable group.  With the controller you assign items to groups and then you can use the controller to select and deselect the items.</p>

<p>A great example of this code is how I handle image highlighting in the <a href="http://blog.vivisectingmedia.com/2008/03/sxsw-2008-hot-freaks-party-and-dr-dog-photos/" title="Photoslider example">Photoslider</a>.  Each of my image thumbnails implement ISelectable and then when a user clicks a thumb it calls the SelectionController.selectItem() and passes itself as an argument.  The SelectionController then sets selected on all the thumbnails in the group, setting true for the passed in item and false for the rest.  I plan on doing a full tutorial in the near future so keep an eye out for it.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/06/vivmedia-code-library-version-002-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Extendable Singleton Pattern</title>
		<link>http://blog.vivisectingmedia.com/2008/06/the-extendable-singleton-pattern/</link>
		<comments>http://blog.vivisectingmedia.com/2008/06/the-extendable-singleton-pattern/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 20:42:43 +0000</pubDate>
		<dc:creator>James Polanco</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex Development]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[patter]]></category>
		<category><![CDATA[singleton]]></category>
		<category><![CDATA[singleton lock]]></category>

		<guid isPermaLink="false">http://blog.vivisectingmedia.com/2008/06/the-extendable-singleton-pattern/</guid>
		<description><![CDATA[The Singleton pattern is one of my favorite little patterns that can be used in any language that provides static typed properties/methods.  There are many different uses of the Singleton and just as many ways to implement them within code.  In this post I am going to first introduce the basic Singleton pattern, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.vivisectingmedia.com/wp-content/uploads/2007/10/rune_flash.gif" alt="rune_flash.gif" align="left" border="0" hspace="10" vspace="5" />The Singleton pattern is one of my favorite little patterns that can be used in any language that provides static typed properties/methods.  There are many different uses of the Singleton and just as many ways to implement them within code.  In this post I am going to first introduce the basic Singleton pattern, explore how it is most often defined in ActionScript (including tips on protecting the Singleton instance), then talk about how to create an extendable Singleton and why on earth you would want to.  If you already know the principles of Singletons, skip ahead to the second section of this post &#8220;Defining Singletons in ActionScript&#8221;.</p>

<p><span id="more-119"></span></p>

<p><strong>What Is a Singleton?</strong><br/>
If you have never heard of the Singleton Pattern you are not alone, I know many senior Java and ActionScript developers that looked at me blankly when I brought up the pattern in passing.  The core idea of the pattern is to solve the issue of when you need only once instance of an object that can be accessed globally in you application.  </p>

<p>For example, you have a User object that stores the user information once they are logged in.  Throughout your code you want to use this information and you also want to make sure that there is only once instance of this user data.   One solution is to pass around a value that represents the user, yet there are many issues with this kind of approach.  First, the code needs to understand this data and expect it when called.  Second, what happens if the user logs out or changes the data, such as their address?  The code needs to know this the next time its called.  Passing it around gets ugly very very fast.</p>

<p>Another solution is to save the values in a global variable.  But where should this live and how should it be accessed?  Does it live in _root (really, really bad idea) or the top Application?  What happens when your code gets nested in another application or is modularized?  How can you find the data?  This is where the singleton comes in. The Singleton pattern leverages the power of static properties and methods which are bound to the Class type itself.  What!?!  Let me show you:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">vivisectingmedia</span>.<span style="color: #006600;">example</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> address:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> birthDate:<span style="color: #0066CC;">Date</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>So there is our basic user class.  Its just a simple data object class that stores our information.  In most cases we create a new instance of it and then start manipulating it, such as:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> loggedInUser:User = <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
loggedInUser.<span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">&quot;Bob&quot;</span>;
loggedInUser.<span style="color: #006600;">address</span> = <span style="color: #ff0000;">&quot;123 Market St.&quot;</span>;
loggedInUser.<span style="color: #006600;">birthData</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1976</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p>In the above example we are working with an instance of a class.  We used the constructor to generate the instance and we are manipulating the properties of that instance.  In ActionScript 3.0 we can leverage the static keyword to define properties on the class itself:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">vivisectingmedia</span>.<span style="color: #006600;">example</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> address:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> birthDate:<span style="color: #0066CC;">Date</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
....
&nbsp;
<span style="color: #808080; font-style: italic;">// we now access the name value through the Class, not an instance</span>
User.<span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">&quot;Bob&quot;</span>;
User.<span style="color: #006600;">address</span> = <span style="color: #ff0000;">&quot;123 Fake St.&quot;</span>;
User.<span style="color: #006600;">birthData</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1976</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p>Those values are being set on the Class not on an instance.  This means that when you change values in one part of the code and then access the class in other parts of the code the stored values are the same.  In a way we have just defined a global data object that stores our user data.  The Singleton pattern takes the ability to store values on the Class and then steps it up a notch.</p>

<p>In theory we could go in and mark EVERYTHING static but this is not ideal and can lead to complications.  The better way is to create a hybrid of the first User class example and the second.  We do this by exposing a static method on User that checks if an instance of User is created and if not creates one and then returns it.  This part of the Singleton is kind of a mind-bender so lets just jump into code.</p>

<p><strong>Defining Singletons in ActionScript</strong><br/>
The core idea of the Singleton is to have static helper methods that manages our object instance by allowing only one instance to exist and also provides access to this instance.  Using the User example (above) here is a complete Singleton which also follows the extendable pattern.  Don&#8217;t worry if you don&#8217;t get all of it on the first pass, I will break it down step by step later.</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">vivisectingmedia</span>.<span style="color: #006600;">example</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// stores our instance</span>
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> __inst:User;
&nbsp;
		<span style="color: #808080; font-style: italic;">// standard public properties</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> address:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> birthDate:<span style="color: #0066CC;">Date</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// accessor for the instance</span>
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> instance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:User
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>__inst<span style="color: #66cc66;">&#41;</span> __inst = <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #66cc66;">&#40;</span>generateLock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> __inst;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// accessor for our SingletonLock</span>
		<span style="color: #0066CC;">static</span> protected <span style="color: #000000; font-weight: bold;">function</span> generateLock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:SingletonLock
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> SingletonLock;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// our constructor, must be public in AS3</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> User<span style="color: #66cc66;">&#40;</span>lock:<span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>lock is SingletonLock<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Invalid use of singleton.&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// add public methods and such here</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> age<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// calculate age and return it</span>
			...
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		...
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> SingletonLock
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SingletonLock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>Let&#8217;s break this down step by step.  First of all lets look at the static property __inst and the static method instance().  These two parts are the most important aspect of the Singleton pattern.  So what are we doing in instance()?  The first thing to notice is that the instance() method is both static and a getter with no setter which makes it read-only.  We would use it like this:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// set the user's info and call the age() method</span>
User.<span style="color: #006600;">instance</span>.<span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">&quot;Fred&quot;</span>;
User.<span style="color: #006600;">instance</span>.<span style="color: #006600;">address</span> = <span style="color: #ff0000;">&quot;123 Mission St.&quot;</span>
User.<span style="color: #006600;">instance</span>.<span style="color: #006600;">birthData</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1978</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">14</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> age:<span style="color: #0066CC;">int</span> = User.<span style="color: #006600;">instance</span>.<span style="color: #006600;">age</span>;</pre></div></div>


<p>What happens is we call the instance() method through the class reference of User, the instance() method then looks and sees if the __inst property is currently storing an instance of User, if not then we create a new instance of User, save it in __inst and then return the reference.  This means the the second time we call instance on the User class, we have already created the instance of User and we just hand back the reference. That&#8217;s the magic of the Singleton right there, we now only have one instance of the class that is created exactly once and is created at the time you need it.  You don&#8217;t need to worry about creating it in onCreationComplete() or in the Document class.  The first time you access it the item creates itself.  Pretty nifty, eh?</p>

<p>So what is all the other crap that is in this class?  The rest of the code is both designed to help enforce Singleton usage in ActionScript and allow extending of the Singleton Class.</p>

<p><strong>Protecting Singletons in ActionScript</strong><br/>
One of the current limitations of AS3 is that constructors have to be public.  In languages like Java they can be marked protected but not in AS3.  This is being resolved in the ECMA 4 standard so when the new version of AS comes out we will not longer have to put all this enforcement code in.</p>

<p>Because constructors are always public there is nothing stopping a developer from ignoring the static instance getter and just creating an instance of the User class locally.  This is a bad thing because we now have multiple instances of the object and this defeats the Singleton pattern.  To help enforce this we use the SingletonLock as a special key that prevents the constructor from being used EXCEPT in instance() call and/or the extension process (more on extending later). Let&#8217;s look at the constructor again:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// our constructor, must be public in AS3</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> User<span style="color: #66cc66;">&#40;</span>lock:<span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>lock is SingletonLock<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;invalid use of singleton.&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>You will notice that the constructor expects one argument of type Class and then checks to make sure the passed in Class is of type SingletonLock, if not we throw an Error.  SingletonLock is an internal class that is ONLY available to the User Class.  We expose this class through a method called generateLock() which hands back the Class reference to the internal Class.  The instance() method uses generateLock() to create the lock and pass it on to the constructor.  By setting this structure up we have created an enforcement policy that only allows Classes with access to generateLock() to create an instance of the class.  Take a moment to go back and walk through the entire User Class to make sure you understand this creation flow.</p>

<p>Its seems like overkill, but this kind of code is very important when working with open source projects or large teams.  It forces developers to follow the pattern and prevents improper use of a Singleton based class.  As I mentioned earlier this is only because AS3 does not allow protected or private constructors.  In the future we can throw all this enforcement code away, but for now we should use it.</p>

<p><strong>Extending A Singleton</strong><br/>
Now that we have the Singleton how can we extended it and why would we ever want to?  Very rarely would you want to extend a Singleton but it does come up.  For me, the number one reason I want to extend Singletons is for automated unit testing.  </p>

<p>Here is the situation: I have a series of unit tests that I want to run and each of the tests need to assume a clean instance of the Singleton exists.  The challenge is that the tests all run in the same instance of the application (FlexUnit) and therefor the Singleton is created on the first test and the second test is now manipulating the previously created Singleton.  Very bad for a testing environment.</p>

<p>One solution is that we expose a reset() method on the Singleton that enables the unit test to reset the Singleton instance.  This is a bad approach because we really don&#8217;t want to expose this public method in the live version because we want to prevent users for resetting the Singleton, this reset() method is only for testing purposes.</p>

<p>The ideal solution is to extend the Singleton in the Test Suite and add the reset() method which is called on tearDown().  The test would use the extended instance so we are now able to verify the core Singleton functionality and still get reset() without exposing it for the deployed version.  Here is how we would create a TestUser that extends our User example:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">vivisectingmedia</span>.<span style="color: #006600;">example</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestUser <span style="color: #0066CC;">extends</span> User
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// stores our instance</span>
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> __inst:TestUser;
&nbsp;
		<span style="color: #808080; font-style: italic;">// accessor for the instance</span>
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> instance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:TestUser
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>__inst<span style="color: #66cc66;">&#41;</span> __inst = <span style="color: #000000; font-weight: bold;">new</span> TestUser<span style="color: #66cc66;">&#40;</span>generateLock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> __inst;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> reset<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			__inst = <span style="color: #000000; font-weight: bold;">new</span> TestUser<span style="color: #66cc66;">&#40;</span>generateLock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// our constructor, must be public in AS3</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TestUser<span style="color: #66cc66;">&#40;</span>lock:<span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span>lock<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>What changed?  First we still define the static private instance but we type it as TestUser.  The value has to be private because the __inst has to be specific to the Class its defined in. Remember that static properties and methods are bound to the Class itself.  Things get a little tricky here so let me see if I can explain it.</p>

<p>We could try and set __inst as protected property on the User class.  When the user calls instance() on TestUser we could create the TestUser instance, store it in the the protected __inst version on User since TestUser is a User.  We could then cast __inst as a TestUser for the return call.</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// accessor for the instance</span>
<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> instance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:TestUser
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>__inst<span style="color: #66cc66;">&#41;</span> __inst = <span style="color: #000000; font-weight: bold;">new</span> TestUser<span style="color: #66cc66;">&#40;</span>generateLock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> TestUser<span style="color: #66cc66;">&#40;</span>__inst<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>The problem with this approach is that if you called User.instance first then tried TestUser.instance you will get an error because __inst is holding the User instance and User can not be upcasted to TestUser.  The solution is to keep the __inst separate in each Class to prevent this possible issue.  The added benefit is that you can have a User instance and TestUser instance living side by side which is awesome if you are extending the Singleton for other purposes.</p>

<p>The next thing we did is redefined instance().  Notice how I did not have to use override?  Static methods are bound only to the Class and not any children that extend the Class.  We have to redefine it to expose it on TestUser.  Also, notice that the code is creating a TestUser and passing in the parents protected generateLock() call.  Make sure to look at how we changed the constructor.  We still expect the lock and we pass the generated lock on the to the super call.  </p>

<p>This is exactly why we use a generateLock() method and pass a Class reference around. Up to this point a lot of developers (myself included) used the following style for defining the constructor:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// accessor for the instance</span>
<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> instance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:User
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>__inst<span style="color: #66cc66;">&#41;</span> __inst = <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SingletonLock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> __inst;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// our constructor, must be public in AS3</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> User<span style="color: #66cc66;">&#40;</span>lock:SingletonLock<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	...
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>The issue with this structure is that you can not extend User because the constructor signature requires knowledge of the SingletonLock class which is an internal class of User and therefore only User can access it.  By replacing the lock as a Class we can still secure the Singleton by validating the passed lock but we can easily extend it since we are expecting type Class in place of type SingletonLock.  </p>

<p>Now that we have fully extended out Class we can add our reset() method which then overwrites the __inst.  That&#8217;s how you can build and extend singletons in ActionScript.  As always please let me know if you see any errors or have any questions about how this all works.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vivisectingmedia.com/2008/06/the-extendable-singleton-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
