<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>The Kiwi Project</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.adobe.com/kiwi/atom.xml" />
   <id>tag:blogs.adobe.com,2009:/kiwi//54</id>
    <link rel="service.post" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54" title="The Kiwi Project" />
    <updated>2007-02-26T18:08:38Z</updated>
    <subtitle>Read/Write Web Components for Flex</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 3.38</generator>
 
<entry>
    <title>The Kiwi Team is Hiring!</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/08/the_kiwi_team_is_hiring.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1441" title="The Kiwi Team is Hiring!" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1441</id>
    
    <published>2006-08-04T00:18:56Z</published>
    <updated>2007-02-26T18:08:38Z</updated>
    
    <summary>Interested in working on a cutting-edge, Flex-based, &quot;Web 2.0&quot; project? Interested in building one of the first Apollo apps from the ground up? The Kiwi team is currently interviewing candidates for a senior engineering position. If you&apos;ve got solid Java/OO...</summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="General" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<p>Interested in working on a cutting-edge, Flex-based, "Web 2.0" project?  Interested in building one of the first <a href="http://labs.adobe.com/wiki/index.php/Apollo">Apollo</a> apps from the ground up?  The Kiwi team is currently interviewing candidates for a senior engineering position.  If you've got solid Java/OO skills (Flex experience is obviously a plus) and live in the SF Bay Area, we want to hear from you!  You can find the job description posted <a href="http://cooljobs.adobe.com/frameset.html?goto=er-joblist">here</a> (search for "kiwi", then click on "Computer Scientist").</p>]]>
        
    </content>
</entry>
<entry>
    <title>Loading Flex Skins at Runtime</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/07/loading_flex_skins_at_runtime.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1419" title="Loading Flex Skins at Runtime" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1419</id>
    
    <published>2006-07-28T23:05:16Z</published>
    <updated>2007-02-26T18:12:39Z</updated>
    
    <summary>flex,skinning,actionscript There are lots of great resources out there on how to skin your Flex applications.&amp;#160; Quick recap: Flex supports two approaches to skinning:&amp;#160; graphical and programmatic.&amp;#160; Graphical skinning involves creating graphical assets in Flash, Photoshop, Fireworks, etc. and embedding...</summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<!-- #BeginTags --><p class="tags"><a href="http://www.technorati.com/tag/flex" rel="tag">flex</a>,<a href="http://www.technorati.com/tag/skinning" rel="tag">skinning</a>,<a href="http://www.technorati.com/tag/actionscript" rel="tag">actionscript</a></p><!-- #EndTags -->
                           <p>There are <a href="http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000800.html">lots</a> of <a href="http://store1.adobe.com/devnet/flex/quickstart/skinning_components/">great</a> <a href="http://www.adobe.com/devnet/flex/articles/flex_skins.html">resources</a> out there on <a href="http://weblogs.macromedia.com/pent/archives/2006/07/writing_flex_2.cfm">how</a> <a href="http://www.adobe.com/devnet/flex/articles/creating_comp_pt2_02.html">to</a> <a href="http://weblogs.macromedia.com/mc/archives/2005/06/windows_xp_them.cfm">skin</a> your Flex applications.&#160; Quick recap: Flex supports two approaches to skinning:&#160; <strong>graphical</strong> and <strong>programmatic</strong>.&#160; Graphical skinning involves creating graphical assets in Flash, Photoshop, Fireworks, etc. and embedding them in your Flex application.&#160; Programmatic skinning involves creating an ActionScript class which defines the skin for a control.&#160; As you might guess, graphical skinning is easier, programmatic skinning more powerful. </p>
                             <p>One drawback to both approaches is that the skinned resources (SWF/PNG/GIF/etc. for graphical skins, the AS class file for programmatic skins) must be available at compile-time for the skins to be applied.&#160; Or do they?&#160; In this post I'll describe a neat trick for pulling in graphical skins at run-time (using a <strong>live demo with source code</strong>).</p>
                             <p>To make this example as simple as possible, I'm going to create a  Flex app that allows the Button control to be dynamically skinned.&#160; This app will pull down a skinning SWF at runtime, load the skins, and apply them to the Button control.&#160; Again, to keep it simple I'm going to use the <a href="http://download.macromedia.com/pub/developer/flex_skins_flash.zip">skin template file</a> provided in <a href="http://www.adobe.com/devnet/flex/articles/flex_skins.html">NJ's skinning article</a>, and apply the RadioButton skins to the Button control.&#160; (A tip of the cap to <a href="http://blogs.adobe.com/rgonzalez/">Roger Gonzalez</a> and <a href="http://rictus.com/muchado/">NJ</a> for basically coming up with this solution.) </p>
                             <h4>Step #1: Create a wrapper SWF for the skin assets</h4>
                           <p>The skin assets are in the aforementioned skin template file.&#160; I want to create a wrapper SWF that my Flex app can load at runtime and from which it can extract the appropriate assets, in this case the four symbols for the RadioButton control.&#160; Here's the source for wrapper SWF:</p>
                             <p><tt><font color="#0066CC">package<br />
                             {<br />
&#160; import flash.display.Sprite;</font></tt></p>
                             <p><font color="#0066CC"><tt> &#160; public class Wrapper extends Sprite<br />
&#160; {<br />
&#160;&#160;&#160; [Embed(source=&quot;flex_skins.swf&quot;,symbol=&quot;RadioButton_upIcon&quot;)]<br />
&#160;&#160;&#160; public var rbUpSkin: Class;<br />
&#160;&#160;&#160; [Embed(source=&quot;flex_skins.swf&quot;,symbol=&quot;RadioButton_downIcon&quot;)]<br />
&#160;&#160;&#160; public var rbDownSkin: Class;<br />
&#160;&#160;&#160; [Embed(source=&quot;flex_skins.swf&quot;,symbol=&quot;RadioButton_disabledIcon&quot;)]<br />
&#160;&#160;&#160; public var rbDisabledSkin: Class;<br />
&#160;&#160;&#160; [Embed(source=&quot;flex_skins.swf&quot;,symbol=&quot;RadioButton_overIcon&quot;)]<br />
&#160;&#160;&#160; public var rbOverSkin: Class;<br />
&#160; }<br />
        }</tt></font></p>
                           <h4> Step #2: Put the wrapper SWF on your web server</h4>
                           <p>The Flex app needs to load the wrapper SWF from somewhere!</p>
                             <h4>Step #3: In your Flex app, use a Loader to load the wrapper SWF</h4>
                             <p> I created a utility class called ClassLoader to wrap up functionality related to loading the SWF and extracting the class.&#160; Here are the key lines:</p>
                             <p><tt><font color="#0066CC">loader = new Loader();<br />
  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);<br />
  loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);<br />
  loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);<br />
  ...</font></tt></p>
                             <p><font color="#0066CC"><tt> request = new URLRequest(swfLib);<br />
var context:LoaderContext = new LoaderContext();<br />
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);<br />
loader.load(request, context);</tt></font><br />                               
</p>
                             <p>Notice that the Loader loads the SWF into an  ApplicationDomain that has the current domain as its parent.&#160; This is the key to ensuring that the app can access the loaded class and its assets.</p>
                             <h4>                               Step #4: Get the class  from the loaded SWF and instantiate it </h4>
                             <p>Here we load the Class using an agreed-upon className (in this case, &quot;Wrapper&quot;):</p>
                             <p><tt><font color="#0066CC">var wrapperClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class;<br />
                             var wrapper:Object = new wrapperClass();</font></tt></p>
                             <h4><tt>                             </tt>Step #5: Apply the skins using setStyle</h4>
                             <p>You can apply the skins to a particular instance of Button or to all instances of Button.&#160; Here's the latter approach: </p>
                             <p><tt><font color="#0066CC">StyleManager.getStyleDeclaration(&quot;Button&quot;).setStyle(&quot;upSkin&quot;, wrapper.rbUpSkin);<br />
  StyleManager.getStyleDeclaration(&quot;Button&quot;).setStyle(&quot;downSkin&quot;, wrapper.rbDownSkin);<br />
  StyleManager.getStyleDeclaration(&quot;Button&quot;).setStyle(&quot;disabledSkin&quot;, wrapper.rbDisabledSkin);<br />
  StyleManager.getStyleDeclaration(&quot;Button&quot;).setStyle(&quot;overSkin&quot;, wrapper.rbOverSkin);</font></tt></p>
                             <h4>    Step #6: Run the app</h4>
                             <p>My sample app (running live <a href="http://blogs.adobe.com/kiwi/apps/Skins.swf">here</a>, with &quot;View Source&quot; enabled) displays a text field where you can enter the URL of the wrapper SWF (also live <a href="http://blogs.adobe.com/kiwi/apps/Wrapper.swf">here</a>).&#160; Enter the wrapper SWF's URL, click the &quot;Apply&quot; button, and you'll see that the button now looks like an oversized radio button.&#160; As you mouse over or click on the button, you'll notice that its appearance changes to display the appropriate skin.&#160; If you create your own wrapper SWF which exposes a different set of symbols with the same class names (rbUpSkin, etc.), you could point the sample app at it and have it load and display a different set of skins.</p>
                             <p>&#160;</p>
                             <p>So why would you want to do this?&#160; Dynamic skinning gives you one incredibly powerful benefit:&#160; <em>you can let your users put their skins on your app</em>.&#160; Imagine an MP3 player like  Winamp built in Flex.&#160; The developer doesn't need to create a library of skins for the app, he/she can just expose a UI for setting the skin SWF (perhaps in the Preferences dialog) and let the user pick and choose from whatever skins the community comes up with.&#160;Equally important, the developer has fine-grained control over which controls can be skinned and which should retain their original skins (by only calling setStyle on the desired controls).&#160; And last but not least, keeping the skins outside of the application SWF will keep the application file size from exploding as the skins proliferate (with a minor but certainly-acceptable-to-the-user performance hit when the skins are loaded). </p>
                             <p>&#160;</p>
                           ]]>
        
    </content>
</entry>
<entry>
    <title>Notetag in Depth</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/07/notetag_in_depth.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1331" title="Notetag in Depth" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1331</id>
    
    <published>2006-07-11T16:55:56Z</published>
    <updated>2006-07-11T16:56:02Z</updated>
    
    <summary><![CDATA[File under: notetag,kiwi,adobe,flex,architecture,mashupBrian Riggs has penned an in-depth article entitled &quot;NoteTag: Anatomy of a Flex mashup&quot;, now available on Flex DevNet site, that unifies many of the blog entries here to describe the architecture behind Notetag....]]></summary>
    <author>
        <name></name>
        
    </author>
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<!-- #BeginTags --><p class="tags">File under: <a href="http://www.technorati.com/tag/notetag" rel="tag">notetag</a>,<a href="http://www.technorati.com/tag/kiwi" rel="tag">kiwi</a>,<a href="http://www.technorati.com/tag/adobe" rel="tag">adobe</a>,<a href="http://www.technorati.com/tag/flex" rel="tag">flex</a>,<a href="http://www.technorati.com/tag/architecture" rel="tag">architecture</a>,<a href="http://www.technorati.com/tag/mashup" rel="tag">mashup</a></p><!-- #EndTags -->Brian Riggs has penned an in-depth article  entitled &quot;<a href="http://www.adobe.com/devnet/flex/articles/notetag.html">NoteTag: Anatomy of a Flex mashup</a>&quot;, now available on Flex DevNet site, that unifies many of the blog entries here to describe the architecture behind Notetag.<br/>
]]>
        
    </content>
