<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.33984-</id>
  <updated>2009-11-19T15:00:28Z</updated>
  <title>Comments for FrameworkQuest 2008 Part 4: IoC With Swiz (http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.33984</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=33984" title="FrameworkQuest 2008 Part 4: IoC With Swiz" />
    <published>2008-12-23T13:00:00Z</published>
    <updated>2008-12-23T13:00:00Z</updated>
    <title>FrameworkQuest 2008 Part 4: IoC With Swiz</title>
    <summary>With a name like Swiz, it has to be good, right? Welcome back, friends, to part four of our ongoing effort to understand these four Flex frameworks. This time we&#8217;re going to look at Swiz, a relative newcomer, created by...</summary>
    <author>
      <name>Tony Hillerson</name>
      
    </author>
    
    <category term="Adobe Feed" />
    
    <category term="Features" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<p>With a name like <a href="http://swizframework.googlecode.com"><span
style='color:#000099'>Swiz</span></a>, it has to be good, right? Welcome back,
friends, to part four of our ongoing effort to understand these four Flex
frameworks. This time we&#8217;re going to look at Swiz, a relative newcomer, created
by <a href="http://cdscott.blogspot.com/"><span style='color:#000099'>Chris
Scott</span></a>. Chris had a simple idea to use a powerful but underused Flex
feature, Metadata, to implement a concept called Inversion of Control.</p>



<p>Sounds scary? Actually, the point of this effort is to make
things easier for you. A big part of the frameworks we&#8217;ve looked at so far is
not just some classes that you have to create, but some wiring you have to do.
You have to make some framework classes, describe them to the framework, and
make sure that the code describing them gets called. That overhead can feel
like a drag on productivity and maintainability. That&#8217;s one thing that
Inversion of Control is made to fix.</p>



<p>Here&#8217;s an example of what we&#8217;re talking about. Remember last week
when we set up <span class=Code><span style='font-family:Monaco'>Mediators</span></span>
to work with the application view, <span class=Code><span style='font-family:
Monaco'>LoginView</span></span>, and <span class=Code><span style='font-family:
Monaco'>MainView</span></span>? We fired off a PureMVC command called <span
class=Code><span style='font-family:Monaco'>ViewPrepCommand</span></span> that
reached in and got the reference to each view, created an <span class=Code><span
style='font-family:Monaco'>ApplicationMediator</span></span>, <span class=Code><span
style='font-family:Monaco'>LoginViewMediator</span></span>, <span class=Code><span
style='font-family:Monaco'>MainViewMediator</span></span>, and passed the views
in to each. It doesn&#8217;t make any difference that we pushed that code into a
Command to keep the view clean, we still had to write the code to take those
steps. Same thing when we wrote the code to associate <span class=Code><span
style='font-family:Monaco'>LoginEvent</span></span> with <span class=Code><span
style='font-family:Monaco'>LoginCommand</span></span> in the <span class=Code><span
style='font-family:Monaco'>TwitteRIAController</span></span> in the Cairngorm
example. We had to go one place to write the code for the event, another place
to write the code for the command, and then another to say that we wanted the
one to associate with the other. Wouldn&#8217;t it be nice if we could, with a
minimum amount of code, ask the framework to do that for us?</p>



<p>Consider Flex Binding. Lovely, isn&#8217;t it? You mark a property as <span
class=Code><span style='font-family:Monaco'>[Bindable]</span></span>, and then
elsewhere you can use the curly brace notation to tell Flex that you want to
wire that value up to another property and update that destination property
whenever the other changes. This is a lot like Inversion of Control.</p>



<p>The control that we&#8217;re talking about here is actually a
responsibility - responsibility to get the resources that a particular
component needs in place. In the current paradigm we&#8217;ve been working with, the
component, or a delegate that we create, is responsible for getting the
component&#8217;s stuff together. IoC means to invert that responsibility up out of
the component and into the framework. Instead of going to find and wire up what
it wants, a component instead just lets the framework knows what it wants, and
the framework does the rest. This requires the component to have knowledge of
the framework, but not to have to know the details of where to get things. </p>



<p>We&#8217;ll get to see IoC in action with Swiz in a bit, but first
let&#8217;s talk for a second, as we have with the other frameworks, about how the
Swiz flow of events works.</p>



<p>Pretty simple, eh? The user interacts with the view and the view
notifies the <span class=Code><span style='font-family:Monaco'>Controller</span></span>.
How that happens is up to you. You could use events and set the <span
class=Code><span style='font-family:Monaco'>Controller</span></span> up as an
event listener, or you could call the <span class=Code><span style='font-family:
Monaco'>Controller</span></span> directly. If there&#8217;s service work to be done,
the <span class=Code><span style='font-family:Monaco'>Controller</span></span>
will call a <span class=Code><span style='font-family:Monaco'>Delegate</span></span>
and the <span class=Code><span style='font-family:Monaco'>Delegate</span></span>
can call the service. Swiz makes it dead simple to wire up the <span
class=Code><span style='font-family:Monaco'>Controller</span></span>/<span
class=Code><span style='font-family:Monaco'>Delegate</span></span>
communication - IF - the service is an AMF service that you can contact with a <span
class=Code><span style='font-family:Monaco'>RemoteObject</span></span>. If the
service is not a <span class=Code><span style='font-family:Monaco'>RemoteObject</span></span>
you have to fend for yourself as I found out. More on that in a bit.</p>



<p>When the service call is over and the <span class=Code><span
style='font-family:Monaco'>Controller</span></span> gets notified, the
controller can put some data on the model and act on the view as necessary. The
<span class=Code><span style='font-family:Monaco'>Controller</span></span> is
free to wire up data from the <span class=Code><span style='font-family:Monaco'>Model</span></span>
to the view PureMVC style, or you can use Binding and let Flex do the work.</p>

<img src="http://www.insideria.com/upload/2008/11/swiz.jpg" alt="swiz.jpg"/>

<p>Again, pretty simple. But it&#8217;s no more than you need to get the job done. The app is separated
into the three concerns, services are encapsulated, and the best part, which
we&#8217;ll see next, is that Swiz takes care of wiring all this stuff together. </p>



<strong>You Turn Me Right &#8216;Round, Baby</strong>

<p>That&#8217;s an IoC joke, right there. Moving along let&#8217;s look in the
root application to see some characteristic Swiz code. </p>



<p><b>twitteria_swiz/src/twitteria_swiz.mxml #20-22<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
[Bindable]

[Autowire(bean="<span class="quote">model</span>")]

<span class="category1">public</span> <span class="category1">var</span> model:TwitteRIAModel;</pre>
</code>

</div></div> 


<p>This is the reference to the model that the application uses to
drive the <span class=Code><span style='font-family:Monaco'>ViewStack</span></span>,
as it does in the Cairngorm application. You&#8217;ve seen a <span style='font-size:
11.0pt;font-family:Monaco'>[</span><span style='font-size:11.0pt;font-family:
Monaco;color:#0033FF'>Bindable</span><span style='font-size:11.0pt;font-family:
Monaco'>]</span> tag before, but what&#8217;s that other tag underneath there? <span
class=Code><span style='font-family:Monaco'>Autowire</span></span> is a Swiz
metadata tag. Flex has had <a
href="http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_3.html"><span
style='color:#000099'>metadata</span></a> around for a while, but recently
allowed a compiler option to keep <a
href="http://coenraets.org/blog/2007/10/annotating-actionscript-classes-with-custom-metadata-simple-orm-framework-for-air/"><span
style='color:#000099'>custom metadata</span></a>. The Swiz swc library adds two
tags to the list of metadata that the Flex compiler will keep around, <span
class=Code><span style='font-family:Monaco'>Autowire</span></span>, and <span
class=Code><span style='font-family:Monaco'>Mediate</span></span>. We&#8217;ll look
at <span class=Code><span style='font-family:Monaco'>Mediate</span></span> in a
bit, but <span class=Code><span style='font-family:Monaco'>Autowire</span></span>
is the first example of Swiz&#8217;s IoC at work. It&#8217;s essentially saying &#8220;When this
view is constructed, go find a <i>bean</i><span style='font-style:normal'>
named &#8216;model&#8217; and set this property, </span><span class=Code><span
style='font-family:Monaco'>model</span></span>, to point to it&#8221;. If you&#8217;ve come
from Java-land to Flex, you know what we mean by <i>bean</i><span
style='font-style:normal'>, but others may not. Lots of talk about beans in
Java-land, for those of you who don&#8217;t know, but all they mean is some sort of
component. Don&#8217;t worry about it, and feel free to make as many jokes as you want.
As far as I&#8217;m concerned, they&#8217;re all deserved. Beans! Come on. Don&#8217;t even get
me started on POJOs. </span></p>



<p>In case you didn&#8217;t notice, this <span class=Code><span
style='font-family:Monaco'>Autowire</span></span> thing is sweet. We don&#8217;t have
to worry about where this model comes from. We don&#8217;t have to think about if it&#8217;s
a Singleton or not. All we know is that we want a model, and the framework will
make sure we have one when we need it. One note of caution: the property has to
be marked <span style='font-size:11.0pt;font-family:Monaco;color:#0033FF'>public</span>
or Swiz won&#8217;t be able to assign to it.</p>



<p>So where do these magical beans come from? Well, there is one bit
of administrativa we need to take care of to get those beans jumping for us.</p>



<p><b>twitteria_swiz/src/twitteria_swiz.mxml #8, 24-26<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
preinitialize="<span class="quote">loadBeans()</span>"
...

<span class="category1">private</span> <span class="category1">function</span> loadBeans():<span class="category1">void</span> {
      Swiz.loadBeans([Beans]);
}</pre>
</code>

</div></div> 


<p>On <span class=Code><span style='font-family:Monaco'>preinitialize</span></span>,
which is very early in the Flex bootstrapping process, we call <span
class=Code><span style='font-family:Monaco'>loadBeans</span></span>, which
delegates up to Swiz and mentions where to find them. It&#8217;s important that this
happen at <span class=Code><span style='font-family:Monaco'>preinitialize</span></span>
so that Swiz is all ready to go when views that use Swiz metadata are created,
including the application itself. Now let&#8217;s look at the bean definition file.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/Beans.mxml <o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;BeanLoader
     xmlns="<span class="quote">org.swizframework.util.*</span>" 
     xmlns:api="<span class="quote">twitter.api.*</span>"
     xmlns:delegates="<span class="quote">com.insideria.twitteria.delegates.*</span>"
     xmlns:model="<span class="quote">com.insideria.twitteria.model.*</span>"
     xmlns:controllers="<span class="quote">com.insideria.twitteria.controllers.*</span>"&gt;
     &lt;controllers:ApplicationController id="<span class="quote">applicationController</span>" /&gt;
     &lt;controllers:LoginViewController id="<span class="quote">loginViewController</span>" /&gt;
     &lt;controllers:MainViewController id="<span class="quote">mainViewController</span>" /&gt;
     &lt;model:TwitteRIAModel id="<span class="quote">model</span>" /&gt;
&lt;/BeanLoader&gt;</pre>
</code>

</div></div> 


<p>This <span class=Code><span style='font-family:Monaco'>BeanLoader</span></span>
is just an MXML file with a tag for any class that you want to <span
class=Code><span style='font-family:Monaco'>Autowire</span></span> anywhere in
the application. Inside we have all the controllers and the model. Notice that
the call to <span class=Code><span style='font-family:Monaco'>loadBeans</span></span>
passes an array, so it&#8217;s possible to split up the bean definitions over
multiple files for good housekeeping.</p>



<p>I decided to use the Flex binding way of wiring up the view to
the model, so that instance that points at model is fair game, just as if we&#8217;d
looked it up as a Singleton, a la Cairngorm, or gotten ahold of it some other
way.</p>



<p><b>twitteria_swiz/src/twitteria_swiz.mxml #37 (formatted)<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;mx:ViewStack selectedIndex="<span class="quote">{model.mainViewIndex}</span>"&gt;</pre>
</code>

</div></div> 

<strong>Logging In</strong>

<p>Just as before, when pressing enter in the password field on
LoginView, the login process is kicked off. Here&#8217;s what it looks like with
Swiz.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/view/LoginView.mxml
#9-14 (formatted)<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">public</span> <span class="category1">function</span> login():<span class="category1">void</span> {
      <span class="category1">var</span> e:DynamicEvent = <span class="category1">new</span> 
           DynamicEvent(LoginViewController.LOG_IN);
      e.username = usernameText.<span class="category2">text</span>;
      e.<span class="category2">password</span> = passwordText.<span class="category2">text</span>;
      Swiz.dispatchEvent(e);
}</pre>
</code>

