<?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>Ola Bildtsen &#187; Flex</title>
	<atom:link href="http://bildtsen.com/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://bildtsen.com</link>
	<description>Flex, Groovy/Grails, and other neat stuff</description>
	<lastBuildDate>Fri, 20 Nov 2009 19:40:37 +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>Webcast: Introduction to Flex and AIR</title>
		<link>http://bildtsen.com/2009/10/webcast-introduction-to-flex-and-air/</link>
		<comments>http://bildtsen.com/2009/10/webcast-introduction-to-flex-and-air/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 17:29:08 +0000</pubDate>
		<dc:creator>Ola Bildtsen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://bildtsen.com/?p=158</guid>
		<description><![CDATA[I recently did a &#8220;tech talk&#8221; at work &#8212; an introduction to Adobe&#8217;s Flex and AIR. The presentation is geared to the techie with some UI-building experience but with little or no knowledge of Flex or FlexBuilder. Although there are some high-level introductory/overview slides up front, the bulk of the presentation is a build-it-from-scratch session [...]]]></description>
			<content:encoded><![CDATA[<p>I recently did a &#8220;tech talk&#8221; at work &#8212; <a href="http://bildtsen.com/wp-content/uploads/2009/10/FlexIntroPresentationLarge.mov">an introduction to Adobe&#8217;s Flex and AIR</a>.  The presentation is geared to the techie with some UI-building experience but with little or no knowledge of Flex or FlexBuilder.</p>
<p>Although there are some high-level introductory/overview slides up front, the bulk of the presentation is a build-it-from-scratch session that shows how to use FlexBuilder to put together a simple Flex app (the obligatory Twitter client).  It also shows how to work with a library project, and then goes on to create an AIR application using a shared component.  Towards the end, I&#8217;m firing up FlexMonkey to show how to test the Flex app we built and how to generate the scripts and AS3 code needed to integrate those tests in a CI build.</p>
<p>The slides are <a href='http://bildtsen.com/wp-content/uploads/2009/10/FlexIntroSlides.pdf'>here</a>.  There are not that many, but there are some useful links on the last slide.</p>
<p>The Flex projects built during the presentation are <a href='http://bildtsen.com/wp-content/uploads/2009/10/FlexAirDemo.tar.gz'>here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bildtsen.com/2009/10/webcast-introduction-to-flex-and-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://bildtsen.com/wp-content/uploads/2009/10/FlexIntroPresentationLarge.mov" length="281253296" type="video/quicktime" />
		</item>
		<item>
		<title>Manipulating Views under Cairngorm using Facades</title>
		<link>http://bildtsen.com/2008/11/manipulating-views-under-cairngorm-using-facades/</link>
		<comments>http://bildtsen.com/2008/11/manipulating-views-under-cairngorm-using-facades/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 19:13:28 +0000</pubDate>
		<dc:creator>Ola Bildtsen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://bildtsen.com/?p=117</guid>
		<description><![CDATA[We recently re-wrote a fairly major Flex application, having an opportunity to start from scratch with lessons learned. The previous implementation used the Cairngorm framework, but not quite in line with its intent &#8212; it was purely used to in &#8220;data commands&#8221; to retrieve data from the server. After reviewing some of the other MVC [...]]]></description>
			<content:encoded><![CDATA[<p>We recently re-wrote a fairly major Flex application, having an opportunity to start from scratch with lessons learned.  The previous implementation used the Cairngorm framework, but not quite in line with its intent &#8212; it was purely used to in &#8220;data commands&#8221; to retrieve data from the server.</p>
<p>After reviewing some of the other MVC frameworks out there (PureMVC mostly), we decided to stick with Cairngorm but to expand its use to the full extent it was intended.  In our mind, that meant to have Cairngorm events/commands handle all user gestures (unless they were trivial, component-local gestures like re-sorting a datagrid, etc.).  This worked great, and we were pretty happy with the emerging structure of the application except for one thing: we didn&#8217;t like the ViewHelper/ViewLocator pieces.  It seemed too cumbersome and overly structured for the simple task of having a command communicate with a view.  We also didn&#8217;t like to control views from commands via the ModelLocator (as also suggested by the Cairngorm docs), as we had tried that in the earlier version and it quickly became a disastrous mess of spaghetti bindings that were incredibly hard to unravel, much less maintain.</p>
<p><span id="more-117"></span></p>
<p>To make this process simpler, we came up with a different approach: view facades.  These facades are essentially ViewHelpers, but we eliminated the ViewLocator by making the facades singletons attached directly to the view.  A sample makes this clearer.  Consider a command GetBookDetails.  We want this command to contact the server and get the details for a particular book.  During this process, the view should show a progress or &#8220;loading&#8230;&#8221; view, to be switched out for the actual book details view when the loading is complete.  That command could look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GetBookDetailsCommand <span style="color: #0066CC;">implements</span> ICommand <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #66cc66;">&#40;</span>event:CairngormEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> bookEvent:GetBookDetailsEvent = event as GetBookDetailsEvent;
&nbsp;
            BookViewFacade.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">showLoadingView</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// Load the book details from the server here, using a custom HTTPServiceEvent of ours...</span>
            <span style="color: #000000; font-weight: bold;">var</span> bookServiceEvent:HTTPServiceEvent = <span style="color: #000000; font-weight: bold;">new</span> HTTPServiceEvent<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'book_get'</span>, BookModelLocator.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">'book'</span>, <span style="color: #ff0000;">'book'</span><span style="color: #66cc66;">&#41;</span>;
            bookServiceEvent.<span style="color: #006600;">params</span> = <span style="color: #66cc66;">&#123;</span>id: bookEvent.<span style="color: #006600;">bookId</span><span style="color: #66cc66;">&#125;</span>
            bookServiceEvent.<span style="color: #006600;">addCommandStatusListener</span><span style="color: #66cc66;">&#40;</span>onBookResult<span style="color: #66cc66;">&#41;</span>;
            bookServiceEvent.<span style="color: #006600;">dispatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onBookResult<span style="color: #66cc66;">&#40;</span>statusEvent:CommandStatusEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            BookViewFacade.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">showBookDetailsView</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>    
    <span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Notice the two calls to <code>BookViewFacade</code>, controlling the visible view in our BookView component.  That component (BookView) would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">. . .    
    <span style="color: #66cc66;">&lt;</span>view:BookViewFacade id=<span style="color: #ff0000;">&quot;facade&quot;</span> bookView=<span style="color: #ff0000;">&quot;{this}&quot;</span><span style="color: #66cc66;">/&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;</span>container:ViewStack id=<span style="color: #ff0000;">&quot;viewStack&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> resizeToContent=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
        <span style="color: #66cc66;">&lt;</span>container:HBox id=<span style="color: #ff0000;">&quot;VIEW_LOADING&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>control:Label <span style="color: #0066CC;">htmlText</span>=<span style="color: #ff0000;">&quot;Loading...&quot;</span><span style="color: #66cc66;">/&gt;</span>
        <span style="color: #66cc66;">&lt;/</span>container:HBox<span style="color: #66cc66;">&gt;</span>
&nbsp;
    	<span style="color: #66cc66;">&lt;</span>container:VBox id=<span style="color: #ff0000;">&quot;VIEW_BOOK_DETAILS&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>control:Label <span style="color: #0066CC;">htmlText</span>=<span style="color: #ff0000;">&quot;{MainModelLocator.getInstance().book.title}&quot;</span><span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;</span>control:Label <span style="color: #0066CC;">htmlText</span>=<span style="color: #ff0000;">&quot;{MainModelLocator.getInstance().book.title}&quot;</span><span style="color: #66cc66;">/&gt;</span>
            . . .
    <span style="color: #66cc66;">&lt;/</span>container:ViewStack<span style="color: #66cc66;">&gt;</span>
. . .</pre></div></div>

<p>Notice the declaration of the view facade <code>BookViewFacade</code>, where the view references itself.  The facade is a singleton, implemented along these lines:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BookViewFacade <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> bookView:BookView;
        <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> instance:BookViewFacade;
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> BookViewFacade<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            instance = <span style="color: #0066CC;">this</span>;    
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:BookViewFacade <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">return</span> instance;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> showLoadingView<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            bookView.<span style="color: #006600;">viewStack</span>.<span style="color: #006600;">selectedChild</span> = bookView.<span style="color: #006600;">VIEW_LOADING</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> showBookDetailsView<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            bookView.<span style="color: #006600;">viewStack</span>.<span style="color: #006600;">selectedChild</span> = bookView.<span style="color: #006600;">VIEW_BOOK_DETAILS</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The view is thus abstracted from the commands, but can be readily manipulated by singleton-access to the view facade and its methods.  You can then easily work with views from within the Cairngorm framework, without the need for maintaining ViewLocators, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://bildtsen.com/2008/11/manipulating-views-under-cairngorm-using-facades/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Flex Implementation using Modules with URLKit Deep-Linking</title>
		<link>http://bildtsen.com/2008/11/a-flex-implementation-using-modules-with-urlkit-deep-linking/</link>
		<comments>http://bildtsen.com/2008/11/a-flex-implementation-using-modules-with-urlkit-deep-linking/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 00:28:07 +0000</pubDate>
		<dc:creator>Ola Bildtsen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://bildtsen.com/?p=92</guid>
		<description><![CDATA[At work, we recently had an opportunity to rebuild the Flex front end to our web application. Having started from scratch with the initial version of the application a year and a half ago (with little prior Flex experience in our staff), this &#8220;greenfield&#8221; opportunity gave us a chance to take the lessons learned (and [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we recently had an opportunity to rebuild the Flex front end to our web application.  Having started from scratch with the initial version of the application a year and a half ago (with little prior Flex experience in our staff), this &#8220;greenfield&#8221; opportunity gave us a chance to take the lessons learned (and new stuff available in Flex 3) and apply them to the new project.  One important change, from an architecture point-of-view, was the introduction of modules and how to make them work with deep-linking.</p>
<p><span id="more-92"></span></p>
<p>With the first version of the app, we quickly realized that a monolithic SWF soon becomes too large to load over not-so-fast internet connections.  By modularizing the app, loading of content that is not immediately needed can be deferred until later.  There is an excellent presentation/demo of what modules are and how to use them at <a href="http://blogs.adobe.com/aharui/2007/03/modules.html">Alex Harui&#8217;s blog</a>.</p>
<p>To get around the complexities of modules and <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=18_Client_System_Environment_5.html">ApplicationDomains</a>, we decided to simply load all modules into the top-level ApplicationDomain.  We also wanted to handle deep-linking in a standard way across all modules.  We use URLKit to do most of this work &#8212; there&#8217;s a detailed explanation of how URLKit works <a href="http://www.insideria.com/2008/09/advanced-flex-deep-linking-wit-1.html">here</a>.  </p>
<p>We started by creating a base class that extends <a href="http://livedocs.adobe.com/flex/3/langref/mx/modules/ModuleLoader.html">ModuleLoader</a>.  It looks something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="actionscript actionscript" style="font-family:monospace;">    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ModuleLoaderBase <span style="color: #0066CC;">extends</span> ModuleLoader <span style="color: #66cc66;">&#123;</span>
&nbsp;
        protected <span style="color: #000000; font-weight: bold;">var</span> isReady:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ModuleLoaderBase<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>;
            applicationDomain = ApplicationDomain.<span style="color: #006600;">currentDomain</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ModuleEvent.<span style="color: #006600;">READY</span>, onReady<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        protected <span style="color: #000000; font-weight: bold;">function</span> onReady<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            isReady = <span style="color: #000000; font-weight: bold;">true</span>;
        <span style="color: #66cc66;">&#125;</span> 
&nbsp;
        <span style="color: #808080; font-style: italic;">/**
         * This function is called from ModuleBase when upon module creationComplete event.
         */</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onModuleCreationComplete<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            initializeDeepLinking<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            MainApplicationFacade.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">appEnabledQueuePop</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/**
         * This is where sub-classes can implement deeplinking using urlKit.
         */</span>
        protected <span style="color: #000000; font-weight: bold;">function</span> initializeDeepLinking<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/**
         *  Add a noCache parameter to the module URL to force the browser to reload the module.
         */</span>
        <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span>u:<span style="color: #0066CC;">String</span><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: #0066CC;">url</span> = u + <span style="color: #ff0000;">&quot;?nocache=&quot;</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: #66cc66;">&#41;</span>.<span style="color: #0066CC;">time</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Notice on line 7 how we&#8217;re pointing the application domain of the module loader to the current or top-level domain.  So all modules we&#8217;re using simply load their class definitions into the top-level ApplicationDomain.  We can do this as long as we&#8217;re not concerned with unloading modules.  If that is a need, this strategy will not work and you&#8217;d have to implement a more complex solution (probably using a &#8220;shared classes&#8221; module as outlined in the presentation linked above).</p>
<p>Using this base class, we then create a new module loader class for each one of our modules.  For instance, here&#8217;s one that loads a book details module:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>module:ModuleLoaderBase
    xmlns:<span style="color: #0066CC;">url</span>=<span style="color: #ff0000;">&quot;http://www.allurent.com/2006/urlkit&quot;</span>
    xmlns:module=<span style="color: #ff0000;">&quot;com.acme.core.module.*&quot;</span>     
    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
            <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">acme</span>.<span style="color: #006600;">module</span>.<span style="color: #006600;">IBookDetailsModule</span>;
            <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">binding</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">BindingUtils</span>;
&nbsp;
            <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> bookId:<span style="color: #0066CC;">String</span>;
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> module:IBookDetailsModule;
&nbsp;
            protected override <span style="color: #000000; font-weight: bold;">function</span> initializeDeepLinking<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
                module = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">child</span> as IBookDetailsModule;
                mx.<span style="color: #006600;">binding</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">BindingUtils</span>.<span style="color: #006600;">bindProperty</span><span style="color: #66cc66;">&#40;</span>module, <span style="color: #ff0000;">&quot;bookId&quot;</span>, <span style="color: #0066CC;">this</span>,  <span style="color: #ff0000;">&quot;bookId&quot;</span><span style="color: #66cc66;">&#41;</span>;
                mx.<span style="color: #006600;">binding</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">BindingUtils</span>.<span style="color: #006600;">bindProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;bookId&quot;</span>, module,  <span style="color: #ff0000;">&quot;bookId&quot;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #66cc66;">&lt;</span>url:UrlRuleSet id=<span style="color: #ff0000;">&quot;urls&quot;</span><span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;</span>url:UrlValueRule id=<span style="color: #ff0000;">&quot;valueRule&quot;</span> urlFormat=<span style="color: #ff0000;">&quot;/*&quot;</span> sourceValue=<span style="color: #ff0000;">&quot;bookId&quot;</span><span style="color: #66cc66;">/&gt;</span>
    <span style="color: #66cc66;">&lt;/</span><span style="color: #0066CC;">url</span>:UrlRuleSet<span style="color: #66cc66;">&gt;</span>      
&nbsp;
<span style="color: #66cc66;">&lt;/</span>module:ModuleLoaderBase<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>Notice the use of an interface (IBookDetailsInterface) to get a handle on the loaded module.  This enables us to &#8220;talk&#8221; to the module without compiling it into the main application (the entire reason for going with modules in the first place).  Also note the two-way binding of the bookId property into and out of the module.  This enables us to set the bookId property on the module loader <b>or</b> the module, and the change will be reflected either way in the browser nav bar.</p>
<p>So now on to the actual module.  First, we have a base class that all modules extend from:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ModuleBase <span style="color: #0066CC;">extends</span> Module <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ModuleBase<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: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FlexEvent.<span style="color: #006600;">CREATION_COMPLETE</span>, onCreationComplete<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onCreationComplete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> loader:ModuleLoaderBase = ModuleLoaderBase<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">parent</span><span style="color: #66cc66;">&#41;</span>;
            loader.<span style="color: #006600;">onModuleCreationComplete</span><span style="color: #66cc66;">&#40;</span><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>Really, the sole purpose of this base class is to call the onModuleCreationComplete function on the module loader base class.  This so that our urlKit properties can be created at the appropriate time.</p>
<p>The sample BookDetailsModule then looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>module:ModuleBase
    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span>
    xmlns:module=<span style="color: #ff0000;">&quot;com.acme.core.module.*&quot;</span>
    <span style="color: #0066CC;">implements</span>=<span style="color: #ff0000;">&quot;com.acme.module.IBookDetailsModule&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
            <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">acme</span>.<span style="color: #006600;">book</span>.<span style="color: #006600;">event</span>.<span style="color: #006600;">GetBookDetailsEvent</span>;
&nbsp;
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _bookId:<span style="color: #0066CC;">String</span>;
            <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> 
            <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> bookId<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>._bookId;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> bookId<span style="color: #66cc66;">&#40;</span>newValue:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #0066CC;">this</span>._bookId = newValue;
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>bookId<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">new</span> GetBookDetailsEvent<span style="color: #66cc66;">&#40;</span>bookId<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">dispatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #66cc66;">&#125;</span>
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;</span>container:ViewStack id=<span style="color: #ff0000;">&quot;viewStack&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> resizeToContent=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
        <span style="color: #66cc66;">&lt;</span>container:HBox id=<span style="color: #ff0000;">&quot;VIEW_LOADING&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>control:Label <span style="color: #0066CC;">htmlText</span>=<span style="color: #ff0000;">&quot;Loading...&quot;</span><span style="color: #66cc66;">/&gt;</span>
        <span style="color: #66cc66;">&lt;/</span>container:HBox<span style="color: #66cc66;">&gt;</span>
&nbsp;
        <span style="color: #66cc66;">&lt;</span>view:BookDetailsView id=<span style="color: #ff0000;">&quot;VIEW_DETAILS&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">/&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;/</span>container:ViewStack<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;/</span>module:ModuleBase<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>So when the module has loaded and receives a change in the bookId property, the module is responsible for the logic of going out to get the data (dispatches the GetBookDetailsEvent).  All logic related to displaying book details is then contained in the module and is not loaded until explicitly referenced by the main app.</p>
<p>In the main application, the module can then be used like this:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;">. . .
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;container:ViewStack</span> id=<span style="color: #ff0000;">&quot;viewStack&quot;</span> resizeToContent=<span style="color: #ff0000;">&quot;true&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;view:HomePageView</span> id=<span style="color: #ff0000;">&quot;VIEW_HOME_PAGE&quot;</span> label=<span style="color: #ff0000;">&quot;home&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;module:BookDetailsModuleLoader</span> id=<span style="color: #ff0000;">&quot;VIEW_BOOK_DETAILS&quot;</span> </span>
<span style="color: #000000;">                url=<span style="color: #ff0000;">&quot;BookDetailsModule.swf&quot;</span> label=<span style="color: #ff0000;">&quot;bookDetails&quot;</span> </span>
<span style="color: #000000;">                width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
. . .</pre></div></div>

<p>In this case, when the VIEW_BOOK_DETAILS module loader is selected as the current child in the viewstack, the module is loaded.  You can now use the urlKit features to load the details for a particular book (with id 12) by deep-linking your browser to:</p>

<div class="wp_syntax"><div class="code"><pre class="url" style="font-family:monospace;">http://myhost/myapp/#/bookDetails/12</pre></div></div>

<p>Or you can reference the module via the module loader in code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">. . .
<span style="color: #006600;">VIEW_BOOK_DETAILS</span>.<span style="color: #006600;">bookId</span> = <span style="color: #cc66cc;">12</span>;
VIEW_BOOK_DETAILS.<span style="color: #006600;">loadModule</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
...</pre></div></div>

<p>In real life, you&#8217;d probably also have a view facade or command that ends up setting the bookId property and selecting the VIEW_BOOK_DETAILS as the active view in the viewstack.  That way, you can very simply load up the book details from code, even from another module.</p>
<p>Clearly, there&#8217;s a bunch more &#8220;meat&#8221; behind the real application than what is shown here, but hopefully this demonstrates a solution to working with modules and deep-linking.  If not, please post comments with questions and I&#8217;ll follow up.</p>
]]></content:encoded>
			<wfw:commentRss>http://bildtsen.com/2008/11/a-flex-implementation-using-modules-with-urlkit-deep-linking/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