</entry>
<entry>
    <title>Making HTTP calls in ActionScript 3</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/07/making_http_calls_in_actionscr.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1245" title="Making HTTP calls in ActionScript 3" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1245</id>
    
    <published>2006-07-03T23:16:27Z</published>
    <updated>2007-02-26T18:09:44Z</updated>
    
    <summary>The lingua franca of the web is HTTP, and no programming language can claim to be a web-oriented language if it doesn&apos;t fully support it. Custom APIs and modern protocols are increasingly being built on top of HTTP. Just as...</summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="ActionScript" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<p>The <em>lingua franca</em> of the web is HTTP, and no programming language can claim to be a web-oriented language if it doesn't fully support it.  Custom APIs and <a href="http://www.atomenabled.org/developers/api/atom-api-spec.php">modern protocols</a> are increasingly being built on top of HTTP.  Just as it's <a href="http://www.tbray.org/ongoing/When/200x/2006/01/08/No-New-XML-Languages">rarely a good idea to invent a new XML language</a>, it's increasingly apparent that HTTP, and more broadly <a href="http://en.wikipedia.org/wiki/REST">REST</a>, is almost always the most appropriate foundation upon which to build new web APIs.</p>

<p>So how does ActionScript 3 stack up in the area of HTTP support?  I'll (arbitrarily) give a score to AS3's support for the core elements of a minimal HTTP implementation.</p>

<h4>Methods</h4>

<p>AS3's <a href="http://livedocs.macromedia.com/flex/2/langref/mx/rpc/http/HTTPService.html">HTTPService </a>class supports the basic HTTP methods (GET, POST, PUT, DELETE, HEAD, OPTIONS, and TRACE), but doesn't allow custom methods.  The <a href="http://en.wikipedia.org/wiki/Webdav">WebDAV protocol</a> uses a handful of custom HTTP methods (PROPFIND, PROPPATCH, MKCOL, etc.) which HTTPService would be unable to invoke, so it may be a while before we see an AS3-based WebDAV implementation.</p>

<p><strong>Score: 4/5</strong> (Support for custom methods is missing, but few APIs use them anyhow)</p>

<h4>Request headers</h4>

<p>HTTPService has a headers property which can hold an arbitrary Array of name-value pairs.</p>

<p><strong>Score: 5/5</strong></p>

<h4>Response headers</h4>

<p>Unfortunately, there's no way to extract the headers from an HTTP response.  (If you're interested in verifying this, just make an HTTPService call to a bogus page and set a breakpoint in the fault handler.  When execution stops there, examine the FaultEvent in Flex Builder's Variables window -- there's no evidence anywhere that the error is indeed a 404.)  I had a conversation with <a href="http://weblogs.macromedia.com/mchotin/">Matt Chotin</a> of the Flex team about this some months ago, and he indicated that not all browsers expose the headers.  </p>

<p>This is a pretty significant limitation, especially since REST principles are motivating the designers of <a href="http://www.atomenabled.org/developers/api/atom-api-spec.php">more recent protocols</a> and APIs to leverage the HTTP status code vocabulary to define the semantics of method results, rather than invent new vocabularies in the form of custom responses.</p>

<p><strong>Score: 1/5</strong> (I'll give it one point, since at least it's possible to distinguish between <a href="http://livedocs.macromedia.com/flex/2/langref/mx/rpc/events/ResultEvent.html">successful calls</a> and <a href="http://livedocs.macromedia.com/flex/2/langref/mx/rpc/events/FaultEvent.html">unsuccessful calls</a>.)</p>

<h4>Authentication</h4>

<p>HTTPService supports authentication against a remote endpoint via the setRemoteCredentials method.  Alternatively, the user's credentials can be specified in Flex Data Server's proxy-service.xml file.</p>

<p><strong>Score: 5/5</strong></p>

<h4>Overall: 15/20</h4>

<p>With the glaring exception of support for response headers, AS3's support for HTTP is full-featured enough to implement just about any REST-style protocol or API.  Let's hope the Flex and Apollo teams can fill this one remaining hole in a future release.</p>]]>
        
    </content>
</entry>
<entry>
    <title>Notetag updated for Flex 2 release</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/06/notetag_updated_for_flex_2_rel.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1209" title="Notetag updated for Flex 2 release" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1209</id>
    
    <published>2006-06-28T16:46:55Z</published>
    <updated>2006-06-28T16:47:09Z</updated>
    
    <summary>File under: adobe,flex,kiwi,notetagFlex 2 was officially released today.&amp;#160; Accordingly, we&apos;ve updated the Notetagdownloadable bits on labs.adobe.com to be compatible with this official release.&amp;#160; Enjoy!...</summary>
    <author>
        <name></name>
        
    </author>
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<!-- #BeginTags --><p class="tags">File under: <a href="http://www.technorati.com/tag/adobe" rel="tag">adobe</a>,<a href="http://www.technorati.com/tag/flex" rel="tag">flex</a>,<a href="http://www.technorati.com/tag/kiwi" rel="tag">kiwi</a>,<a href="http://www.technorati.com/tag/notetag" rel="tag">notetag</a></p><!-- #EndTags --><a href="http://www.adobe.com/products/flex/">Flex 2</a> was <a href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/200606/062806Flex2.html">officially released today</a>.&#160; Accordingly, we've updated the <a href="http://labs.adobe.com/wiki/index.php/NoteTag">Notetag</a>downloadable bits on <a href="http://labs.adobe.com/"> labs.adobe.com</a> to be compatible with this official release.&#160; Enjoy! <br/>
]]>
        
    </content>
</entry>
<entry>
    <title>RSS and RIAs</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/06/rss_and_rias.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1094" title="RSS and RIAs" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1094</id>
    
    <published>2006-06-09T22:23:56Z</published>
    <updated>2006-06-09T22:24:01Z</updated>
    
    <summary>File under: adobe,kiwi,flex,apollo,rss,web2.0,riaQuoted from http://blogs.zdnet.com/Stewart/?p=33: » RSS Round Up and the Rich Internet | The Universal Desktop | ZDNet.com I think RSS is so important for the RIA vision because it breaks down the data into simple, easy to consume...</summary>
    <author>
        <name></name>
        
    </author>
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<!-- #BeginTags --><p class="tags">File under: <a href="http://www.technorati.com/tag/adobe" rel="tag">adobe</a>,<a href="http://www.technorati.com/tag/kiwi" rel="tag">kiwi</a>,<a href="http://www.technorati.com/tag/flex" rel="tag">flex</a>,<a href="http://www.technorati.com/tag/apollo" rel="tag">apollo</a>,<a href="http://www.technorati.com/tag/rss" rel="tag">rss</a>,<a href="http://www.technorati.com/tag/web2.0" rel="tag">web2.0</a>,<a href="http://www.technorati.com/tag/ria" rel="tag">ria</a></p><!-- #EndTags --><p>Quoted from <cite>http://blogs.zdnet.com/Stewart/?p=33</cite>:</p>
<blockquote>
  <p><a href="http://blogs.zdnet.com/Stewart/?p=33"> » RSS Round Up and the Rich Internet | The Universal Desktop | ZDNet.com </a></p>
  <!--StartFragment-->
  <p>I think RSS is so important for the RIA vision because it breaks down the data into simple, easy to consume bits - perfect for a developer creating an application that puts the content front and center. As RSS expands, and we're seeing that with <a href="http://www.microformats.org/">microformats</a>, the lure of pairing the technology with RIAs is only going to get stronger.</p>
  </blockquote>
<p>We completely agree, which is <a href="http://blogs.adobe.com/kiwi/2006/05/introductions.html">why The Kiwi Project exists</a> at Adobe.</p>
                           ]]>
        
    </content>
</entry>
<entry>
    <title>An Asynchronous Cookbook (Part Two)</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/06/an_asynchronous_cookbook_part_1.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1077" title="An Asynchronous Cookbook (Part Two)" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1077</id>
    
    <published>2006-06-09T18:25:10Z</published>
    <updated>2007-02-26T18:13:02Z</updated>
    
    <summary>In the previous post, I outlined a few different solutions to the problem of how to structure your asynchronous ActionScript code. The concept of an asynchronous method chain, in which a series of methods that make asynchronous calls to external...</summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="ActionScript" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<p>In the <a href="http://blogs.adobe.com/kiwi/2006/06/an_asynchronous_cookbook_part.html">previous post</a>, I outlined a few different solutions to the problem of how to structure your asynchronous ActionScript code.  The concept of an asynchronous method chain, in which a series of methods that make asynchronous calls to external services are executed sequentially, is an important one for Flex developers who want their apps to pull in data from multiple web services.  <a href="http://labs.adobe.com/wiki/index.php/NoteTag">NoteTag </a>is a prime example:  it publishes notes to <a href="http://www.blogger.com">Blogger </a>and/or <a href="http://www.typepad.com">TypePad</a>, and stores references to notes and tasks on <a href="http://del.icio.us">del.icio.us</a>.</p>

<p>But suppose that one method in the asynchronous chain needs some piece of data generated by an earlier method in the chain.  How can you make state available to more than one method in the chain?</p>

<p><strong>Problem #4: </strong>One or more methods in an asynchronous method chain need access to data generated somewhere else in the chain.  For example, imagine that our getFirstFeed method needs to return the first feed in an Atom service document <em>and </em>the Atom service document.</p>

<p><strong>Solution #4a: </strong><em>Stash the data onto the call object and pass it down the chain</em> (per <a href="http://kuwamoto.org/2006/05/16/dealing-with-asynchronous-events-part-1">Sho’s suggestion</a>). This approach works fine in the simple case, but suppose you have a really long chain of methods – you might end up passing data through a bunch of methods that don’t need it, just so that the last method can use the data.</p>

<p><strong>Solution #4b: </strong><em>Stash the data on the enclosing object as a private data member.</em> This is perhaps the simplest solution, as it makes the data available to any method in the chain.  <strong>But </strong>if the client method is called a second time before it has finished its first series of asynchronous calls, then the stashed data could be overwritten!  What we really want is a way to ensure that any state we generate during the execution of the asynchronous method chain is scoped on a per-method-invocation basis…</p>

<p><strong>Solution #4c: </strong><em>Achieve per-method-invocation variable-scoping by putting the logic for the chained calls into an internally-scoped delegate class which is instantiated when the client method is called.</em>  Because a new delegate is instantiated each time the method is called, the data can be stored on the delegate without any risk of its being overwritten.  This approach can be done by convention (by forcing your clients to use a factory class that creates a new object for each operation) or explicitly (by having the method literally create a delegate object, as below).</p>

<pre style="background-color:#CCCCCC; overflow: scroll;">
public class FeedRetriever extends EventDispatcher
{
    private var protocol:AtomPublishingProtocol; // initialized elsewhere

<p>    // Dispatches a GetFeedEvent after retrieving the first feed listed<br />
    // in the service document.<br />
    public function getFirstFeed(serviceURI:URI):void<br />
    {<br />
        var delegate:FeedRetrieverDelegate =<br />
            new FeedRetrieverDelegate(this,protocol);<br />
        delegate.getFirstFeed(serviceURI);<br />
    }<br />
}</p>