</div></div> 


<p>First thing we do is to created a <span class=Code><span
style='font-family:Monaco'>DynamicEvent</span></span>, which is a little used
(as far as I know) Flex event that is a dynamic class. That means we can assign
to whatever properties we want on it, just like ActionScript&#8217;s <span
class=Code><span style='font-family:Monaco'>Object</span></span>. Swiz doesn&#8217;t
mandate the use of <span class=Code><span style='font-family:Monaco'>DynamicEvents</span></span>,
but it slyly suggests that we can use this class instead of the more
time-consuming method of creating a new Event for each type of payload. Just
remember if you use dynamic objects that the compiler won&#8217;t catcher errors for
you if you misspell things, but that&#8217;s what <a
href="http://code.google.com/p/fluint/"><span style='color:#000099'>unit tests</span></a>
are for, right?</p>



<p>Our payload this time is the username and password. Instead of
dispatching an event the regular way, we dispatch events through Swiz if we
want framework classes to get them. Notice that there&#8217;s no controller instance
specified on the <span class=Code><span style='font-family:Monaco'>LoginView</span></span>,
nor does <span class=Code><span style='font-family:Monaco'>LoginViewController</span></span>
know anything about the view (although both could be true if the application
needed it), but <span class=Code><span style='font-family:Monaco'>LoginViewController</span></span>
is still out there waiting for this <span class=Code><span style='font-family:
Monaco'>LOG_IN</span></span> event, because it was instantiated in the <span
class=Code><span style='font-family:Monaco'>BeanLoader</span></span>. How does
the controller sign up to get events? Like this:</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/controllers/LoginViewController.as
#18-25 <o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
[Mediate(event="<span class="quote">login</span>", properties="<span class="quote">username,password</span>")]
<span class="category1">public</span> <span class="category1">function</span> login(username:<span class="category2">String</span>, <span class="category2">password</span>:<span class="category2">String</span>):<span class="category1">void</span> {
      model.username = username;
      model.<span class="category2">password</span> = <span class="category2">password</span>;
      <span class="category1">var</span> e:Event = <span class="category1">new</span> Event(LOGIN_COMPLETE);
      Swiz.dispatchEvent(e);
}</pre>
</code>

