<?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>Penguinspeak &#187; PureMVC</title>
	<atom:link href="http://macmartine.com/blog/category/puremvc/feed" rel="self" type="application/rss+xml" />
	<link>http://macmartine.com/blog</link>
	<description>This is how I see it.</description>
	<lastBuildDate>Tue, 19 Oct 2010 00:39:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Deferred instantiation of mediators in a PureMVC Flex application</title>
		<link>http://macmartine.com/blog/2008/01/deferred_instantiation_of_medi.html</link>
		<comments>http://macmartine.com/blog/2008/01/deferred_instantiation_of_medi.html#comments</comments>
		<pubDate>Mon, 14 Jan 2008 20:14:39 +0000</pubDate>
		<dc:creator>99miles</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[PureMVC]]></category>

		<guid isPermaLink="false">http://macmartine.com/blog/?p=21</guid>
		<description><![CDATA[I&#8217;m creating my first project using PureMVC after using Cairngorm for a few projects. Once I started understanding the concepts and intent behind each of the architecture components (Proxies and Models, Views and Mediators, Controllers and Commands), it&#8217;s been great in it&#8217;s relative simplicity. I did printed out the docs and read over them everyday [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m creating my first project using PureMVC after using Cairngorm for a few projects. Once I started understanding the concepts and intent behind each of the architecture components (Proxies and Models, Views and Mediators, Controllers and Commands), it&#8217;s been great in it&#8217;s relative simplicity. I did printed out the docs and read over them everyday at lunch for a few days in a row just make it all really sink it, but it didn&#8217;t take too long to click.<br />
The best part is that I&#8217;ve had a few questions so I decided to check out the PureMVC forums on the PureMVC site. So far everything I&#8217;ve searched has returned a thread with a very detailed, extensive answer from Cliff! The days go so much easier when there&#8217;s easy to find and good information about whatever your working with.<br />
One of the problems I ran into pretty quickly was that I had a TabNavigator with 3 tabs where the contents aren&#8217;t to be drawn or loaded until they are clicked on.<br />
I initially tried to register the mediators for those 3 view components at startup, which to no surprise threw runtime errors because the views didn&#8217;t yet exist. Not being sure what the best solution was here, I searched the forums and found <a href="http://forums.puremvc.org/index.php?topic=113.0">this thread</a>.<br />
I went with Cliff&#8217;s recommendation (deferred instantiation) and here&#8217;s what I have now:<br />
My TabNavigator has 3 tabs each containing one custom component named &#8220;tags&#8221;, &#8220;groups&#8221;, &#8220;info&#8221;.<br />
In each of these components I have a creationComplete event which calls an onCreationComplete function, which in turn dispatches a custom Event:</p>
<pre name="code" class="java">
dispatchEvent( new ComponentLoadedEvent( ComponentLoadedEvent.COMPONENT_LOADED, true, false, this ) );
</pre>
<p>The mediator of the TabNavigator itself listens for this event and calls handleLoad when it hears it:</p>
<pre name="code" class="java">
mainComponent.addEventListener( ComponentLoadedEvent.COMPONENT_LOADED, handleLoad );
</pre>
<p>The handleLoad() registers the appropriate mediator for the loaded component:</p>
<pre name="code" class="java">
public function handleLoad( e : Event ):void
{
var component :Object 	= e["component"].name;
switch(component)
{
case "tags":
facade.registerMediator( new TagsMediator( mainComponent.tags )  );
break;
case "groups":
facade.registerMediator( new GroupsMediator( mainComponent.groups )  );
break;
case "info":
facade.registerMediator( new UploadStatusMediator( mainComponent.info )  );
break;
}
}
</pre>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/home/?status=Deferred+instantiation+of+mediators+in+a+PureMVC+Flex+application+http%3A%2F%2Fbit.ly%2FnEvOe" title="Post to Twitter"><img class="nothumb" src="http://macmartine.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big2.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://macmartine.com/blog/2008/01/deferred_instantiation_of_medi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

