<?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>Almer/Blank Labs &#187; Code &amp; Samples</title>
	<atom:link href="http://labs.almerblank.com/tag/code-samples/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.almerblank.com</link>
	<description>Blog of the Talent at Almer/Blank</description>
	<lastBuildDate>Mon, 19 Jul 2010 22:55:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Thoughts on PureMVC Mediators</title>
		<link>http://labs.almerblank.com/2010/02/thoughts-on-puremvc-mediators/</link>
		<comments>http://labs.almerblank.com/2010/02/thoughts-on-puremvc-mediators/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 05:01:52 +0000</pubDate>
		<dc:creator>Omar Gonzalez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[code examples]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[PureMVC]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1302</guid>
		<description><![CDATA[A common practice amongst PureMVC developers when creating PureMVC Mediator implementations is the &#034;view getter&#034;, a getter method that returns the instance of the view object that the Mediator is coupled with.  As an example I will use an imaginary media player with a playlist. In a PlaylistMediator class the method would be something [...]]]></description>
			<content:encoded><![CDATA[<p>A common practice amongst PureMVC developers when creating PureMVC Mediator implementations is the &#034;view getter&#034;, a getter method that returns the instance of the view object that the Mediator is coupled with.  As an example I will use an imaginary media player with a playlist.<span id="more-1302"></span> In a PlaylistMediator class the method would be something like below.</p>
<p>ex. PlaylistMediator</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project.view
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.patterns.mediator.Mediator;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PlaylistMediator extends Mediator
	<span style="color: #000000;">&#123;</span>
		static <span style="color: #0033ff; font-weight: bold;">public</span> const NAME<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;PlaylistMediator&quot;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> PlaylistMediator<span style="color: #000000;">&#40;</span> viewComponent<span style="color: #000000; font-weight: bold;">:</span>PlaylistView <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> NAME, viewComponent <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> playlistView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>PlaylistView
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> getViewComponent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> PlaylistView;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>As I&#039;ve worked on PureMVC projects with other developers I&#039;ve had the opportunity to see different approaches at writing application code in a PureMVC setting.  The view getter was a pretty common practice, but as I&#039;ve seen the way its used, and abused, I started wondering to myself, why?  Why is this method necessary?  Well obviously, it is necessary to retrieve the view component, without having to cast the type each time its needed.  The real question is, why is it public?</p>
<p>The purpose of the Mediator is to listen for events on the view and send notifications to the Controller, and to provide an API to manipulate the view.  And to a lesser extent, to listen to notifications that should update the view.  However, I am not a fan of this either, and I try to keep notification handling in Mediators to a minimum.  But that is beside the point I am trying to make about the view getter.  With an API to the view provided by the Mediator I feel like the view getter should actually be protected or private, instead of public.</p>
<p>ex. PlaylistMediator</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project.view
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.patterns.mediator.Mediator;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PlaylistMediator extends Mediator
	<span style="color: #000000;">&#123;</span>
		static <span style="color: #0033ff; font-weight: bold;">public</span> const NAME<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;PlaylistMediator&quot;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> PlaylistMediator<span style="color: #000000;">&#40;</span> viewComponent<span style="color: #000000; font-weight: bold;">:</span>PlaylistView <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> NAME, viewComponent <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> playlistView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>PlaylistView
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> getViewComponent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> PlaylistView;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Using protected or private enforces that you should manipulate the view via the Mediator&#039;s API, and also stops promoting code like this:</p>
<p>ex. PlaylistLoadedCommand</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project.controller.command
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.view.PlaylistMediator;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.interfaces.INotification;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.patterns.command.SimpleCommand;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PlaylistLoadedCommand extends SimpleCommand
	<span style="color: #000000;">&#123;</span>
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> execute<span style="color: #000000;">&#40;</span> notification<span style="color: #000000; font-weight: bold;">:</span>INotification <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> playlist<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = notification.getBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Array</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> playlistMediator<span style="color: #000000; font-weight: bold;">:</span>PlaylistMediator = facade.retrieveMediator<span style="color: #000000;">&#40;</span> PlaylistMediator.NAME <span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> PlaylistMediator;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> playlistItemView<span style="color: #000000; font-weight: bold;">:</span>PlaylistItemView;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&amp;</span>lt; playlist.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				playlistItemView		= <span style="color: #0033ff; font-weight: bold;">new</span> PlaylistItemView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				playlistItemView.<span style="color: #004993;">data</span>		= playlist<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span>;
				playlistItemView.<span style="color: #004993;">x</span>		= <span style="color: #000000; font-weight:bold;">0</span>;
				playlistItemView.<span style="color: #004993;">y</span>		= playlistItemView.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">*</span> i;
				playlistMediator.playlistView.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> playlistItemView <span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And instead, promotes code like this:</p>
<p>ex. PlaylistLoadedCommand &#8211; Registered to a notification sent when a Proxy is done loading playlist data</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project.controller.command
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.view.PlaylistMediator;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.interfaces.INotification;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.patterns.command.SimpleCommand;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PlaylistLoadedCommand extends SimpleCommand
	<span style="color: #000000;">&#123;</span>
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> execute<span style="color: #000000;">&#40;</span> notification<span style="color: #000000; font-weight: bold;">:</span>INotification <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> playlist<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = notification.getBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Array</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> playlistMediator<span style="color: #000000; font-weight: bold;">:</span>PlaylistMediator = facade.retrieveMediator<span style="color: #000000;">&#40;</span> PlaylistMediator.NAME <span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> PlaylistMediator;
			playlistMediator.updatePlaylist<span style="color: #000000;">&#40;</span> playlist <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In this example the Command simply calls the updatePlaylist() method on the PlaylistMediator, which encapsulates the logic required to actually update the playlist.  The PlaylistMediator can now also offer this functionality to another application system if it is required later in development due to another action.  Perhaps when the playlist is done and a refresh call is made, or if the user manually refreshes the playlist.</p>
<p>ex. In PlaylistMediator&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> updatePlaylist<span style="color: #000000;">&#40;</span> playlist<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> playlistItemView<span style="color: #000000; font-weight: bold;">:</span>PlaylistItemView;
	<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&amp;</span>lt; playlist.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		playlistItemView		= <span style="color: #0033ff; font-weight: bold;">new</span> PlaylistItemView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		playlistItemView.<span style="color: #004993;">data</span>		= playlist<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span>;
		playlistItemView.<span style="color: #004993;">x</span>		= <span style="color: #000000; font-weight:bold;">0</span>;
		playlistItemView.<span style="color: #004993;">y</span>		= playlistItemView.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">*</span> i;
&nbsp;
		playlistView.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> playlistItemView <span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This was just a small example, where I only showed accessing one mediator.  There are instances where a notification might need to update two or three views.  Instead of writing 10-20 lines in a Command per Mediator that needs to have a view updated, its much neater and easier to read to simply call a method on each Mediator.  This has other benefits other than short code.  If you are following some code that you are trying to debug it is easier to understand what happens if a notification is handled directly by a Command, since you will be able to see all affected actors, Mediators, Proxies, in a single centralized location.  Listening to the notifications within all the mediators makes it more difficult to find all of the places that a single notification effects, as the example illustrates below.  The alternative would be to listen to the notifications in each mediator, and have a command that triggers the proxy method.  I think its more maintainable and easier to debug if all notifications go directly to a command.  It makes more commands, and its more tedious, but in the end its far more maintainable and easier to debug.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project.controller.command
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.view.PlaylistMediator;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.view.MenuMediator;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.model.proxy.ApplicationDataProxy;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.interfaces.INotification;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.patterns.command.SimpleCommand;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PlaylistLoadedCommand extends SimpleCommand
	<span style="color: #000000;">&#123;</span>
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> execute<span style="color: #000000;">&#40;</span> notification<span style="color: #000000; font-weight: bold;">:</span>INotification <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> playlist<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = notification.getBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Array</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> playlistMediator<span style="color: #000000; font-weight: bold;">:</span>PlaylistMediator = facade.retrieveMediator<span style="color: #000000;">&#40;</span> PlaylistMediator.NAME <span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> PlaylistMediator;
			playlistMediator.updatePlaylist<span style="color: #000000;">&#40;</span> playlist <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> menuMediator<span style="color: #000000; font-weight: bold;">:</span>MenuMediator = facade.retrieveMediator<span style="color: #000000;">&#40;</span> MenuMediator.NAME <span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> MenuMediator;
			menuMediator.resetMenu<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> applicationDataProxy<span style="color: #000000; font-weight: bold;">:</span>ApplicationDataProxy = facade.retrieveMediator<span style="color: #000000;">&#40;</span> ApplicationDataProxy.NAME <span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> ApplicationDataProxy;
			applicationDataProxy.getPlaylistInfo<span style="color: #000000;">&#40;</span> playlist <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2010/02/thoughts-on-puremvc-mediators/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ZamfBrowser 1.1</title>
		<link>http://labs.almerblank.com/2009/11/zamfbrowser-1-1/</link>
		<comments>http://labs.almerblank.com/2009/11/zamfbrowser-1-1/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 22:50:21 +0000</pubDate>
		<dc:creator>Omar Gonzalez</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[code examples]]></category>
		<category><![CDATA[code generator]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[stub]]></category>
		<category><![CDATA[stub code]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Zamf]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[ZendAMF]]></category>
		<category><![CDATA[ZendAMF Service Browser]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1275</guid>
		<description><![CDATA[Just posted an update to ZamfBrowser.  ZamfBrowser can now generate code for use in either Flash or Flex based projects.  Simply point ZamfBrowser to the source path folder where your code is, the &#034;com&#034; folder.  Then enter the package you would like the services in, for example &#034;com.project.services&#034;.  ZamfBrowser will create a methods package and [...]]]></description>
			<content:encoded><![CDATA[<p>Just posted an update to ZamfBrowser.  ZamfBrowser can now generate code for use in either Flash or Flex based projects.  <span id="more-1275"></span>Simply point ZamfBrowser to the source path folder where your code is, the &#034;com&#034; folder.  Then enter the package you would like the services in, for example &#034;com.project.services&#034;.  ZamfBrowser will create a methods package and a classes package within the services package you specify.  The classes in the &#034;classes&#034; package reflect the AMF services on the backend.  Service calls can also be made by starting a method object by itself from the classes in the &#034;methods&#034; package.  The Flex package uses the same class that ZamfBrowser uses to unit test methods.  The Flash package has been lightly tested.  As bugs come up please post them to the site http://zamfbrowser.riaforge.org   Usage examples will follow soon at http://labs.almerblank.com</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/11/zamfbrowser-1-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Organizing PureMVC Notifications</title>
		<link>http://labs.almerblank.com/2009/11/organizing-puremvc-notifications/</link>
		<comments>http://labs.almerblank.com/2009/11/organizing-puremvc-notifications/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 09:33:28 +0000</pubDate>
		<dc:creator>Omar Gonzalez</dc:creator>
				<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[pmvc]]></category>
		<category><![CDATA[PureMVC]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1071</guid>
		<description><![CDATA[One of my favorite things about using PureMVC as my application framework are the standards established for organizing application code.  For notification names the common ways that I have seen these organized is by declaring constants on the concrete Facade, or by externalizing them to external classes.  I have tried both approaches, but my preferred [...]]]></description>
			<content:encoded><![CDATA[<p>One of my favorite things about using PureMVC as my application framework are the standards established for organizing application code.  For notification names the common ways that I have seen these organized is by declaring constants on the concrete Facade, or by externalizing them to external classes.  I have tried both approaches, but my preferred method is to externalize the constants to notification classes.  Not only do I feel like its more organized because the notification names for a section of the application are centralized to different notification classes.  But, it is also a good way to clean up the amount of imports in the concrete Facade and centralize the Command registrations to these notification classes.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project.controller.notifications
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.controller.commands.LoginCommand;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.controller.commands.LogoutCommand;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.interfaces.IFacade;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LoginNotifications
	<span style="color: #000000;">&#123;</span>
		static <span style="color: #0033ff; font-weight: bold;">public</span> const LOGIN<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;LOGIN_NOTIFICATION&quot;</span>;
&nbsp;
		static <span style="color: #0033ff; font-weight: bold;">public</span> const LOGOUT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;LOGOUT_NOTIFICATION&quot;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LoginNotifications<span style="color: #000000;">&#40;</span> facade<span style="color: #000000; font-weight: bold;">:</span>IFacade <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			facade.registerCommand<span style="color: #000000;">&#40;</span> LOGIN, LoginCommand <span style="color: #000000;">&#41;</span>;
			facade.registerCommand<span style="color: #000000;">&#40;</span> LOGOUT, LogoutCommand <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Above is an example of a notification class.  The constructor requires an IFacade object that it uses in the constructor to map notifications to commands using the IFacade object that is passed into the constructor.  You can see how a bigger group of commands can be nicely organized into this class.  Below is an example concrete Facade.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.controller.notifications.LoginNotifications;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.patterns.facade.Facade;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ProjectFacade extends Facade
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ProjectFacade<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>ProjectFacade
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>instance<span style="color: #000000;">&#41;</span> instance = <span style="color: #0033ff; font-weight: bold;">new</span> ProjectFacade<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> instance;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> initializeController<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span>.initializeController<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">new</span> LoginNotifications<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In the example above we can see the usage example for the notifications class for the login group.  In the override for the initializeController() method, after initializing the controller, a LoginNotifications object is started with a reference to the IFacade instance that is the concrete facade, or simply &#034;this&#034;.  The amount of imports is reduced in the concrete facade, and there are less lines required in the initializeController() method, creating a neater, shorter concrete facade class.</p>
<p>This kind of organization is almost always based on personal preference, this just happens to be mine. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/11/organizing-puremvc-notifications/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Intro to Open Source Media Framework and Flash</title>
		<link>http://labs.almerblank.com/2009/10/intro-to-open-source-media-framework-and-flash/</link>
		<comments>http://labs.almerblank.com/2009/10/intro-to-open-source-media-framework-and-flash/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 18:24:05 +0000</pubDate>
		<dc:creator>rblank</dc:creator>
				<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Open Source Media Framework]]></category>
		<category><![CDATA[OSMF]]></category>

		<guid isPermaLink="false">http://www.rblank.com/?p=367</guid>
		<description><![CDATA[I have recently completed a course on working with the Adobe Open Source Media Framework. Introduction to the Adobe Open Source Media Framework for Flash, which is 90 minutes of video-based online training, has been posted to the Adobe Developer Connection, and to the Rich Media Institute.
OSMF is relatively new, and if you haven't yet [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.opensourcemediaframework.com/"><img class="alignleft size-full wp-image-369" title="Adobe OSMF" src="http://www.rblank.com/wp-content/uploads/2009/10/ishot-4.png" alt="Adobe OSMF" width="181" height="53" /></a>

I have recently completed a course on working with the <a href="http://www.opensourcemediaframework.com/">Adobe Open Source Media Framework</a>. <em>Introduction to the Adobe Open Source Media Framework for Flash</em>, which is 90 minutes of video-based online training, has been posted to the <a href="http://www.adobe.com/devnet/flash/articles/video_osmf.html">Adobe Developer Connection</a>, and to the <a href="http://richmediainstitute.com/ondemand/intro_to_flash_and_open_source_media_framework">Rich Media Institute</a>.

OSMF is relatively new, and if you haven't yet heard about it, you should check it out. I have been building video players in Flash for over eight years, and almost no two players are ever built the same way. OSMF is an attempt at standardizing the way that such players are built into Flash. Incorporating basic functionality (which we cover in this course), as well as more advanced behaviors like playlists, overlays and integrated advertising, OSMF is a set of classes available for Flash Platform development.

In this course, we cover the basics of working with OSMF in Adobe Flash CS4 -- coding on the timeline to build a fully-functional video player, step-by-step.

And, of course, it's <strong><em>FREE</em></strong>, so you really don't have an excuse. Check it out!

<strong>Title</strong>: Introduction to the Adobe Open Source Media Framework for Flash
<strong>Duration</strong>: 90 minutes
<strong>Price</strong>: FREE
<a href="http://www.adobe.com/devnet/flash/articles/video_osmf.html">View Course at Adobe Developer Connection</a>
<a href="http://richmediainstitute.com/ondemand/intro_to_flash_and_open_source_media_framework">View Course at the Rich Media Institute</a> (eligible for certificate of completion)
<strong>Description</strong>: This course covers all the basic functionality and concepts required to build progressive video players in Flash CS4 with the Adobe Open Source Media Framework. We start from the basics, and work our way to a fully-functioning video player, authored from scratch, using OSMF and Flash CS4.

OSMF is Adobe's community-centered approach to standardizing the way that media players (and, in particular, video players) are built on the Adobe Flash Platform. Although still in prelease, OSMF encompasses media playback functionality, playlists, branding, advertising, and other monetization aspects, and represents a powerful and comprehensive attempt to standardize a huge portion of the work currently executed in Flash.

<strong>Who this Course is For</strong>: This course is useful for two sets of students looking to get up to speed with OSMF:
<ul>
	<li>Low-to-intermediate level Flash ActionScripters, comfortable coding on the timeline, who want to learn the raw ActionScript, as well as the underlying concepts, required to work with OSMF</li>
	<li>Higher level coders, using Adobe Flash or Flex, who want a quick run-down of the core classes utilized when building an OSMF video player</li>
</ul>
<strong>Outline</strong>:
<ul>
	<li>Introduction: Brief Overview of OSMF and Installing the SWC ( 5:44 )</li>
	<li>Lesson 1 : Basics of Video Playback with OSMF ( 6:46 )</li>
	<li>Lesson 2 : Handling Changes in View State ( 7:04 )</li>
	<li>Lesson 3: Adding a Pause Toggle Button ( 8:55 )</li>
	<li>Lesson 4: Sizing the Video ( 9:56 )</li>
	<li>Lesson 5: Adding Volume Control ( 5:56 )</li>
	<li>Lesson 6: Adding a Progress Bar ( 13:58 )</li>
	<li>Lesson 7: Adding Seek Functionality ( 10:43 )</li>
	<li>Lesson 8: Cleaning Up After a Video ( 8:26 )</li>
	<li>Lesson 9 : Playing Multiple Videos ( 11:05 )</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/10/intro-to-open-source-media-framework-and-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