</div></div> 


<p>Here&#8217;s the other metadata tag we mentioned, <span class=Code><span
style='font-family:Monaco'>Mediate</span></span>. The <span class=Code><span
style='font-family:Monaco'>Mediate</span></span> tag goes on controller methods
that you want called when a certain type of event is dispatched through Swiz.
The event argument to the tag needs to match the string type of the event, but
sadly it&#8217;s not possible to make this point to the same constant that defines
that string at this point. Just keep an eye out that they&#8217;re the same.</p>



<p>The tag&#8217;s properties argument tells Swiz which properties of the
incoming event it should grab and pass into the tagged method. The gain is that
you don&#8217;t have to add an event listener somewhere else, you have the code right
here annotating the method. Also, you don&#8217;t have to do the boilerplate event
wrangling to get data you need out. You say what data you&#8217;re expecting and from
what type of event, and the framework will get it out for you. That means you
can just write regular functions, which has the added benefit of letting you
call those functions from other code that doesn&#8217;t use events. I didn&#8217;t test it,
so don&#8217;t quote me on it, but it&#8217;s also theoretically possible to have more than
one <span class=Code><span style='font-family:Monaco'>Mediate</span></span> tag
per method, I suppose.</p>



<p>Inside the <span class=Code><span style='font-family:Monaco'>login</span></span>
method we set the username and password on the model, which is, of course, <span
class=Code><span style='font-family:Monaco'>Autowired</span></span> up on the
controller as well.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/controllers/LoginViewController.as
#15-16<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
[Autowire(bean="<span class="quote">model</span>")]