<p>// Internally-scoped delegate which is instantiated on every call to<br />
// FeedRetriever.getFirstFeed (and which can therefore safely store state).<br />
internal class FeedRetrieverDelegate<br />
{<br />
    private var target:IEventDispatcher;<br />
    private var protocol:AtomPublishingProtocol;</p>

<p>    // State that needs to be tracked (the service document).<br />
    private var service:IService;<br />
	<br />
    public function FeedRetrieverDelegate(target:IEventDispatcher,<br />
        protocol:AtomPublishingProtocol):void<br />
    {<br />
        this.target = target;<br />
        this.protocol = protocol;<br />
    }</p>

<p>    public function getFirstFeed(serviceURI:URI):void<br />
    {<br />
        // Use a utility class to handle registration and unregistration<br />
        // of event listeners.<br />
        var responder:AsyncResponder = new AsyncResponder();<br />
        responder.setNextEventHandler(protocol,<br />
            onGetService, // result handler<br />
            “getService”, // result event<br />
            onFault,      // fault handler<br />
            “atomFault”); // fault event<br />
		<br />
        // Make the asynchronous call to retrieve the service document.<br />
        protocol.getService(serviceURI);<br />
    }</p>

<p>    private function onGetService(event:GetServiceEvent):void<br />
    {<br />
        // Store the service document since the next method needs<br />
        // access to it.<br />
        this.service = event.service;</p>

<p>        // Get the collection that represents the first feed.<br />
        var collection:ICollection = service.workspaces[0].collections[0];<br />
	<br />
        // Use a utility class to handle registration and unregistration<br />
        // of event listeners.<br />
        var responder:AsyncResponder = new AsyncResponder();<br />
        responder.setNextEventHandler(protocol,<br />
            onGetFeed,    // result handler<br />
            “getFeed”);   // result event<br />
            onFault,      // fault handler<br />
            “atomFault”); // fault event<br />
	<br />
        // Make the asynchronous call to retrieve the first feed.<br />
        protocol.getFeed(collection);<br />
    }</p>

<p>    private function onGetFeed(event:GetFeedEvent):void<br />
    {<br />
        // Dispatch a result event to the caller, using<br />
        // the passed-in target object.<br />
        var newEvent:GetFeedEvent = new GetFeedEvent();<br />
        newEvent.feed = event.feed;<br />
        newEvent.service = this.service;<br />
        target.dispatchEvent(newEvent);							<br />
    }</p>

<p>    private function onFault(event:AtomFaultEvent):void<br />
    {<br />
        // Do fault processing...<br />
    }</p>

<p>    // ...<br />
}<br />
</pre></p>

<p>But it’s not always ideal from an object-orientation perspective to separate this logic into two classes.  Is there a way that we can attain per-method-invocation variable-scoping without using multiple classes?  Our final solution accomplishes just that.</p>

<p><strong>Solution #4d: </strong><em>Put your responder code in one or more closures.</em>  (A closure is a function that exists within the body of another function and which when executed has its own set of local variables.) Within a closure, you can access variables in the outer scope – a nice benefit.  The drawback?  Because the closure needs to be declared prior to the asynchronous method call, the flow of control within the code can be a bit confusing.</p>

<pre style="background-color:#CCCCCC; overflow: scroll;">
public class FeedRetriever extends EventDispatcher
{
    private var protocol:AtomPublishingProtocol; // initialized elsewhere

<p>    // Dispatches a GetFeedEvent that contains the first feed and<br />
    // the service document.<br />
    public function getFirstFeed(serviceURI:URI):void<br />
    {<br />
        // #1: The flow of control starts here...<br />
	<br />
        // Declare a function closure that will be called later.  <br />
        var onGetService:Function = function(event1:GetServiceEvent):void<br />
        {<br />
            // #3: After protocol.getService completes, control jumps<br />
            // to here...</p>

<p>            // We set the service document into a local variable,<br />
            // which is accessible even from within the subsequent<br />
            // closure.<br />
            var serviceLocalVar:IService = event1.service;<br />
			<br />
            // Get the first feed in the service document.<br />
            var collection:ICollection = serviceLocalVar.workspaces[0].collections[0];<br />
	<br />
            // Declare another function closure to be called later.<br />
            var onGetFeed:Function = function(event2:GetFeedEvent):void<br />
            {<br />
                // #5: After protocol.getFeed completes, control<br />
                // jumps to here, and finishes by dispatching<br />
                // the client event.</p>

<p>                // Dispatch a result event to the caller.<br />
                var newEvent:GetFeedEvent = new GetFeedEvent();<br />
                newEvent.feed = event2.feed</p>

<p>                // Notice how we can access serviceLocalVar - <br />
                // this is one nice benefit of closures.<br />
                newEvent.service = serviceLocalVar;<br />
                dispatchEvent(newEvent);	<br />
            }</p>

<p>            // #4: ... and continues down to here...</p>

<p>            // Use a utility class to handle registration and<br />
            // unregistration of event listeners.<br />
            var responder2:AsyncResponder = new AsyncResponder();<br />
            responder2.setNextEventHandler(protocol,<br />
                onGetFeed, // result handler<br />
                GetFeedEvent.GET_FEED, // result event<br />
                onFault, // fault handler<br />
                AtomFaultEvent.ATOM_FAULT); // fault event<br />
	<br />
            // Make the asynchronous call to retrieve the first feed.<br />
            protocol.getFeed(collection);<br />
        }</p>

<p>        // #2: ... and continues down to here...</p>

<p>        // Use a utility class to handle registration and unregistration<br />
        // of event listeners.<br />
        var responder1:AsyncResponder = new AsyncResponder();<br />
        responder1.setNextEventHandler(protocol,<br />
            onGetService, // result handler<br />
            “getService”, // result event<br />
            onFault,      // fault handler<br />
            “atomFault”); // fault event<br />
	<br />
        // Make the asynchronous call.<br />
        protocol.getService();<br />
    }</p>

<p>    private function onFault(event:AtomFaultEvent):void<br />
    {<br />
        // Do fault processing...<br />
    }<br />
}<br />
</pre></p>

<p>Following the flow of control in the previous example is a bit like watching a yoyo in action.  Sho has some ideas<br />
on <a href="http://kuwamoto.org/2006/05/16/dealing-with-asynchronous-events-part-2/">how to improve the readability</a> of closure-heavy code.</p>

<p><strong>Summary: </strong>When it comes to implementing asynchronous methods in ActionScript, there are a number of approaches that you can take.  In many cases you’ll be able to stick with the simplest approach (create an event listener to respond to the event), but there are certain situations where the more complicated approaches are called for.  For each such situation, ask yourself the following questions:<br />
<ul><br />
<li>Do I need to process the result of an asynchronous call?</li><br />
<li>Will the object that makes the asynchronous call be used again after I’m done with it?</li><br />
<li>Do I need to make multiple sequential asynchronous calls?</li><br />
<li>In the chain of sequential asynchronous calls, does a method need access to data that is generated by a different method in the chain?</li><br />
</ul></p>

<p>If the answer to any of these questions is “yes”, then consider using one or more of the following:<br />
<ul><br />
<li>A helper class that can manage event registration (a la AsyncResponder)</li><br />
<li>Stateful objects</li><br />
<li>Delegates that achieve per-method-invocation variable scoping</li><br />
<li>Closures</li><br />
</ul></p>]]>
        
    </content>
</entry>
<entry>
    <title>An Asynchronous Cookbook (Part One)</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/06/an_asynchronous_cookbook_part.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1076" title="An Asynchronous Cookbook (Part One)" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1076</id>
    
    <published>2006-06-05T21:37:39Z</published>
    <updated>2007-02-26T18:14:03Z</updated>
    
    <summary>If you haven’t read Sho Kuwamoto’s series of blog posts on dealing with asynchronous events, I highly recommend them. Any Flex developer that builds applications that make remote calls is eventually going to run into the problem of how best...</summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="ActionScript" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<p>If you haven’t read Sho Kuwamoto’s <a href="http://kuwamoto.org/2006/05/16/dealing-with-asynchronous-events-part-1/">series </a>of <a href="http://kuwamoto.org/2006/05/16/dealing-with-asynchronous-events-part-2/">blog </a><a href="http://kuwamoto.org/2006/05/19/dealing-with-asynchronous-events-part-3/">posts </a>on dealing with asynchronous events, I highly recommend them.  Any Flex developer that builds applications that make remote calls is eventually going to run into the problem of how best to structure their code.  In the course of developing <a href="http://labs.adobe.com/wiki/index.php/NoteTag">NoteTag</a>, we tried dozens of solutions to “the asynchronous problem”. The bad news:  there is no one-size-fits-all solution.  The good news: there are a few key rules-of-thumb which can guide you towards choosing the solution that’s right for the situation.</p>

<p>I’ll walk through the specific problems we’re trying to solve, using the example of a class which provides support for retrieving an Atom service document.  (In <a href="http://www.ietf.org/html.charters/atompub-charter.html">Atom Publishing Protocol</a> parlance, a service document is an index of blogs that are available from a particular account on a blog server.)</p>

<p><strong>Problem #1: </strong>Asynchronous calls don’t return right away, but you often need to process the result.</p>

<p><strong>Solution #1: </strong>Create a result handler method, and add it as an event listener to the object which is making the asynchronous call.</p>

<pre style="background-color:#CCCCCC; overflow: scroll;">
public class AtomPublishingProtocol extends EventDispatcher
{
    // Dispatches a GetServiceEvent after retrieving the service document.
    public function getService(serviceURI:URI):void
    {
        var service:HTTPService = new HTTPService();
        service.url = serviceURI.toString();
        service.method = "GET";
        service.resultFormat="e4x";
        service.addEventListener("result",onGetServiceResult);
        service.send();
    }

<p>    private function onGetServiceResult(event:ResultEvent):void<br />
    {<br />
        var xml:XML = new XML(event.result);<br />
        var atomEvent:GetServiceEvent = new GetServiceEvent();<br />
        <br />
        // Convert the XML to a domain object.<br />
        atomEvent.service = ModelFactory.createServiceFromXML(xml));</p>

<p>        dispatchEvent(atomEvent);<br />
    }</p>

<p>    // ...<br />
}<br />
</pre></p>

<p>This is the simplest problem, with a correspondingly simple solution.  (I’ve left out the fault listener to keep this simplest of examples as simple as possible.)  One thing to point out:  we didn’t need to unregister the HTTPService event listener because we created a new instance and “threw it away”.  But that won’t always be the case…</p>

<p><strong>Problem #2: </strong>Asynchronous calls are made using an object that can be called from multiple places in the application.  (Imagine that our app reuses one instance of HTTPService for all remote calls.)</p>

<p><strong>Solution #2: </strong>For every event registration, there must be a corresponding “unregistration”.  Failure to unregister an event listener could lead to it being called again if the event-generating object (HTTPService, in the following example) is called from somewhere else.</p>