<span class="category1">public</span> <span class="category1">var</span> model:TwitteRIAModel;</pre>
</code>

</div></div> 



<p>After setting those properties on the model, it then dispatches
an event saying that log in is complete. Notice that instead of a <span
class=Code><span style='font-family:Monaco'>DynamicEvent</span></span>, we&#8217;re
using just a regular Flash <span class=Code><span style='font-family:Monaco'>Event</span></span>
here. Either one will work, and <span class=Code><span style='font-family:Monaco'>Event</span></span>
is fine when we don&#8217;t have to carry a payload.</p>



<p>The next step after logging in is loading the timeline, and we do
that on the <span class=Code><span style='font-family:Monaco'>MainViewController</span></span>.</p>



<strong>Loading The Timeline</strong>

<p>When the <span class=Code><span style='font-family:Monaco'>MainViewController</span></span>
is instantiated from the <span class=Code><span style='font-family:Monaco'>BeanLoader</span></span>,
it registers to receive the log in event right away.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/controllers/MainViewController.as
#22-24<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">public</span> <span class="category1">function</span> MainViewController() {
      Swiz.addEventListener(
           LoginViewController.LOGIN_COMPLETE,
           loginComplete
      );
}</pre>
</code>

</div></div> 


<p>This is another way to listen for events sent through Swiz
besides <span class=Code><span style='font-family:Monaco'>Mediate</span></span>.
Once the event is received, <span style='font-size:11.0pt;font-family:Monaco'>loginComplete</span>
is called.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/controllers/MainViewController.as
#53-55<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">private</span> <span class="category1">function</span> loginComplete(e:Event):<span class="category1">void</span> {
      loadTweets();
}</pre>
</code>

</div></div> 


<p><b>twitteria_swiz/src/com/insideria/twitteria/controllers/MainViewController.as
#31-34<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">public</span> <span class="category1">function</span> loadTweets():<span class="category1">void</span> {
      <span class="category1">var</span> delegate:TwitterDelegate = <span class="category1">new</span> TwitterDelegate(<span class="category1">this</span>);
      delegate.loadTimeline(username);
}</pre>
</code>

</div></div> 


<p><strike>Now comes the point where we call the delegate to get the latest
timeline. Now, as I mentioned before this part is really easy if you&#8217;re using a
service that is wrapped by a <span class=Code><span style='font-family:Monaco'>RemoteObject</span></span>.
Then all you&#8217;d do is call <span class=Code><span style='font-family:Monaco'>createCommand</span></span>,
passing the delegate method to call, its arguments, and a result and fault
callback. As long as the delegate method returned an <span class=Code><span
style='font-family:Monaco'>AsyncToken</span></span> object, Swiz would then
take care of all the callbacks. That&#8217;s a nice set up, but unfortunately it
doesn&#8217;t work for us, because we&#8217;re not using an AMF service.</strike></p>

<p>As I found out later, the above paragraph is not true. HTTPService and WebService do work with AsyncToken, so only in the case of code like our example project do you need to do any hacking around to work with Swiz.</p>

<p>What I did instead was hack together a more elaborate and
depressing solution where I made an interface that I force any object calling
the delegate to implement.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/delegates/TwitterResponder.as
#3-10 (formatted)<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">public</span> <span class="category1">interface</span> TwitterResponder {
      <span class="category1">function</span> <span class="category2">get</span> username():<span class="category2">String</span>;
      <span class="category1">function</span> <span class="category2">get</span> <span class="category2">password</span>():<span class="category2">String</span>;
      <span class="category1">function</span> friendsTimelineResult(tweets:<span class="category2">Array</span>):<span class="category1">void</span>;
      <span class="category1">function</span> setStatusResult():<span class="category1">void</span>;
}</pre>
</code>

</div></div> 


<p>Then I can make sure I know how the instance of the delegate
should get the username and password, and that there&#8217;s a callback method for
getting the timeline and status results. I&#8217;m sure there&#8217;s an easier way, but
this occurred to me at the time. Some time in the future, I&#8217;d like to help Swiz
out of this mess and make it just as easy to arbitrarily work with delegates
that call any type of service. We&#8217;ll see if the time presents itself.</p>