<pre style="background-color:#CCCCCC; overflow: scroll;">
public class AtomPublishingProtocol extends EventDispatcher
{
    private var service:HTTPService; // initialized elsewhere

<p>    // Dispatches a GetServiceEvent after retrieving the service document.<br />
    public function getService(serviceURI:URI):void<br />
    {<br />
        service.url = serviceURI.toString();<br />
        service.method = "GET";<br />
        service.resultFormat="e4x";<br />
        service.addEventListener("result",onGetServiceResult);<br />
        service.addEventListener(”fault”,onFault);<br />
        service.send();<br />
    }</p>

<p>    private function onGetServiceResult(event:ResultEvent):void<br />
    {<br />
        // Manually unregister the listeners in case service<br />
        // is used from somewhere else.<br />
        service.removeEventListener(“result”,onGetServiceResult);<br />
        service.removeEventListener(“fault”,onFault);</p>

<p>        var xml:XML = new XML(event.result);<br />
        var atomEvent:GetServiceEvent = new GetServiceEvent();</p>

<p>        // Convert the XML to a domain object.<br />
        atomEvent.service = ModelFactory.createServiceFromXML(xml));</p>

<p>        dispatchEvent(atomEvent);<br />
    }</p>

<p>    private function onFault(event:FaultEvent):void<br />
    {<br />
        // Manually unregister the listeners here too!<br />
        service.removeEventListener(“result”,onGetServiceResult);<br />
        service.removeEventListener(“fault”,onFault);</p>

<p>        // Do fault processing...<br />
    }</p>

<p>    // ...<br />
}<br />
</pre></p>

<p><strong>Problem #3:</strong> A method needs to perform multiple asynchronous calls before returning.  Let’s make the use case a bit more complicated:  we now use our AtomPublishingProtocol implementation to return the first feed listed in the service document.</p>

<p><strong>Solution #3a:</strong> Chain the calls together manually.</p>

<pre style="background-color:#CCCCCC; overflow: scroll;">
public class FeedRetriever extends EventDispatcher
{
    private var protocol:AtomPublishingProtocol; // initialized elsewhere

<p>    // Dispatches a GetFeedEvent after retrieving the first feed listed<br />
    // in the service document.<br />
    public function getFirstFeed(serviceURI:URI):void<br />
    {<br />
        // Manually set up the event listeners.<br />
        protocol.addEventListener(“getService”,onGetService);<br />
        protocol.addEventListener(“atomFault”,onGetServiceFault);<br />
	<br />
        // Make the asynchronous call to retrieve the service document.<br />
        protocol.getService(serviceURI);<br />
    }</p>

<p>    private function onGetService(event:GetServiceEvent):void<br />
    {<br />
        // Manually unregister the event listeners.<br />
        protocol.removeEventListener(”getService”,onGetService);<br />
        protocol.removeEventListener(”atomFault”,onGetServiceFault);</p>

<p>        // Get the collection that represents the first feed.<br />
        var collection:ICollection = event.service.workspaces[0].collections[0];</p>

<p>        // Manually set up the next set of event listeners.<br />
        protocol.addEventListener(“getFeed”,onGetFeed);<br />
        protocol.addEventListener(“atomFault”,onGetFeedFault);</p>

<p>        // Make the asynchronous call to retrieve the first feed.<br />
        protocol.getFeed(collection);<br />
    }</p>

<p>    private function onGetServiceFault(event:AtomFaultEvent):void<br />
    {<br />
        // Manually unregister the event listeners.<br />
        protocol.removeEventListener(”getService”,onGetService);<br />
        protocol.removeEventListener(”atomFault”,onGetServiceFault);</p>

<p>        // Do fault processing...<br />
    }</p>

<p>    private function onGetFeed(event:GetFeedEvent):void<br />
    {<br />
        // Ugh!  How many times do we have to manually<br />
        // add and remove event listeners?!?!?<br />
        protocol.removeEventListener(”getFeed”,onGetFeed);<br />
        protocol.removeEventListener(“atomFault”,onGetFeedFault);</p>

<p>        // Dispatch a result event to the caller.<br />
        var newEvent:GetFeedEvent = new GetFeedEvent();<br />
        newEvent.feed = event.feed;<br />
        dispatchEvent(newEvent);							<br />
    }</p>

<p>    private function onGetFeedFault(event:AtomFaultEvent):void<br />
    {<br />
        // Manually unregister the event listeners.<br />
        protocol.removeEventListener(”getFeed”,onGetFeed);<br />
        protocol.removeEventListener(”atomFault”,onGetFeedFault);<br />
	<br />
        // Do fault processing...<br />
    }</p>

<p>    // ...<br />
}<br />
</pre></p>

<p>As you can see, it’s a real pain to manually handle registration and unregistration of event listeners.  A helper class which can take care of the event registration for us will simplify our code.</p>

<p><strong>Solution #3b:</strong> Use a helper class (e.g. <a href="http://livedocs.macromedia.com/labs/kiwi/connections/com/adobe/kiwi/connections/utils/AsyncResponder.html">AsyncResponder </a>to manage event registration. (For reasons of space, I don’t include the source for the helper class, but you can find it in the <a href="http://download.macromedia.com/pub/labs/kiwi/notetag/Connections_0525.zip">Connections library</a>, or in the <a href="http://download.macromedia.com/pub/labs/kiwi/notetag/NoteTag-source_0526.zip">NoteTag download</a>.)</p>

<pre style="background-color:#CCCCCC; overflow: scroll;">
public class FeedRetriever extends EventDispatcher
{
    private var protocol:AtomPublishingProtocol; // initialized elsewhere

<p>    // Dispatches a GetFeedEvent after retrieving the first feed listed<br />
    // in the service document.<br />
    public function getFirstFeed(serviceURI:URI):void<br />
    {<br />
        // Use a utility class to handle registration and unregistration<br />
        // of event listeners.<br />
        var responder:AsyncResponder = new AsyncResponder();<br />
        responder.setNextEventHandler(protocol,<br />
            onGetService, // result handler<br />
            “getService”, // result event<br />
            onFault,      // fault handler<br />
            “atomFault”); // fault event<br />
		<br />
        // Make the asynchronous call to retrieve the service document.<br />
        protocol.getService(serviceURI);<br />
    }</p>

<p>    private function onGetService(event:GetServiceEvent):void<br />
    {<br />
        // Get the collection that represents the first feed.<br />
        var collection:ICollection = event.service.workspaces[0].collections[0];<br />
	<br />
        // Use a utility class to handle registration and unregistration<br />
        // of event listeners.<br />
        var responder:AsyncResponder = new AsyncResponder();<br />
        responder.setNextEventHandler(protocol,<br />
            onGetFeed,    // result handler<br />
            “getFeed”);   // result event<br />
            onFault,      // fault handler<br />
            “atomFault”); // fault event<br />
	<br />
        // Make the asynchronous call to retrieve the first feed.<br />
        protocol.getFeed(collection);<br />
    }</p>

<p>    private function onGetFeed(event:GetFeedEvent):void<br />
    {<br />
        // Dispatch a result event to the caller.<br />
        var newEvent:GetFeedEvent = new GetFeedEvent();<br />
        newEvent.feed = event.feed;<br />
        dispatchEvent(newEvent);							<br />
    }</p>

<p>    private function onFault(event:AtomFaultEvent):void<br />
    {<br />
        // Do fault processing...<br />
    }</p>

<p>    // ...<br />
}<br />
</pre></p>

<p>This chaining of methods works quite well, and is reasonably easy for a reader to follow. (NoteTag uses this approach in a number of places, both explicitly with AsyncResponder and indirectly via the ChainedCommand class, which uses AsyncResponder to chain asynchronous method calls within <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html">Cairngorm </a>Commands.)</p>

<p>In the next post, I’ll add another wrinkle to this problem: what if one method in the asynchronous method chain needs access to data that was generated earlier in the chain?</p>]]>
        
    </content>