<p>So now calling the delegate, which is the same old guy we&#8217;ve been
using from project to project, will call back to <span style='font-size:11.0pt;
font-family:Monaco'>friendsTimelineResult</span> on the controller when the
timeline is loaded, which sets the collection on the model.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/controllers/MainViewController.as
#44-46<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">public</span> <span class="category1">function</span> friendsTimelineResult(tweets:<span class="category2">Array</span>):<span class="category1">void</span> {
      model.currentTweets = <span class="category1">new</span> ArrayCollection(tweets);
}</pre>
</code>

</div></div> 


<p>Binding takes over from there and the new list is shown in <span
class=Code><span style='font-family:Monaco'>MainView</span></span>.</p>



<strong>Setting Status</strong>

<p>Just as before, pressing enter in the status text field will kick
off the chain of events to set status.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/view/MainView.mxml
#15-18<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">private</span> <span class="category1">function</span> setStatus():<span class="category1">void</span> {
      controller.setStatus(statusText.<span class="category2">text</span>); 
      statusText.<span class="category2">clear</span>();
}</pre>
</code>

</div></div> 


<p>This time we again elected to call up to the controller.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/controllers/MainViewController.as
#26-29<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">public</span> <span class="category1">function</span> setStatus(statusMessage:<span class="category2">String</span>):<span class="category1">void</span> {
      <span class="category1">var</span> delegate:TwitterDelegate = <span class="category1">new</span> TwitterDelegate(<span class="category1">this</span>);
      delegate.setStatus(statusMessage);
}</pre>
</code>

</div></div> 


<p>The controller calls out to the delegate, and the delegate
returns to say that the status is set, so we kick off a load timeline again to
get the latest tweets.</p>



<p><b>twitteria_swiz/src/com/insideria/twitteria/controllers/MainViewController.as
#48-51<o:p></o:p></b></p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">public</span> <span class="category1">function</span> setStatusResult():<span class="category1">void</span> {
      <span class="linecomment">// reload tweets to get the newest</span>
      loadTweets();
}</pre>
</code>

</div></div> 


<p>And that&#8217;s the Swiz version, folks!</p>



<strong>Next Up</strong>

<p>I&#8217;m supposed to be leaving the evaluations until the last
article, but I will say right away that Swiz certainly delivers on its promise
of cutting down boilerplate code. It&#8217;s a breeze to work with, and the only
tough spot is if you&#8217;re not using an AMF service.</p>



<p>Next time we&#8217;re going to look at our last framework, Mate, and
see how it takes advantage of MXML to make a simple, declarative Flex
framework.<span style='font-size:10.0pt;font-family:"Times New Roman";
color:windowtext'><o:p></o:p></span></p>

<p style="padding-top: 15px; border-top: 1px solid #ccc;">Read the rest of FrameworkQuest 2008: 

<ul>