</entry>
<entry>
    <title>Architecting a Flex App</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/05/architecting_a_flex_app_1.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1058" title="Architecting a Flex App" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1058</id>
    
    <published>2006-05-31T23:49:05Z</published>
    <updated>2007-02-26T18:14:59Z</updated>
    
    <summary><![CDATA[ Web developers who take Flex for a spin may initially be confused by the user interface model.&#160; Although a typical, servlet-style, request-response model will work in Flex, There Is A Better Way.&#160; Thanks to the &quot;[Binding]&quot; tag in the...]]></summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[                             <p> Web developers who take Flex for a spin may initially be confused by the user interface model.&#160; Although a typical, servlet-style, request-response model will work in Flex, There Is A Better Way.&#160; Thanks to the &quot;[Binding]&quot; tag in the Actionscript language, you can bind your view to your model data so that changes to the model are automatically reflected in the view.&#160; The <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html">Cairngorm</a> microarchitecture formalizes this approach, and is a great starting point for developers who want to figure out how to &quot;make it all work together&quot;.&#160; In this post I'll describe how variable binding, feature-driven development, and Cairngorm all work together for <a href="http://labs.adobe.com/wiki/index.php/NoteTag">NoteTag</a>.</p>
                             <p>Here's how a typical, non-trivial Flex app might be architected:</p>
                             <p><img src="http://blogs.adobe.com/kiwi/notetag_arch_003.jpg" width="450" height="443" hspace="10" /></p>
                             <p>Domain</p>
                             <ul>
                               <li>The classes that make up the domain model.&#160; In NoteTag, this includes Notes, Tasks, and Subscriptions.&#160; (A Subscription is a collection of related Notes or Tasks.)</li>
                             </ul>
                             <p>Model</p>
                             <ul>
                               <li>A Singleton that holds bindable instances of the domain model.&#160; In NoteTag, the ModelLocator Singleton holds the user's list of Subscriptions, the user's Connections, the current Subscription, the current Note, etc.</li>
                             </ul>
                             <p>View</p>
                             <ul>
                               <li>The UI components (generally, though not always, MXML files).&#160; The UI components that are state-dependent are bound to instance variables in the ModelLocator.&#160; Any changes to data in the ModelLocator will cause the UI to automatically update, provided that that data is marked as &quot;[Bindable]&quot;.&#160; An example in NoteTag is the NoteListView, which presents the list of Notes in the current Subscription.&#160; If the current Subscription or any of its Notes change then the NoteListView will automatically update to reflect the changes.</li>
                             </ul>
                             <p>Controller</p>
                             <ul>
                               <li>Infrastructure for implementing features as event-driven Commands.&#160; Examples in NoteTag include GetSubscriptionCommand, GetNoteCommand, etc.</li>
                             </ul>
                             <p>Business</p>
                             <ul>
                               <li> Business logic classes perform operations on Domain objects, often making calls to remote services and returning the results asynchronously.&#160; The SubscriptionManager class is the entry point for most of NoteTag's business logic.</li>
                             </ul>
                             <p>Service</p>
                             <ul>
                               <li>The services layer, which holds all classes that are used to make remote service (HTTPService, RemoteService, and WebService) calls.&#160; NoteTag uses a set of service factory classes, which decouple the configuration of specific HTTP services from the components that make calls to HTTP services. </li>
                             </ul>
                             <p>Most application features touch on some or all of these components.&#160; Here's the workflow for a typical  feature:</p>
                             <ol>
                               <li>The View broadcasts an event.</li>
                               <li>The singleton Controller receives the event, maps it to its corresponding Command, and executes the Command.</li>
                               <li>The Command delegates to the appropriate Business object to perform the business logic.</li>
                               <li>The Business object performs the business logic, possibly making one or more asynchronous calls to various Services, and returns the result by dispatching a new event  to the Command.</li>
                               <li>The Command assigns the result to the singleton Model.</li>
                               <li>Any Views that are bound to the data in the singleton Model are automatically updated.</li>
                             </ol>
                             <p>So how would this work for a specific feature?&#160; When the user selects a Note from the list of Notes (at the top of the screen, below), the Note is loaded from the appropriate repository (Blogger or TypePad) and displayed in the editor (at the bottom of the screen, below):</p>
                             <p><a href="images/03_notetag_published_note.jpg"><img src="http://blogs.adobe.com/kiwi/03_notetag_published_note_thumb.jpg" width="440" height="327" hspace="20" border="0" /></a></p>
                             <p>&#160;</p>
                             <p><strong>1. Broadcasting the Event</strong></p>
                             <p>When the user clicks on the first Note in the list, NoteListView dispatches an event, as follows:</p>
                             <p><tt>// NoteListView.mxml <br />
                             private function getSelectedEntry(event:ListEvent) : void<br />
                             {<br />
                            &#160; var selectedEntry:TagBasedEntry = <br />
                            &#160;&#160;&#160; TagBasedEntry(currentFeed.entries[event.rowIndex-1]);</tt></p>
                             <p><tt>&#160;	Application.application.dispatchEvent(<br />
                            &#160;&#160;&#160; new GetNoteEvent(selectedEntry.metadata,true));<br />
                             }</tt></p>
                             <p><strong>2. Responding to the Event</strong></p>
                             <p>Because NoteTag's Front Controller has registered itself to listen for all Command Events, it will be notified when GetNoteEvent is dispatched:<br />
                               <tt>// NoteTagController.as<br />
                               public class NoteTagController extends FrontController<br />
                               {<br />
&#160; public function NoteTagController()<br />
&#160; {<br />
&#160;&#160;&#160; addCommand(LoginEvent.EVENT_LOGIN, LoginCommand);<br />
&#160;&#160;&#160; addCommand(GetNoteEvent.EVENT_GET_NOTE, GetNoteCommand);<br />
&#160;&#160;&#160; addCommand(GetTaskEvent.EVENT_GET_TASK, GetTaskCommand);<br />
&#160;&#160;&#160; addCommand(PostNoteEvent.EVENT_POST_NOTE, PostNoteCommand);<br />
&#160;&#160;&#160; // more commands...<br />
&#160; }<br />
                               } </tt><br />
  Cairngorm's FrontController provides the infrastructure for listening for events and responding to them by executing the appropriate command.</p>
                             <p><strong>3. Executing the Command</strong></p>
                           <p> To retrieve the Note, NoteTag needs to make a call to the blog server that stores the user's notes.&#160; The GetNoteCommand, which implements Cairngorm's Command interface, takes care of this:</p>
                             <p> <tt>// GetNoteCommand.as<br />
                             internal class GetNoteCommand extends ChainedCommand<br />
                             {<br />
                             &#160;
public override function execute(event:CairngormEvent):void<br />
&#160;
{<br />
&#160;&#160;&#160; var initialEvent:GetNoteEvent = GetNoteEvent(event);<br />
<br />
&#160;&#160;&#160;
var subscriptionManager:SubscriptionManager =<br />
&#160;&#160;&#160;&#160;&#160;
ModelLocator.getInstance().subscriptionManager;<br />
<br />
&#160;&#160;&#160;
setNextEventHandler(subscriptionManager,<br />
&#160;&#160;&#160;&#160;&#160;
handleLoadNote,<br />
&#160;&#160;&#160;&#160;&#160;
LoadNoteEvent.EVENT_LOAD_NOTE,<br />
&#160;&#160;&#160;&#160;&#160;
onSubscriptionFault,<br />
&#160;&#160;&#160;&#160;&#160;
SubscriptionFaultEvent.EVENT_SUBSCRIPTION_FAULT);</tt></p>
                             <p><tt> &#160;&#160;&#160;	subscriptionManager.loadNote(initialEvent.metadata);<br />
 &#160; }<br />
  <br />
 &#160; private function handleLoadNote(event:LoadNoteEvent):void<br />
 &#160; {<br />
 &#160;&#160;&#160; // handle result here... <br />
 &#160; }<br />
  <br />
 &#160; // ...<br />
  }</tt></p>
                             <p>(You may have noticed that GetNoteCommand extends ChainedCommand -- this class chains asynchronous calls together using the setNextEventHandler method.&#160; In a future post, I'll go into greater detail on ChainedCommand, and asynchronous responders in general.) <br /></p>
                           <p><strong>4. Performing the Business Logic</strong></p>
                             <p>The SubscriptionManager handles the loading of the Note by executing a series of HTTP service calls to the tag server and the blog server.&#160; When the note has been loaded, the SubscriptionManager will dispatch a LoadNoteEvent, which will be handled by GetNoteCommand.handleLoadNote (see the next item).</p>
                             <p><strong>5. Updating the Model</strong></p>
                             <p>GetNoteCommand responds to the event by assigning the loaded Note to the appropriate data member on the ModelLocator:</p>
                             <p><tt>// GetNoteCommand.as<br />
internal class GetNoteCommand extends ChainedCommand<br />
{<br /> 
&#160;
// ...
</tt><tt><br />
  <br />
&#160; private function handleLoadNote(event:LoadNoteEvent):void<br />
&#160; {<br />
&#160;&#160;&#160; ModelLocator.getInstance().currentNote = event.note;<br />
&#160; }<br />
  <br />
&#160; // ...<br />
  }</tt></p>
                             <p><strong>6. Updating the View</strong></p>
                             <p>Any views that are bound to the ModelLocator's currentNote member will automatically update themselves to reflect the new data.&#160; NoteView, the component that's responsible for displaying the Note in an editor, is one such view:</p>
                             <p><tt>// NoteView.mxml<br />
&lt;mx:VBox xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;<br />
&#160;&#160;&#160;
xmlns:view=&quot;com.adobe.kiwi.notetag.view.*&quot;<br />
&#160;
&#160;
xmlns=&quot;*&quot;&gt;<br />
&#160;
&lt;mx:Script&gt;<br />
&#160; &lt;![CDATA[<br />
&#160;&#160;&#160; import com.adobe.kiwi.notetag.model.*;<br />

&#160;&#160;&#160; [Bindable] private var model:ModelLocator = ModelLocator.getInstance();<br />
&#160; ]]&gt;<br />
&#160;	&lt;/mx:Script&gt;<br />
<br />
	&#160;	&lt;view:NoteEdit id=&quot;noteEditor&quot; width=&quot;100%&quot; height=&quot;100%&quot;<br />
	&#160;&#160;&#160;
    <strong>note=&quot;{model.currentNote}&quot;</strong> /&gt;</tt><tt><br />
                             <br />
&lt;/mx:VBox&gt;</tt> </p>
                             <p>&#160;</p>
                             <p>Every other feature -- publishing a Note, fetching a Subscription, updating a Task -- is implemented with the same Event-to-Command-to-Model-to-View approach.&#160; Command-specific Events can be dispatched from multiple contexts, without knowing which Views will be affected.&#160; Views can bind to Model changes without knowing where the originating Event was dispatched from.&#160; Loose coupling leads to cleaner, more maintainable code. </p>
                           ]]>
        
    </content>
</entry>
<entry>
    <title>NoteTag Installation: Tips From the Field</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/05/notetag_installation_tips_from_1.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1048" title="NoteTag Installation: Tips From the Field" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1048</id>
    
    <published>2006-05-30T18:54:31Z</published>
    <updated>2007-02-26T18:15:43Z</updated>
    
    <summary>Here are some &quot;tips from the field&quot; to help with the NoteTag installation process. If you have any problems (or suggestions!), add them to the comments for this thread. 1) There are a few references to &quot;C:\Dev\workspace&quot; in the installation...</summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="General" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<p>Here are some "tips from the field" to help with the NoteTag installation process.  If you have any problems (or suggestions!), add them to the comments for this thread.</p>

<p>1) There are a few references to "C:\Dev\workspace" in the installation guide.  This is the suggested workspace folder location, but feel free to use any path.</p>

<p>2) With regard to the SSL keystore file, be sure that the name you use with keytool.exe is the same as the <attribute name="keystore"> element in jrun.xml.  For example, if the command to generate the keystore file is:</p>

<p><b>keytool -genkey -alias localhost -validity 9999 -keyalg RSA -keystore c:\notetag.keystore -keypass mypass -storepass mypass</b></p>

<p>then the SSL service in jrun.xml should look like this:</p>

<pre>&lt;service class=&quot;jrun.servlet.http.SSLService&quot; name=&quot;SSLService&quot;&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;port&quot;&gt;9100&lt;/attribute&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;keyStore&quot;&gt;{jrun.rootdir}/lib/notetag.keystore&lt;/attribute&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;keyStorePassword&quot;&gt;mypass&lt;/attribute&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;trustStore&quot;&gt;{jrun.rootdir}/lib/trustStore&lt;/attribute&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;socketFactoryName&quot;&gt;jrun.servlet.http.JRunSSLServerSocketFactory&lt;/attribute&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;deactivated&quot;&gt;false&lt;/attribute&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;bindAddress&quot;&gt;*&lt;/attribute&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;interface&quot;&gt;*&lt;/attribute&gt;</pre><pre><span style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>&lt;attribute name=&quot;clientAuth&quot;&gt;false&lt;/attribute&gt;</pre><pre>&lt;/service&gt;</pre>]]>
        
    </content>