<li><a href="http://www.insideria.com/2008/12/frameworkquest-2008-introducti.html" target="_blank">Part 1 - Introduction</a></li>
<li><a href="http://www.insideria.com/2008/12/frameworkquest-2008-part-2-get.html" target="_blank">Part 2 - Get Control with Cairngorm</a></li>
<li><a href="http://www.insideria.com/2008/12/frameworkquest-2008-part-3-fra.html" target="_blank">Part 3 - Framework Agnostic Views with PureMVC</a></li>
<li>Part 4 - loC with Swiz</li>
<li><a href="http://www.insideria.com/2008/12/frameworkquest-2008-part-5-mat.html" target="_blank">Part 5 - Mate, the Pure MXML Framework</a></li>
<li><a href="http://www.insideria.com/2009/01/frameworkquest-2008-part-6-the.html" target="_blank">Part 6 - The Exciting Conclusion</a></li>
</ul></p>
<p  style="border-bottom: 1px solid #ccc; padding-top: 15px; margin-bottom: 15px;"></p>
]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33984-comment:2049452</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33984" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html#comment-2049452" />
    <title>Comment from Mansour Raad on 2008-12-23</title>
    <author>
        <name>Mansour Raad</name>
        <uri>http://thunderheadxpler.blogspot.com/</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://thunderheadxpler.blogspot.com/">
        <![CDATA[<p>Great post - thanks - I've been following SWIZ for quite some time and love its simplicity and it IoC</p>]]>
    </content>
    <published>2008-12-23T14:52:43Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33984-comment:2049460</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33984" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html#comment-2049460" />
    <title>Comment from Tony Hillerson on 2008-12-23</title>
    <author>
        <name>Tony Hillerson</name>
        <uri>http://thillerson.blogspot.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://thillerson.blogspot.com">
        <![CDATA[<p>So, upon further review, an HTTPService call does return an AsyncToken, so working with an HTTPService should work pretty smoothly with Swiz. Sorry for any confusion.</p>

<p>@Mansour - good to hear, thanks!</p>]]>
    </content>
    <published>2008-12-23T16:38:23Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33984-comment:2049891</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33984" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html#comment-2049891" />
    <title>Comment from Ansury on 2008-12-30</title>
    <author>
        <name>Ansury</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Nice, kinda like Spring for Flex. ^_^</p>]]>
    </content>
    <published>2008-12-30T20:40:28Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33984-comment:2049893</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33984" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html#comment-2049893" />
    <title>Comment from Tony Hillerson on 2008-12-30</title>
    <author>
        <name>Tony Hillerson</name>
        <uri>http://thillerson.blogspot.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://thillerson.blogspot.com">
        <![CDATA[<p>if you want something even more like Spring for Flex, try Spring for Actionscript (Prana): <br />
<a href="http://www.herrodius.com/blog/158">http://www.herrodius.com/blog/158</a><br />
<a href="http://http://www.pranaframework.org/">http://http://www.pranaframework.org/</a></p>]]>
    </content>
    <published>2008-12-30T20:51:34Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33984-comment:2060873</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33984" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html#comment-2060873" />
    <title>Comment from Mike on 2009-06-01</title>
    <author>
        <name>Mike</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Thanks for continuing in this Framework series, I like it a lot. Mike from <a href="http://www.goarticles.com/cgi-bin/showa.cgi?C=1649504">the jump manual</a> guide.</p>]]>
    </content>
    <published>2009-06-02T06:24:52Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33984-comment:2066406</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33984" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html#comment-2066406" />
    <title>Comment from Frank on 2009-06-18</title>
    <author>
        <name>Frank</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi,</p>

<p>This is great tutorial. First, I downloaded your code but there are things missing. Namely the window component. I was able to modify to work without the missing code, but now when I compile and run, nothing happens..no errors or anything. The grids appear on the browser of <a href="http://www.firstwebhosting.net/online-marketing.html">internet marketing</a> but no data is displayed. Please bear in mind that I do not know anything on what I need to do to set up Livecycle. So, could you please email me of call me through <a href="http://www.firstwebhosting.net/voice-over-ip.html">internet phone</a> the complete codeset and let me know if there's anyway you could help me diagnose my problem. As a sidenote, I noticed on a previous version of Flex (version 2), there is a Livecycle Data Services ES 2.5.1 comes up as an option when on my Programs launch bar. I'm trying to run version 3 of Flex on a different box, and it does not contain this. Could this be the problem?</p>

<p>Thanks</p>

<p>Frank<br />
</p>]]>
    </content>
    <published>2009-06-18T07:34:53Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33984-comment:2193111</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33984" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/frameworkquest-2008-part-4-ioc.html#comment-2193111" />
    <title>Comment from Dave on 2009-11-19</title>
    <author>
        <name>Dave</name>
        <uri>http://taller4idiots.com/grow-taller-for-idiots/</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://taller4idiots.com/grow-taller-for-idiots/">
        <![CDATA[<p>Indeed there is a lot of talk about beans in Java-land, for those of you who don’t know, but all they mean is some sort of component. </p>

<p>An I didn't know that the Swiz swc library adds two tags to the list of metadata that the Flex compiler will keep around, Autowire, and Mediate. We’ll look at Mediate in a bit, but Autowire is the first example of Swiz’s IoC at work. </p>

<p>Dave From <a href="http://taller4idiots.com/grow-taller-for-idiots/">grow taller for idiots</a></p>]]>
    </content>
    <published>2009-11-19T15:00:24Z</published>
  </entry>

</feed