</entry>
<entry>
    <title>AS3 programming 101 for C/C++ coders</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/05/as3_programming_101_for_cc_cod_1.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1040" title="AS3 programming 101 for C/C++ coders" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1040</id>
    
    <published>2006-05-28T05:42:15Z</published>
    <updated>2006-05-28T05:54:56Z</updated>
    
    <summary>In my previous article, I covered ActionScript 3 languange syntax and constructs that may be of interest to C/C++ coders starting out on ActionScript 3. This article covers areas of AS3 that are different from C/C++ in regards to functional...</summary>
    <author>
        <name>Darrick Brown</name>
        
    </author>
            <category term="ActionScript" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<p>In <a href="http://blogs.adobe.com/kiwi/2006/05/as3_language_101_for_cc_coders_1.html">my previous article</a>, I covered ActionScript 3 languange syntax and constructs that may be of interest to C/C++ coders starting out on ActionScript 3. This article covers areas of AS3 that are different from C/C++ in regards to functional issues that may be interesting to people with C/C++ experience. ActionScript 3 is a powerful language with some very nice features. However, as a long time C/C++ coder I found ActionScript lacking things I was used to having. </p>]]>
        <![CDATA[<p>&nbsp;</p>
<p><strong>No control over application message loop</strong></p>
<p>In a standard C/C++ application, your application has full control of the message loop. In Flash/ActionScript, this is not the case. The main application message loop is controlled by the application that is hosting the Flash player. This is either the browser, the stand alone flash player, or some other custom application. Flash is purely event driven. Your Flash application receives callbacks for every type of notification. This includes things like user events, application commands, and network responses. This means that ActionScript cannot block for any reason. If your Flash application blocks in a loop (or just just taking a long time computing something), the entire player and perhaps even the host application will block as well. Flash must handle everything via asynchronous callbacks. </p>
<p>In a typical desktop application written in C/C++, modal dialogs manage the message loop. This allows a modal dialog function to block and then return when the user is finished without causing the entire application to freeze. This is not the case in ActionScript. In ActionScript, you must display the modal dialog then return and wait for a callback that indicates what the user chose. This also means that using &quot;alert&quot; dialogs in ActionScript for debugging purposes is not entirely useful since the alert will display and the application will continue running.</p>
<p><a href="http://kuwamoto.org/">Sho Kuwamoto</a> from the Flex Builder team has a running series of articles covering the issues of &quot;Dealing with asynchronous events&quot;. So far, he has <a href="http://kuwamoto.org/2006/05/16/dealing-with-asynchronous-events-part-1/">Part 1</a>, <a href="http://kuwamoto.org/2006/05/16/dealing-with-asynchronous-events-part-2/">Part 2</a>, and <a href="http://kuwamoto.org/2006/05/19/dealing-with-asynchronous-events-part-3/">Part 3</a> available. I strongly recommend reading these articles. They provide a lot of good information for dealing with asynchronous nature of AS3. </p>
<p>&nbsp;</p>
<p><strong>No threads</strong></p>
<p>In Flash/Flex, your application executes in a single thread.  If you are used to using threads in your applications, this can feel somewhat constraining. However, since all AS3 applications are event driven and must handle everything asynchronously, AS3 has some nice language features that allows you to make asynchronous calls. Granted, asynchronous function calls are no where near a replacement for true threading, but asynchronous calls can provide for a similar user experience if you architect your application with this design pattern in mind.</p>
<p>The Timer class   is very useful in this area. The Timer class allows you to schedule a function to be called by the framework at a later time on fixed intervals via &quot;timer&quot; event notifications. You can think of these timer events as time slices in which your asynchronous logic can execute. Since all Flash applications run in a single thread, you never need to worry about locking, mutexes, or semaphores, but you do need to be careful that any asynchronous function call does not take too long or the application will appear to hang or freeze. </p>
<p>&nbsp;</p>
<p><strong>No enum</strong></p>
<p>AS3 has no enum. This can make porting C/C++ code to ActionScript a little more work. The lack of an enum may also disrupt how someone versed in C/C++ would approach a problem. Some people have come up with dynamic runtime solutions. For example, <a href="http://www.darronschall.com/weblog/archives/000097.cfm">Darron Schall's EnumeratedType class</a> provides a single class that allows you to declare a new &quot;enum&quot; where ever needed. This is a nice, simple design that solves the runtime issues related to enums. It however does not catch errors at compile time (mismatched assignments or comparisons, etc.), because the AS3 language only has  primative types  for us to use which can accept any assignment. </p>
<p>Another approach could be as simple as defining a class with statics:</p>
<blockquote>
  <pre style="background-color:#CCCCCC; overflow: scroll;">public class MyEnum
{
	static public const FIRST:MyEnum = new MyEnum();
	static public const SECOND:MyEnum = new MyEnum();
	static public const THIRD:MyEnum = new MyEnum();

}</pre>
</blockquote><p>This class then could be used similar to enum definitions when assigning or comparing variables as such:
<blockquote>
  <pre style="background-color:#CCCCCC; overflow: scroll;">public function getValue() : MyEnum

{
    return MyEnum.SECOND;
}</pre></blockquote>
<p>This way requires you to create a new file/class for each enum, but it enforces type safety because you are passing the data around as a custom type.</p>
<p>&nbsp;</p>
<p><strong>Public class constructors and singleton objects</strong></p>
<p>In AS3, all class constructors must be public. This limitation is mainly due to the fact that ECMAscript 4 is not final and AS3 has chosen to abstain from protected/private constructors until it is resolved. But this limitation means is that AS3 does not have a  straight forward way of implementing <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton classes</a>. If the constructor must be public, anyone can create an instance of your class. However, there is a little trick you can use to implement a singleton class in AS3 that will ensure that is one and only one instance of your class.</p>
<p>In my previous <a href="http://blogs.adobe.com/kiwi/2006/05/as3_language_101_for_cc_coders_1.html">AS3/C++ article</a>,  the section &quot;Only one packaged class per file&quot; touched on an interesting nuance of AS3 that allows you to declare a class outside the package declaration. This class is only accessable to code within that file. We can use this to create an implementation of a singleton class.  The following code represents the contents of a file named "Singleton.as":</p>
<blockquote>
  <pre style="background-color:#CCCCCC; overflow: scroll;">package my.package
{
    public class Singleton
    {
         public function Singleton(blocker:SingletonBlocker)
         {
             if (blocker == null)
                 throw new Error("Public construction not allowed.  Use getInstance()");
         }
		 
         public static function getInstance() : Singleton
         {
             return instance;
         }
		 
         private var instance:Singleton = new Singleton(new SingletonBlocker());
    }
}

// Outside the package, declare the blocker class
class SingletonBlocker
{
}
</pre>
</blockquote>
<p>Since the "<tt>SingletonBlocker</tt>" class is outside the package declaration, other classes do not have access to it.  The public constructor of the Singleton class requires the &quot;<tt>blocker</tt>&quot; parameter, otherwise it throws an exception. The combination of these two controls prevents any code from outside this file from ever constructing a new &quot;<tt>Singleton</tt>&quot; object instance. The only way to obtain a valid instance is to call the static function &quot;<tt>getInstance()</tt>&quot;.</p>
<p>&nbsp; </p>]]>
    </content>
</entry>
<entry>
    <title>Dissecting a Mashup: NoteTag&apos;s Reusable Flex Components</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/05/dissecting_a_mashup_notetags_r.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1032" title="Dissecting a Mashup: NoteTag's Reusable Flex Components" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1032</id>
    
    <published>2006-05-26T19:30:00Z</published>
    <updated>2007-02-26T18:19:44Z</updated>
    
    <summary><![CDATA[Whenever I come across a new Flex 2.0 project, my first two questions are:
                               
                               &quot;How do I try it out?&quot;
                             &quot;Can I see the source?&quot;
                             
                           (Short answers: &quot;Go to the NoteTag Labs page!&quot; and &quot;Yes, go to the NoteTag Labs page!&quot;)&nbsp; After that, my next question is usually:
                           
                             Is there anything here I can reuse? 
                           
                           In NoteTag's case, the answer is a resounding &quot;Yes!&quot;&nbsp; Interested in publishing to a blog server that supports the Atom Publishing Protocol?&nbsp; Take a look at our AtomProtocol library.&nbsp; Interested in working with a read/write Feed object model that supports the various flavors of RSS and Atom?&nbsp; Try the Feeds library.&nbsp; In this post I'll give a brief overview of each reusable library that's included with NoteTag. ]]></summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="Components" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<p>Whenever I come across a new Flex 2.0 project, my first two questions are:</p>
                               <ul>
                               <li>&quot;How do I try it out?&quot;</li>
                             <li>&quot;Can I see the source?&quot;</li>
                             </ul>
                           <p>(Short answers: &quot;Go to the <a href="http://labs.adobe.com/wiki/index.php/NoteTag">NoteTag Labs page</a>!&quot; and &quot;Yes, go to the <a href="http://labs.adobe.com/wiki/index.php/NoteTag">NoteTag Labs page</a>!&quot;)&nbsp; After that, my next question is usually:</p>
                           <ul>
                             <li>Is there anything here I can reuse? </li>
                           </ul>
                           <p>In NoteTag's case, the answer is a resounding &quot;Yes!&quot;&nbsp; Interested in publishing to a blog server that supports the <a href="http://www.ietf.org/html.charters/atompub-charter.html">Atom Publishing Protocol</a>?&nbsp; Take a look at our AtomProtocol library.&nbsp; Interested in working with a read/write Feed object model that supports the various flavors of RSS and Atom?&nbsp; Try the Feeds library.&nbsp; In this post I'll give a brief overview of each reusable library that's included with NoteTag. </p><p>Below is a rough diagram of the NoteTag architecture.&nbsp; In future posts I'll talk about the NoteTag specific components, but today I'll focus on the lower part of the diagram.</p><p><br></p><p><img alt="notetag arch.jpg" src="http://blogs.adobe.com/kiwi/images/notetag%20arch.jpg" width="443" height="602" hspace="20" /></p><p>&nbsp;</p><p>From bottom to top:</p><p><strong>corelib</strong></p>
                             <p>The <a href="http://labs.adobe.com/wiki/index.php/ActionScript_3%3Aresources%3Aapis%3Alibraries#corelib">corelib</a> library is an ActionScript 3.0 library developed by the Adobe Developer Relations team, and made available on the <a href="http://labs.adobe.com/">Adobe Labs</a> site.&nbsp; The Kiwi team didn't develop this library, but we use it heavily (for  URI support, date parsing,and WSSE authentication), and I expect that most Flex developers will want to add it to their arsenal of tools. </p><p><strong>Connections</strong></p><p>The <a href="http://labs.adobe.com/wiki/index.php/NoteTag#Kiwi_Connections_Library">Connections</a> library provides basic support for connection management. Read/write web applications typically make calls to multiple web services, often authenticating with different credentials for each service -- NoteTag is a good example of this, using <a href="http://del.icio.us">del.icio.us</a> to store metadata relating to notes and tasks, and <a href="http://www.blogger.com">Blogger</a> or <a href="http://www.typepad.com">TypePad</a> to store the note content.&nbsp; The Connections library provides an object model for user-specific Connections to an Endpoint (e.g. Blogger) that supports a specific Protocol (e.g. the Atom Publishing Protocol). </p><p><strong>Feeds</strong></p><p>The <a href="http://labs.adobe.com/wiki/index.php/NoteTag#Kiwi_Feeds_Library">Feeds</a> library provides a format-independent Feed object model for Atom 0.3, Atom 1.0, RSS 1.0, and RSS 2.0.&nbsp; The Feeds library is similar in spirit to the existing RSS and Atom libraries, but provides a few key additions:</p>
                             <ul>
                               <li>support for Atom 0.3 (required by Blogger and TypePad)</li>
                             <li>support for reading from <em>and</em> writing to Feed objects</li>
                             <li>support for feed extensions</li>
                             </ul>
                           <p>Let's take a look at the second bullet point.&nbsp; Here's how you might create a new Atom 1.0 entry from scratch:</p><p><tt>// Create an empty entry.</tt></p><p><tt>var factory:IFeedElementFactory = new Atom10FeedFactory();</tt></p><p><tt>var entry:IEntry = factory.createEntry();</tt></p><p>&nbsp;</p><p><tt>// Assign a title to the entry.</tt></p><p><tt>var title:IContent = factory.createTitle();</tt></p><p><tt>title.value = &quot;My Latest Entry&quot;; // assign the content to the title </tt></p><p><tt>entry.title = title; // assign the title to the entry</tt></p><p>&nbsp;</p><p><tt>// Assign an id to the entry.</tt></p><p><tt>entry.id = &quot;id:1234567890&quot;;</tt></p><p>&nbsp;</p><p><tt>// The entry is being published &quot;right now&quot;.</tt></p><p><tt>entry.published = new Date();</tt></p><p>&nbsp;</p><p><tt>// Display the XML for the entry. </tt></p><p><tt>trace(entry.xml);</tt></p><p>What's nice about this approach is that you only have to change one of line of code if you're working with a different feed format:</p><p><tt>var factory:IFeedElementFactory = <strong>new RSS20FeedFactory();</strong> // switch to RSS2.0!</tt> </p><p><strong>TagServerProtocol</strong></p><p>The <a href="http://labs.adobe.com/wiki/index.php/NoteTag#Kiwi_TagServerProtocol_Library">TagServerProtocol</a> library provides a generic interface for a tag server protocol, and one specific implementation: <a href="http://del.icio.us">del.icio.us</a>.&nbsp; There are a variety of tag servers (more commonly referred to as social bookmarking services) out in the wild, most of which provide different flavors of the same API.&nbsp; The ITagServerProtocol interface is a &quot;least-common denominator&quot; interface that should work for most of these services.&nbsp; We'd love to see someone try to implement it for <a href="http://www.simpy.com">Simpy</a> or <a href="http://www.shadows.com/">Shadows</a> and then plug it in to NoteTag...</p><p><strong>AtomProtocol</strong></p><p>The AtomProtocol library provides a generic interface for the Atom Publishing Protocol, and two specific implementations: <a href="http://www.blogger.com">Blogger</a> and <a href="http://typepad.com">TypePad</a>.&nbsp; The protocol interface&nbsp; and introspection document object model conform as closely as possible to the <a href="http://www.ietf.org/internet-drafts/draft-ietf-atompub-protocol-08.txt">current draft (08)</a> of the APP specification, though there are some features (such as collection paging and media collections) which we punted on.&nbsp; Still, it ought to be possible to create a plugin for Google's <a href="http://code.google.com/apis/gdata/index.html">GData</a>]]>
        
    </content>
</entry>
<entry>
    <title>AS3 language 101 for C/C++ coders</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/05/as3_language_101_for_cc_coders.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1029" title="AS3 language 101 for C/C++ coders" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1029</id>
    
    <published>2006-05-25T23:30:52Z</published>
    <updated>2006-07-07T19:01:42Z</updated>
    
    <summary>This article covers aspects of ActionScript 3 that would be helpful to C/C++ application engineers transitioning to application development in Flex and Flash. I&apos;ve used C/C++ through most of my educational and professional career. I&apos;ve also done a respectable share...</summary>
    <author>
        <name>Darrick Brown</name>
        
    </author>
            <category term="ActionScript" />
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<p>This article covers aspects of ActionScript 3 that would be helpful to C/C++ application engineers transitioning to application development in Flex and Flash.</p>

<p>I've used C/C++ through most of my educational and professional career.  I've also done a respectable share of Javascript and Perl.  ActionScript 3 could be viewed as an interesting blend of features from all of these languages.  Actionscript 3 conforms to the ECMAscript 4 spec.  So, it is a standard languange.  In addition to the standard language syntax, AS3 contains a custom class framework for working with Flex/Flash.</p>

<p>The following are areas in the AS3 language that I personally found interesting.</p>]]>
        <![CDATA[<p><br/><strong>Type declarations</strong></p>

<p>Compared to C/C++, the first syntax oddity that you'll notice is how AS3 declares it's variable types. All type declarations are in post-fix notation. For example, in C you would define a function like:</p>

<blockquote style="background-color: #CCCCCC;"><code>int myFunction(char *str);</code></blockquote>

<p>In AS3 this same function declaration looks like:</p>

<blockquote style="background-color: #CCCCCC;"><code>function myFunction(str:String) : int</code></blockquote>
<p>&#160;</p>

<p><strong>Typecasting</strong></p>
<p>In AS3, think of typecasting like calling the constructor of the type.  Functionally, this isn't what happens, but the syntax is what it appears to be doing. </p>
<blockquote>
<table border="0">
<tr><td>In C:</td><td style="background-color: #CCCCCC;"><code>int i = (int)somefloat;</code></span></td>
</tr>
<tr><td>In AS3:&nbsp;&nbsp;&nbsp;</td><td style="background-color: #CCCCCC;"><code>var i:int = int(somefloat);</code></td>
</tr>
</table>
</blockquote>

<p>If you see what appears to be something calling the constructor of a class or type but it does not use "new", it's not calling a constructor.  It's performing a typecast.  For example:</p>

<blockquote style="background-color: #CCCCCC;"><code>
var foo:SomeClass = SomeClass(someObject);<br />
var bar:SomeClass = new SomeClass(someObject);
</code></blockquote>

<p>The first line is typecasting "someObject" into SomeClass.  The second line is creating a new SomeClass object, passing "someObject" as a parameter to the constructor.  This subtle difference can have wide ranging effects (new object vs. reusing an existing object, etc.).&nbsp; Depending on what the class constructor takes as a parameter, it is possible that both the typecast and the constructor would compile with no errors/warnings in all situations.&nbsp; So, be careful.&nbsp; The difference between a typecast and a new object is just the &quot;new&quot; keyword.</p>

<p>&nbsp;</p>
<p><strong>Variable scope</strong></p>

<p>Variables are scoped to the function. ActionScript employs a system called &quot;variable hoisting&quot;, which implicitly pulls all variable declarations in the function (even ones in nested blocks) to the top of the function at compile time.&nbsp; For example:</p>

<blockquote style="background-color: #CCCCCC;">
<pre>public function doSomething() : void
{
    var foo:int = 4;
    
    if (foo)
    {
        var bar:int = 2;
    }
}</pre></blockquote>

<p>With viable hoisting,  all declared variables in a function are moved to the top of the function block at compile time. In the above example, the compile time result looks like:</p>

<blockquote style="background-color: #CCCCCC;">
<pre>public function doSomething() : void
{
    var foo:int;
    var bar:int;

    foo = 4;
    
    if (foo)
    {
        bar = 2;
    }
}</pre></blockquote>

<p>Note that the &quot;bar&quot; variable is now in scope for the entire function.&nbsp; This subtle variable handling in AS3 may lead to unintended situations since any use of the &quot;bar&quot; variable before the &quot;if(foo)&quot; block is now valid, even though it is not declared until inside the if() block.&nbsp; AS3 will complain if you declare the same variable more than once in the same function, but it won't complain if you use a variable before it's declared.</p>

<p><br/><strong>void * </strong></p>

<p>In AS3, you can use the wild card type to mimic the &quot;void *&quot; type.&nbsp; For example, say you have a factory object that can return objects of many types.&nbsp; This can be implemented as such:</p>

<blockquote style="background-color: #CCCCCC;">
<pre>public function wildcard() : void
{
    var anything:* = ObjectFactory.getData();
}</pre></blockquote>

<p><br/><strong>Run time type checking</strong></p>

<p>Since you can pass things around as anything using the wildcard type (void *), you need a way to check the type of the object at runtime.  To do this, you can use the "<code>is</code>" directive:</p>

<blockquote style="background-color: #CCCCCC;">
<pre>public function doSomething() : void
{
    var something:* = getData();

    if (something is String)
    {
        // handle string logic
    }
    else
    {
       // do something else
    }
}</pre></blockquote>

<p>This allows for runtime type checking which allows your application to perform different logic depending on what the given object is.</p>

<p><br/><strong>No function overloading</strong></p>

<p>There is no function overloading in AS3.  However, you can implement a system that mimics function overloading.  For example, in C++ you might have some function definitions like: </p>

<blockquote style="background-color: #CCCCCC;">
<pre>int doSomething(int i);
int doSomething(char *str);</pre></blockquote>

<p>In AS3, you can't overload a function, but the language allows you to make use of the type wildcard "<code>*</code>" and use the &quot;is&quot; directive as a way of performing runtime checks and branching based on what was passed in.  For example:</p>

<blockquote style="background-color: #CCCCCC;">
<pre>function doSomething(obj:*) : int
{
    if (obj is int)
        // do int stuff
    else if (obj is String)
        // do string stuff
    else
        // what type did you give me?<br />
}</pre></blockquote>

<p><br/><strong>No operator overloading</strong></p>

<p>AS3 has no way to override the meaning of "+", "=", or any other operator.  The closest functionality is the get/set member accessors that you can declare to handle the getting and assignment of class members.</p>

<p><br/><strong>Everything is an object</strong> </p>

<p>All types within AS3 are derived classes of the base class "Object".  Even if a class does not "extend Object", it still does.  This means when you pass anything to a function, you are passing that data by reference (pointer) in all cases.  If the called function modifies the object you passed, your version of the data will be modified as well. </p>

<p>However, there are some exceptions.  Basic types like int, Number, and String are objects as well, but their implementation performs reference counting  to make them behave like stack objects.  If the called function simply assigns  new values to variables of these basic types, the data in the caller function does not get modified.</p>

<p><br/><strong>Only one packaged class per file</strong></p>

<p>When implementing AS3 classes, you can only have one class definition per package declaration per AS file. For example:</p>

<blockquote>
<table width="100%">
<tr><td><p>MyClass.as</p></td></tr>
<tr><td><pre  style="background-color: #CCCCCC;">package my.class.package
{
    public class MyClass
    {
        public function MyClass()
        {
             ...
        }
    }
}</pre></td></tr>
<tr><td><p style="text-align: center">Fig. 1</p></td></tr></table></blockquote>

<blockquote>
<table width="100%">
<tr><td><p>MyClass.as</p></td></tr>
<tr><td><pre  style="background-color: #CCCCCC;">package my.class.package
{
    public class MyClass
    {
        public function MyClass()
        {
             ...
        }
    }
}

class MyPrivateClass
{
    public function MyPrivateClass()
    {
         ...
    }
}</pre></td></tr>
<tr><td><p style="text-align: center">Fig. 2</p></td></tr></table></blockquote>

<blockquote>
<table width="100%">
<tr><td><p>MyClass.as</p></td></tr>
<tr><td><pre  style="background-color: #CCCCCC;">package my.class.package
{
    public class MyClass
    {
        public function MyClass()
        {
             ...
        }
    }

    public class AnotherClass
    {
        public function AnotherClass
        {
              ...
        }
    }
}</pre></td></tr>
<tr><td><p style="text-align: center">Fig. 3</p></td></tr></table></blockquote>

<p>Fig. 1 and 2 are valid in AS3.  Fig. 3 is not valid.  AS3 does not allow you to have more than one class inside a package declaration and you can only have one package declaration per file. The interesting thing to note is that the "PrivateClass" in Fig. 2 is only accessable to code inside that file.  Outside that file, the "PrivateClass" is an unknown type.  You can use the construct in Fig. 2 to hide implementation classes from the rest of the world.</p>

<p>Being limited to one public class per file may not be a huge problem, but it may come as a logistical hurdle if you are expecting to define multiple classes within the same file.  Plan your file structure accordingly.</p> 

<p><br/><strong>virtual functions</strong></p>

<p>The major difference between AS3 and C++ when it comes to inherited functions is the fact that the functions in a derived class do not override the base class functions unless you declare a method as "<code>override</code>".  Without this declaration, the base class version of the function will be called in all cases.</p>

<p>You can think of this as almost the opposite of C++'s "virtual" declaration.  In C++, once a function is declared virtual, that function is automatically virtual for all derived classes regardless if the derived class declares it as virtual.  In AS3, the derived class controls what functions are "virtual" (overridden).</p>

<p><br/><strong>dynamic_cast</strong></p>

<p> In AS3, you will find yourself dealing with interfaces.  These are similar in concept to abstract base classes in C++.  Objects that implement an interface will be passed around as instances of that interface.  So, given an object of a specific interface, how do you get the object as an instance of its subclass?  You use the "<code>as</code>" functionality.  For example:</p>

<blockquote style="background-color: #CCCCCC;">
<pre>var someInterface:ISomeInterface = factory.getSomeInterface();
var someClass:SomeClass = (someInterface as SomeClass);</pre></blockquote>

<p>If &quot;someInterface&quot; is actually an instance of &quot;SomeClass&quot; or a derived class of &quot;SomeClass&quot;, the variable &quot;someClass&quot; will be a reference to that object.&nbsp; If &quot;someInterface&quot; is an instance of some other class, the &quot;someClass&quot; variable will be null.</p>

<p><br/><strong>Raw character strings</strong></p>

<p>AS3 has a primative string type named "String".  You can access the characters of the string and do things with them, but what if you want access to the raw ASCII or UTF8 bytes?  The easiest way to do this is via the ByteArray() class.  You can write a string into a ByteArray object and then pull it back out as raw bytes.</p>

<p>&nbsp;</p>
<p>Well, I hope this is useful to anyone making the transition to Flex/ActionScript from C/C++.  If you have any questions, found an error in my assessment, or just want to say something, please leave a comment.  We're trying to make Flex development as easy as possible for everyone and any feedback is much appreciated.</p>

<p>Thanks!</p>]]>
    </content>
</entry>
<entry>
    <title>An Overview of NoteTag</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/05/an_overview_of_notetag_1.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1028" title="An Overview of NoteTag" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1028</id>
    
    <published>2006-05-25T20:51:28Z</published>
    <updated>2007-02-26T18:21:23Z</updated>
    
    <summary>The Kiwi team is focused on enabling developers to build read/write web components in Flex and Apollo. NoteTag is a proof-of-concept Flex 2.0 application which offers a solution to a common problem: how to keep track of tasks while taking...</summary>
    <author>
        <name>Brian Riggs</name>
        
    </author>
            <category term="General" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[The Kiwi team is focused on enabling developers to build read/write web components in Flex and Apollo. <a href="http://labs.adobe.com/wiki/index.php/NoteTag">NoteTag</a> is a proof-of-concept Flex 2.0 application which offers a solution to a common problem: how to keep track of tasks while taking notes for a meeting. <p>Let's jump straight into the user experience. I'm in a meeting with my Kiwi cohorts, and I'm in charge of note-taking duties. I launch my browser, navigate to the NoteTag URL, and immediately start taking notes.</p><p><a href="http://blogs.adobe.com/kiwi/images/01_notetag_note.jpg"><img src="http://blogs.adobe.com/kiwi/01_notetag_note_001.jpg" width="440" height="328" hspace="20" /></a></p><p>After the usual status round-robin, Darrick points out that there's a bug which he needs to investigate further. Aha! We have our first task! I highlight the text of the task (&quot;Need to locate RichTextEditor source&quot;) and click the &quot;Tag as Task&quot; button on the control bar. The task's text now changes to red, and the property inspector at the bottom of the screen is pre-populated with values. I set the owner to &quot;darrick&quot; and continue taking notes.</p><p><a href="http://blogs.adobe.com/kiwi/images/02_notetag_tagged_task.jpg"><img src="http://blogs.adobe.com/kiwi/02_notetag_tagged_task.jpg" width="440" height="328" hspace="20" /></a></p><p>When the meeting ends I click &quot;Publish&quot;, and the note and tasks are posted to our backend. (More on that later.) If I want, I can browse through the previously-posted meeting notes in an RSS aggregator-like view...</p><p><a href="http://blogs.adobe.com/kiwi/images/03_notetag_published_note.jpg"><img src="http://blogs.adobe.com/kiwi/03_notetag_published_note.jpg" width="440" height="327" hspace="20" /></a></p><p>.. but most likely, I'm done. Darrick, on the other hand, has some work to do. He connects to NoteTag and clicks on &quot;My Tasks&quot; to see his aggregated list of tasks. If the text of the task alone doesn't provide the context he needs, he can click on the task to see the enclosing note.</p><p><a href="http://blogs.adobe.com/kiwi/images/04_notetag_task.jpg"><img src="http://blogs.adobe.com/kiwi/04_notetag_task.jpg" width="440" height="327" hspace="20" /></a></p><p>After Darrick has finished his investigation, he needs to mark the task as completed. He checks the box next to the Task, and the task instantly turns from red to green in the note.</p><a href="http://blogs.adobe.com/kiwi/images/05_notetag_task_update.jpg"><p><img src="http://blogs.adobe.com/kiwi/05_notetag_task_update.jpg" width="440" height="331" hspace="20" /></a></p><p>This is more than just a local change: anyone who views either the note or Darrick's list of tasks will see that the task has been finished.</p><p><a href="http://blogs.adobe.com/kiwi/images/06_notetag_updated_note.jpg"><img src="http://blogs.adobe.com/kiwi/06_notetag_updated_note.jpg" width="440" height="328" hspace="20" /></a></p><p>At this point you might be thinking, &quot;I've seen plenty of applications that help people keep track of tasks. What's unique about NoteTag?&quot; Two things...</p><p>First, NoteTag is a completely free, completely open-source Flex 2.0 application. Want to figure out how we're aggregating tasks? Just dive in to the source code. Want to see how we're publishing notes to the web? It's all there. Want to use our source code in your application?  Help yourself! NoteTag should be a great resource for developers who are ramping up on Flex, and who want to understand how to build an app that involves more than a handful of classes.</p><p>The other unique thing about NoteTag is the backend: there is none! (Well, none that we wrote, at least.) Here's where the notes are stored:</p><p><a href="http://blogs.adobe.com/kiwi/images/07_blogger.jpg"><img src="http://blogs.adobe.com/kiwi/07_blogger.jpg" width="440" height="508" hspace="20" /></a></p><p><a href="http://www.blogger.com">Blogger</a>! (NoteTag also supports <a href="http://www.typepad.com">TypePad</a>, and theoretically could use any service that supports the <a href="http://www.ietf.org/html.charters/atompub-charter.html">Atom Publishing Protocol</a>.)</p><p>And here's where we store references to the notes and tasks:</p><p><a href="http://blogs.adobe.com/kiwi/images/08_delicious.jpg"><img src="http://blogs.adobe.com/kiwi/08_delicious.jpg" width="440" height="203" hspace="20" /></a></p><p><a href="http://del.icio.us">Delicious</a>! Every note and task is tagged with information about the author, owner, status, etc., and points to the URL of the note on the blog server.</p><p>What this means is that NoteTag doesn't replace existing workflows and services, it <i>complements</i> them. You can view your tasks in NoteTag, or you can log into your delicious account and use delicious's support for filters, related tags, and tag clouds to view them in new and interesting ways.</p><p>All that being said -- we on the Kiwi project think NoteTag will be less interesting as an end-user product and more interesting as an application that developers can use to learn how to build their own read/write web applications in Flex. In the next post, I'll talk about the overall design and architecture of NoteTag, as well as the reusable components that we've developed.<br> </p>]]>
        
    </content>
</entry>
<entry>
    <title>Introductions</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/kiwi/2006/05/introductions.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=54/entry_id=1019" title="Introductions" />
    <id>tag:blogs.adobe.com,2006:/kiwi//54.1019</id>
    
    <published>2006-05-24T17:38:40Z</published>
    <updated>2006-05-24T17:41:42Z</updated>
    
    <summary>File under: adobe,flex,apollo,kiwi,web2.0,rss,atom,delicious Hello everyone, and welcome to the Kiwi Project blog. As our tag line says, the Kiwi Project is focused on creating read/write web components for Flex.&amp;#160;What does this mean?&amp;#160;Over the last year or so the Web 2.0...</summary>
    <author>
        <name></name>
        
    </author>
            <category term="General" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/kiwi/">
        <![CDATA[<!-- #BeginTags --><p class="tags">File under: <a href="http://www.technorati.com/tag/adobe" rel="tag">adobe</a>,<a href="http://www.technorati.com/tag/flex" rel="tag">flex</a>,<a href="http://www.technorati.com/tag/apollo" rel="tag">apollo</a>,<a href="http://www.technorati.com/tag/kiwi" rel="tag">kiwi</a>,<a href="http://www.technorati.com/tag/web2.0" rel="tag">web2.0</a>,<a href="http://www.technorati.com/tag/rss" rel="tag">rss</a>,<a href="http://www.technorati.com/tag/atom" rel="tag">atom</a>,<a href="http://www.technorati.com/tag/delicious" rel="tag">delicious</a></p><!-- #EndTags -->
                           <p>Hello everyone, and welcome to the Kiwi Project blog. As our tag line says, the Kiwi Project is focused on creating read/write web components for Flex.&#160;What does this mean?&#160;</p><p>Over the last year or so the Web 2.0 meme has grown phenomenally.&#160; While <a href="http://en.wikipedia.org/wiki/Web_2.0">the definition of  Web 2.0 has been hotly debated</a>, people are starting to focus on a fundamental attribute…</p>
						   <blockquote cite="http://blogs.sun.com/roller/page/stern"> <p><a href="http://blogs.sun.com/roller/page/stern?entry=web_2_0_in_three"> Hal Stern: The Morning Snowman : Weblog </a></p>Everything that <a href="http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html">Tim O'Reilly posits as Web 2.0 examples</a> is distinguished from a Web 1.0 counterpoint as being writeable. Three words: read-write web.

</blockquote>
<p>We couldn't agree more.&#160; In fact, from (the &quot;new&quot;) Adobe's perspective, we've been promoting the read/write web for years thru our <a href="http://www.adobe.com/products/contribute/">Contribute</a> product, which is both an HTML browser and a WYSIWYG HTML editor all in one  application.</p><p>With the rising interest in <a href="http://adaptivepath.com/publications/essays/archives/000385.php">AJAX</a> and <a href="http://en.wikipedia.org/wiki/Rich_Internet_Application">RIAs</a>, it became important for us to understand how to empower our <a href="http://www.adobe.com/products/flex/">Flex</a> environment to create read/write web applications. This means developing Flex components that understand  specific Web 2.0 technologies such as RSS, blogging, tagging, and  microformats. And with <a href="http://news.com.com/Flash+to+jump+beyond+the+browser/2100-1007_3-6071005.html?tag=nefd.lede">hints of Apollo emerging</a>, this means understanding how to build Flex components that work both in the browser and on the desktop.</p><p>Thus the Kiwi Project was born.&#160; The team is comprised of engineers who have been involved with the development of both <a href="http://www.adobe.com/products/dreamweaver/">Dreamweaver</a> and <a href="http://www.adobe.com/products/contribute/">Contribute</a>, who are intimitely familiar with the challenges of read/write web applications. &#160; The team also has experience in both desktop and web development, but like many of us at this time, is new to Flex development.&#160; This blog will chronicle our experiences in mastering Flex and our progress in exploring and developing  that set of read/write web components for Flex developers. </p><p>Our first proof-of-concept release is just around the corner…</p>]]>
        
    </content>
</entry>

</feed> 

