<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Clockwork Objects</title><link>http://clockobj.co.uk</link><description>User Experience &amp; Web Design and Development</description><language>en</language><lastBuildDate>Thu, 18 Jun 2009 16:01:35 PDT</lastBuildDate><generator>http://wordpress.org/?v=2.8</generator><sy:updatePeriod xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">hourly</sy:updatePeriod><sy:updateFrequency xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">1</sy:updateFrequency><geo:lat>50.2638</geo:lat><geo:long>-5.059</geo:long><image><link>http://clockobj.co.uk/</link><url>http://clockobj.co.uk/images/cwo-mid.png</url><title>Clockwork Objects</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/miletbaker" type="application/rss+xml" /><feedburner:emailServiceId>miletbaker</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><title>Scale-9 in Objective-C Cocoa on the Mac</title><link>http://feedproxy.google.com/~r/miletbaker/~3/B3o-nVkN7jg/</link><category>Objective-C and Cocoa</category><category>Cocoa</category><category>Objective-C</category><category>Scale9</category><category>UI Design</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Thu, 18 Jun 2009 15:49:35 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=297</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Having used flash extensively for the last few years I have really come to rely on using Scale-9 scaling on UI elements in the rich internet apps I design and develop. It is a great technique for things like rounded rectangles, button graphics etc and ensuring the rounded corners do not distort when stretched.</p>
<p>I have recently been doing Cocoa Development on Mac OS X 10.5 and was looking for a way to do this in Cocoa and <a href="http://www.karlkraft.com/index.php/2007/11/14/nsdrawninepartimage/">came across</a> a great drawing method named <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Miscellaneous/AppKit_Functions/Reference/reference.html">NSDrawNinePartImage</a>. The method has the following signature:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">void</span> NSDrawNinePartImage<span style="color: #002200;">&#40;</span><span style="color: #a61390;">NSRect</span> frame,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>topLeftCorner,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>topEdgeFill,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>topRightCorner,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>leftEdgeFill,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>centerFill,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>rightEdgeFill,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>bottomLeftCorner,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>bottomEdgeFill,
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>bottomRightCorner,
   NSCompositingOperation op,
   CGFloat alphaFraction,
   <span style="color: #a61390;">BOOL</span> flipped
<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p><span id="more-297"></span><br />
This method requires the developer to provide 9 separate images to create the 9 sections of the scale 9 image. Luckily the article I had stumbled across had a handy example for using a single class, so I thought that I would use their technique to create a simple generic class that can be used to draw a single NSImage as a Scale-9 scalable image. This could be used for example in an NSView or NSButtonCell.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  GTDrawImage.m</span>
<span style="color: #11740a; font-style: italic;">//  StretchMyView</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Jon Baker on 17/06/2009.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 Go Tripod Ltd. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;GTDrawImage.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> GTDrawImage
&nbsp;
&nbsp;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> drawScalableImage<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sourceImage scaleTopLeft<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">NSPoint</span><span style="color: #002200;">&#41;</span>topLeftPoint scaleBottomRight<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">NSPoint</span><span style="color: #002200;">&#41;</span>bottomRightPoint inFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">NSRect</span><span style="color: #002200;">&#41;</span>frame 
<span style="color: #002200;">&#123;</span>
	NSSize sourceSize <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>sourceImage size<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Top left</span>
	<span style="color: #a61390;">NSRect</span> topLeftTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, topLeftPoint.x, sourceSize.height <span style="color: #002200;">-</span> topLeftPoint.y<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> topLeftCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, topLeftPoint.y, topLeftTileRect.size.width, topLeftTileRect.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// TopRight</span>
	<span style="color: #a61390;">NSRect</span> topRightTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>, sourceSize.width <span style="color: #002200;">-</span> bottomRightPoint.x, topLeftTileRect.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> topRightCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span>sourceSize.width <span style="color: #002200;">-</span> topRightTileRect.size.width, topLeftPoint.y, topRightTileRect.size.width, topRightTileRect.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Top</span>
	<span style="color: #a61390;">NSRect</span> topTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, sourceSize.width <span style="color: #002200;">-</span> topLeftTileRect.size.width <span style="color: #002200;">-</span> topRightTileRect.size.width, topLeftTileRect.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> topCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span>topLeftPoint.x, topLeftPoint.y, topTileRect.size.width, topTileRect.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Bottom Left</span>
	<span style="color: #a61390;">NSRect</span> bottomLeftTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, topLeftCutRect.size.width, bottomRightPoint.y<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> bottomLeftCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, bottomLeftTileRect.size.width, bottomLeftTileRect.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Bottom Right</span>
	<span style="color: #a61390;">NSRect</span> bottomRightTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>, topRightCutRect.size.width, bottomLeftTileRect.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> bottomRightCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span>topRightCutRect.origin.x, <span style="color: #2400d9;">0</span>, bottomRightTileRect.size.width , bottomRightTileRect.size.height <span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Bottom</span>
	<span style="color: #a61390;">NSRect</span> bottomTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>, topTileRect.size.width, bottomLeftTileRect.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> bottomCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span>topCutRect.origin.x, <span style="color: #2400d9;">0</span>, bottomTileRect.size.width, bottomTileRect.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// left</span>
&nbsp;
	<span style="color: #a61390;">NSRect</span> leftTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, bottomLeftTileRect.size.width, sourceSize.height <span style="color: #002200;">-</span> topTileRect.size.height <span style="color: #002200;">-</span> bottomTileRect.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> leftCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, bottomRightPoint.y, leftTileRect.size.width, leftTileRect.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// right</span>
&nbsp;
	<span style="color: #a61390;">NSRect</span> rightTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, topRightCutRect.size.width, leftCutRect.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> rightCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span>bottomRightPoint.x, bottomRightPoint.y, rightTileRect.size.width, rightTileRect.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//center</span>
	<span style="color: #a61390;">NSRect</span> centerTileRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, topTileRect.size.width, leftTileRect.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">NSRect</span> centerCutRect <span style="color: #002200;">=</span> NSMakeRect<span style="color: #002200;">&#40;</span>topCutRect.origin.x, bottomRightPoint.y, centerTileRect.size.width, centerTileRect.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>topLeft <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>topLeftTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>topLeft lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>topLeftTileRect fromRect<span style="color: #002200;">:</span>topLeftCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>topLeft unlockFocus<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>top <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>topTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>top lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>topTileRect fromRect<span style="color: #002200;">:</span>topCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>top unlockFocus<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>topRight <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>topRightTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>topRight lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>topRightTileRect fromRect<span style="color: #002200;">:</span>topRightCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>topRight unlockFocus<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//setup center section, left, right</span>
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>left <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>leftTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>left lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>leftTileRect fromRect<span style="color: #002200;">:</span>leftCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>left unlockFocus<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>center <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>centerTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>center lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>centerTileRect fromRect<span style="color: #002200;">:</span>centerCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>center unlockFocus<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>right <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>rightTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>right lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>rightTileRect fromRect<span style="color: #002200;">:</span>rightCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>right unlockFocus<span style="color: #002200;">&#93;</span>;	
&nbsp;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>bottomLeft <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>bottomLeftTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottomLeft lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>bottomLeftTileRect fromRect<span style="color: #002200;">:</span>bottomLeftCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottomLeft unlockFocus<span style="color: #002200;">&#93;</span>;		
&nbsp;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>bottom <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>bottomTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottom lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>bottomTileRect fromRect<span style="color: #002200;">:</span>bottomCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottom unlockFocus<span style="color: #002200;">&#93;</span>;		
&nbsp;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>bottomRight <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>bottomRightTileRect.size<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottomRight lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sourceImage drawInRect<span style="color: #002200;">:</span>bottomRightTileRect fromRect<span style="color: #002200;">:</span>bottomRightCutRect operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottomRight unlockFocus<span style="color: #002200;">&#93;</span>;
&nbsp;
&nbsp;
	NSDrawNinePartImage<span style="color: #002200;">&#40;</span>
						frame, 
						topLeft, top, topRight,
						left, center, right,
						bottomLeft, bottom, bottomRight,
						NSCompositeSourceOver, <span style="color: #2400d9;">1.0</span>, <span style="color: #a61390;">NO</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>topLeft release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>top release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>topRight release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>left release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>center release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>right release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottomLeft release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottom release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>bottomRight release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>To use this generic classes, you simply need to import it where required:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;GTDrawImage.h&quot;</span></pre></div></div>

<p>&#8230;and then you can call from within, for example the drawRect:, selector using the following method:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">NSRect</span><span style="color: #002200;">&#41;</span>rect <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>GTDrawImage drawScalableImage<span style="color: #002200;">:</span>baseImage scaleTopLeft<span style="color: #002200;">:</span>NSMakePoint<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">8</span>, <span style="color: #2400d9;">16</span><span style="color: #002200;">&#41;</span> scaleBottomRight<span style="color: #002200;">:</span>NSMakePoint<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">16</span>,<span style="color: #2400d9;">8</span><span style="color: #002200;">&#41;</span> inFrame<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>self bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>drawScalableImage takes an NSImage, in this case baseImage, and two reference points (NSPoint) to split the image into nine slices, firstly the scaleTopLeft: and secondly the scaleBottomRight:, both located from the bottom left corner. So for example to split a 24px x 24px image into 9 equal 8px by 8px segments (see below), the topLeftPoint would be x=8px, y=16px and the bottom x=16 and y=8.</p>
<p><img class="s3-img" src="http://clockobj.co.uk.s3.amazonaws.com/scale9.png" border="0" alt="scale9.png" /></p>
<p>Just download the following classes into your projects and away you go:</p>
<ul>
<li>Header: <a class="s3-link" href="http://clockobj.co.uk.s3.amazonaws.com/GTDrawImage.h">GTDrawImage.h</a></li>
<li>Implementation: <a class="s3-link" href="http://clockobj.co.uk.s3.amazonaws.com/GTDrawImage.m">GTDrawImage.m</a></li>
<li>Sample Project using GTDrawImage: <a class="s3-link" href="http://clockobj.co.uk.s3.amazonaws.com/StretchMyView.zip">StretchMyView.zip</a> (Adapted example I found. Unfortunately I can&#8217;t remember where and so don&#8217;t know who to credit)</li>
</ul>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/miletbaker?a=B3o-nVkN7jg:mG-_58F3qY4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=B3o-nVkN7jg:mG-_58F3qY4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=B3o-nVkN7jg:mG-_58F3qY4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=B3o-nVkN7jg:mG-_58F3qY4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=B3o-nVkN7jg:mG-_58F3qY4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=B3o-nVkN7jg:mG-_58F3qY4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=B3o-nVkN7jg:mG-_58F3qY4:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=B3o-nVkN7jg:mG-_58F3qY4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=B3o-nVkN7jg:mG-_58F3qY4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=B3o-nVkN7jg:mG-_58F3qY4:XAVGb8Xj5zA"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=XAVGb8Xj5zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/B3o-nVkN7jg" height="1" width="1"/>]]></content:encoded><description>Having used flash extensively for the last few years I have really come to rely on using Scale-9 scaling on UI elements in the rich internet apps I design and develop. It is a great technique for things like rounded rectangles, button graphics etc and ensuring the rounded corners do not distort when stretched.
I have [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2009/06/18/scale-9-in-objective-c-cocoa-on-the-mac/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">1</slash:comments><feedburner:origLink>http://clockobj.co.uk/2009/06/18/scale-9-in-objective-c-cocoa-on-the-mac/</feedburner:origLink></item><item><title>Great 404 Page Idea</title><link>http://feedproxy.google.com/~r/miletbaker/~3/D_83eggI0dc/</link><category>Entrepreneurship</category><category>Usability</category><category>404</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Thu, 18 Jun 2009 02:53:23 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=273</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I came across <a href="http://www.hogbaysoftware.com/book/">a great 404 page</a> the other day and thought I would share it. The page at first glances looks like any other but if you read the text, you will see that they have redeemed themselves for the broken link by offering me a discount of $3 off any of their products.</p>
<p><img class="s3-img" style="border: 0px initial initial;" src="http://clockobj.co.uk.s3.amazonaws.com/Picture 1.png" border="0" alt="Picture 1.png" width="477" height="439" /></p>
<p>This is a great way to capture the interest of would be browsers that would normally see this page and immediately hit the back key, instead not only do they capture my attention, but they also tap into my curiosity which gets me to immediately click the products link.</p>
<p>In this case I didn&#8217;t need any of their products but this is a great tip.</p>
<p>Also note the search bar being visible. This is essential on a 404 page for keeping customers that know what they are looking for on your site.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/miletbaker?a=D_83eggI0dc:CZ3-x_5p12g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=D_83eggI0dc:CZ3-x_5p12g:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=D_83eggI0dc:CZ3-x_5p12g:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=D_83eggI0dc:CZ3-x_5p12g:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=D_83eggI0dc:CZ3-x_5p12g:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=D_83eggI0dc:CZ3-x_5p12g:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=D_83eggI0dc:CZ3-x_5p12g:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=D_83eggI0dc:CZ3-x_5p12g:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=D_83eggI0dc:CZ3-x_5p12g:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=D_83eggI0dc:CZ3-x_5p12g:XAVGb8Xj5zA"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=XAVGb8Xj5zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/D_83eggI0dc" height="1" width="1"/>]]></content:encoded><description>I came across a great 404 page the other day and thought I would share it. The page at first glances looks like any other but if you read the text, you will see that they have redeemed themselves for the broken link by offering me a discount of $3 off any of their products.

This [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2009/06/18/great-404-page-idea/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments><feedburner:origLink>http://clockobj.co.uk/2009/06/18/great-404-page-idea/</feedburner:origLink></item><item><title>Review: iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod Touch</title><link>http://feedproxy.google.com/~r/miletbaker/~3/rRGpu-0Ll_Q/</link><category>Objective-C and Cocoa</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Sun, 01 Mar 2009 11:55:59 PST</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=245</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p><a href="http://www.amazon.co.uk/gp/product/0470742828/ref=cm_cr_rev_prod_title"><img class="float_left" style="margin-left: 10px; margin-right: 10px;" title="iPhone Development" src="http://ecx.images-amazon.com/images/I/51TiKTlPq2L._SL500_AA240_.jpg" alt="" width="192" height="192" /></a>Maher&#8217;s Book is an in-depth reference into the world of iPhone application development aimed at both beginners and experienced Objective-C / Cocoa developers alike</p>
<p>The book is concise and more theoretical than many of the others I have read on the subject and covers everything you need to know to get started. One of the best things about this book is the depth it goes into many of the topics. For example, the book goes into great detail about consuming RESTful web services and parsing XML and makes use of real-world Web APIs such as Google Maps API for these examples. The book also provides a good insight into using the local file system and creating and working with local sqlite3 databases as well as several concise chapters on creating views and working with pretty much every control. Unfortunately the book lacks any coverage of Interface Builder (this may partly be down to when the book was written and what features were available at the time of writing) which provides in many cases quicker and easier solutions to creating views and handling events. I feel the example views shown in the various screen shots have suffered because of this.</p>
<p>Overall this book serves as an excellent reference, going into more depth in the programatic theory than many of the other books, and is certainly good value and just over £20.</p>
<p><a href="http://www.amazon.co.uk/gp/product/0470742828/ref=cm_cr_rev_prod_title">This book is available via Amazon.co.uk</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/miletbaker?a=rRGpu-0Ll_Q:OL3eW0bcuQ0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=rRGpu-0Ll_Q:OL3eW0bcuQ0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=rRGpu-0Ll_Q:OL3eW0bcuQ0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=rRGpu-0Ll_Q:OL3eW0bcuQ0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=rRGpu-0Ll_Q:OL3eW0bcuQ0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=rRGpu-0Ll_Q:OL3eW0bcuQ0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=rRGpu-0Ll_Q:OL3eW0bcuQ0:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=rRGpu-0Ll_Q:OL3eW0bcuQ0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/miletbaker?i=rRGpu-0Ll_Q:OL3eW0bcuQ0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/miletbaker?a=rRGpu-0Ll_Q:OL3eW0bcuQ0:XAVGb8Xj5zA"><img src="http://feeds.feedburner.com/~ff/miletbaker?d=XAVGb8Xj5zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/rRGpu-0Ll_Q" height="1" width="1"/>]]></content:encoded><description>Maher&amp;#8217;s Book is an in-depth reference into the world of iPhone application development aimed at both beginners and experienced Objective-C / Cocoa developers alike
The book is concise and more theoretical than many of the others I have read on the subject and covers everything you need to know to get started. One of the best [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2009/03/01/review-iphone-sdk-programming-developing-mobile-applications-for-apple-iphone-and-ipod-touch/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">0</slash:comments><feedburner:origLink>http://clockobj.co.uk/2009/03/01/review-iphone-sdk-programming-developing-mobile-applications-for-apple-iphone-and-ipod-touch/</feedburner:origLink></item><item><title>Mate Framework for Adobe Flex</title><link>http://feedproxy.google.com/~r/miletbaker/~3/YjkG1O8Pz-E/</link><category>Flex and Air</category><category>as3</category><category>Mate</category><category>RIA</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Wed, 03 Dec 2008 15:30:35 PST</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=219</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p><a href="http://clockobj.co.uk/wp-content/uploads/2008/12/banner_mate2.jpg"><img class="alignnone size-medium wp-image-220" title="banner_mate2" src="http://clockobj.co.uk/wp-content/uploads/2008/12/banner_mate2-300x69.jpg" alt="" width="300" height="69" /></a></p>
<p>I just wanted to share with you a great framework I have been using recently called <a href="http://mate.asfusion.com/">Mate</a> (pronounced ma-tay).</p>
<p>Developed by the guys at <a href="http://www.asfusion.com/">ASFusion</a> Mate is a great framework that features MXML declared event handling, dependency injection and best of all it is really easy to use and implement (It even has a way of reusing your existing Cairngorm commands. Additionally in the next version there will be an infrastructure for mocking out your services and really provides a clean architecture for Flex apps.</p>
<p>The framework is provided as a .swc file you can drop straight into your /libs folder and supports both Flex 2 and Flex 3. The only downside to the framework is the <a href="http://mate.asfusion.com/page/documentation">documentation</a> does not reflect the latest .swc and is a little light in places, however the <a href="http://mate.asfusion.com/forums/">forums</a> are excellent and very active and there is a good selection of <a href="http://mate.asfusion.com/page/examples">examples</a>.</p>
<p>I will be blogging about this in more details soon, but wanted to share my initial thoughts and urge you to look at this framework as it is really worth it.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=PgTtdLjp"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=g9lY3ceM"><img src="http://feeds.feedburner.com/~f/miletbaker?i=g9lY3ceM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=jBGnIzJw"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=nJVHnUQf"><img src="http://feeds.feedburner.com/~f/miletbaker?i=nJVHnUQf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=KcmuFJbw"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=Z8SoqbHA"><img src="http://feeds.feedburner.com/~f/miletbaker?i=Z8SoqbHA" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=HVXIloA8"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/YjkG1O8Pz-E" height="1" width="1"/>]]></content:encoded><description>I just wanted to share with you a great framework I have been using recently called Mate (pronounced ma-tay).
Developed by the guys at ASFusion Mate is a great framework that features MXML declared event handling, dependency injection and best of all it is really easy to use and implement (It even has a way of [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/12/03/mate-framework-for-adobe-flex/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">4</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/12/03/mate-framework-for-adobe-flex/</feedburner:origLink></item><item><title>Rails deployment is so easy these days</title><link>http://feedproxy.google.com/~r/miletbaker/~3/0UXyfR3ZkLs/</link><category>Ruby on Rails</category><category>Apache</category><category>Phusion Passenger</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Sat, 22 Nov 2008 04:04:16 PST</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=196</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p><a href="http://clockobj.co.uk/wp-content/uploads/2008/11/enterprise_logo_alpha.png"><img class="float_left alignleft size-full wp-image-214" style="margin: 5px;" title="enterprise_logo_alpha" src="http://clockobj.co.uk/wp-content/uploads/2008/11/enterprise_logo_alpha.png" alt="" width="261" height="68" /></a>I have been meaning to blog about Phusion Passenger for a while as about 3-4 months ago we migrated Stubmatic from using Apache / Mongrel Cluster to <a href="http://www.modrails.com/">Phusion Passenger A.K.A. mod_rails</a>.<br />
<span id="more-196"></span><br />
Mod rails is extreamly easy to install. Make sure you update gem first:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem update <span style="color: #660033;">--system</span></pre></div></div>

<p>Then install the Phusion Passenger gem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> passenger</pre></div></div>

<p>Once complete you can run the Phusion Passenger install that compiles mod_rails for you.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">passenger-install-apache2-module</pre></div></div>

<p>Once this completes it will give you some code to past into your httpd.conf file and you are ready to start configuring your sites.. Well actually if you have been using Mongrels then time to strip most of the configuration out of your https.conf file. You can have as simple a configuration as shown below. <strong>Note:</strong> The DocumentRoot should be set to the public folder within your app. Passenger automatically detects that this is a rails app.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    ServerName www.stubmatic.com
    DocumentRoot /websites/stubmatic/public</pre></div></div>

<p>One thing to note is that by default Passenger disables ModRewrite for that VirtualHost and in our case we use ModRewrite for a number of things such as providing a Maintenance page when maintenance.html is in our public folder allowing us to take the app offline. We also use ModRewrite to hide .svn folders, so we needed to use ModRewrite. Thankfully Passenger provides a solution. <strong>Note: You must first make sure you remove the .htaccess file in your rails public folder!</strong></p>
<p>So our new Apache configuration looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    ServerName www.stubmatic.com
    DocumentRoot /websites/stubmatic/public
&nbsp;
    RailsAllowModRewrite on
&nbsp;
    RewriteEngine On
&nbsp;
    RewriteRule ^(.*/)?.svn/ - [F,L]
&nbsp;
    RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /maintenance.html [L]</pre></div></div>

<p>If you want to setup an Apache / Phusion Passenger testing server you will also need to add the following directive to your VirtualHost configuration:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">RailsEnv development</pre></div></div>

<p>As you can see Phusion Passenger make deployment of Ruby on Rails as trivial as deploying a PHP. You can easily reload Phusion Passenger by running the following command from within your Rails project root.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">touch tmp/restart.txt</pre></div></div>

<p>In terms of performance, Phusion Passenger holds it&#8217;s own against Mongrel and there are <a href="http://www.modrails.com/documentation.html">plenty of details on Phusion&#8217;s website</a>.</p>
<p>For more information:</p>
<ol>
<li><a href="http://www.modrails.com/">Phusion Passenger</a></li>
<li><a href="http://www.modrails.com/documentation/Users%20guide.html">Phusion Passenger Documentation</a></li>
</ol>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=jN5uUJLO"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=xidNR64h"><img src="http://feeds.feedburner.com/~f/miletbaker?i=xidNR64h" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=PxmC4UDR"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=ZDKXQDir"><img src="http://feeds.feedburner.com/~f/miletbaker?i=ZDKXQDir" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=jzOpfRG9"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=VPuZiJaI"><img src="http://feeds.feedburner.com/~f/miletbaker?i=VPuZiJaI" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=aHrNqoOO"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/0UXyfR3ZkLs" height="1" width="1"/>]]></content:encoded><description>I have been meaning to blog about Phusion Passenger for a while as about 3-4 months ago we migrated Stubmatic from using Apache / Mongrel Cluster to Phusion Passenger A.K.A. mod_rails.

Mod rails is extreamly easy to install. Make sure you update gem first:

gem update --system

Then install the Phusion Passenger gem

gem install passenger

Once complete you can [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/11/22/rails-deployment-is-so-easy-these-days/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">0</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/11/22/rails-deployment-is-so-easy-these-days/</feedburner:origLink></item><item><title>Excellent OS X SQLite 3 Management &amp; Query App</title><link>http://feedproxy.google.com/~r/miletbaker/~3/8WZm3v6NudA/</link><category>Flex and Air</category><category>Objective-C and Cocoa</category><category>Python Django</category><category>Ruby on Rails</category><category>Adobe Air</category><category>iPhone</category><category>sqlite 3</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Thu, 20 Nov 2008 12:11:50 PST</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=190</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<dl id="attachment_191" class="wp-caption alignnone" style="width: 138px;">
<dt class="wp-caption-dt"><a href="http://clockobj.co.uk/wp-content/uploads/2008/11/baseicon.png"><img class="size-medium wp-image-191 alignnone float_left" title="baseicon" src="http://clockobj.co.uk/wp-content/uploads/2008/11/baseicon.png" alt="Base Icon" width="102" height="102" /></a></dt>
</dl>
<p>iPhone and Adobe Air developers (as well as any others that use SQLite 3) <a href="http://menial.co.uk">Menial</a> has just released an excellent little app for creating, managing and running queries against SQLite 3 databases called Bases.</p>
<p><a href="http://clockobj.co.uk/wp-content/uploads/2008/11/schema1.png"><img class="alignnone size-full wp-image-193" title="schema1" src="http://clockobj.co.uk/wp-content/uploads/2008/11/schema1.png" alt="" width="500" height="424" /></a></p>
<p>The application is simple to use, very user friendly and has worked well from the testing I have done. It costs just £10 and there is a free trial available so you can try before you buy.</p>
<p><a href="http://menial.co.uk/software/base/">Find out more and download here</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=77zQgRlv"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=w8tKq7Ug"><img src="http://feeds.feedburner.com/~f/miletbaker?i=w8tKq7Ug" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=94bUV5pA"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=oC90uZp0"><img src="http://feeds.feedburner.com/~f/miletbaker?i=oC90uZp0" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=cVuBqSLu"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=FUeDnnvo"><img src="http://feeds.feedburner.com/~f/miletbaker?i=FUeDnnvo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=H6Fhav4V"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/8WZm3v6NudA" height="1" width="1"/>]]></content:encoded><description>iPhone and Adobe Air developers (as well as any others that use SQLite 3) Menial has just released an excellent little app for creating, managing and running queries against SQLite 3 databases called Bases.

The application is simple to use, very user friendly and has worked well from the testing I have done. It costs just [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/11/20/excellent-os-x-sqlite-3-management-query-app/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">1</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/11/20/excellent-os-x-sqlite-3-management-query-app/</feedburner:origLink></item><item><title>Creating a two-way binding between Model and Form in Flex</title><link>http://feedproxy.google.com/~r/miletbaker/~3/TpvucT7Jeo8/</link><category>Flex and Air</category><category>ActionScript</category><category>AIR</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Mon, 20 Oct 2008 16:56:18 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=172</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>A quick sorry to all my Flex readership for the lack of Flex related posts these last few months. I though I would drop a quick tip / class I often use to create a two way binding between a form to a corresponding class model.<br />
<span id="more-172"></span><br />
Flex provides a one way binding through its &lt;mx:Binding&gt; tags, if you are unfamiliar with this tag check out the <a href="http://www.adobe.com/devnet/flex/quickstart/using_data_binding/#section3">section on them in Adobe&#8217;s Flex quick start guide</a>. However if you want changes made to the model reflected in the form as well as changes made to the form reflected back in the model you need to set up two way bindings. To simplify this I have created a helper class (listed below) which then allows me to establish a two way binding.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.vibrant.components.Forms
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">DisplayObject</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.binding.utils.BindingUtils;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.binding.utils.ChangeWatcher;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ModelBinding
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _modelWatcher		<span style="color: #000000; font-weight: bold;">:</span> ChangeWatcher;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _componentWatcher		<span style="color: #000000; font-weight: bold;">:</span> ChangeWatcher;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> bindingsAreEstablished	<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ModelBinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Property field
		 * @default null
		 */</span>	
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _model <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Object</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> model<span style="color: #000000;">&#40;</span> <span style="color: #004993;">value</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Object</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_model = <span style="color: #004993;">value</span>;
			updateBinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> model<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Object</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> _model;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Property field, field within model to bind
		 * @default &quot;&quot;
		 */</span>		
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _field<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> field<span style="color: #000000;">&#40;</span> <span style="color: #004993;">value</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_field = <span style="color: #004993;">value</span>;
			updateBinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> field<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> _field;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Property: target, component to tartget binding from model to.
		 */</span>		
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _target <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Object</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">target</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">value</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Object</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_target = <span style="color: #004993;">value</span>;
			updateBinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">target</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Object</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> _target;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Property: property, to bind to on target component
		 */</span>		
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _property <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;text&quot;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> property<span style="color: #000000;">&#40;</span> <span style="color: #004993;">value</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_property = <span style="color: #004993;">value</span>;
			updateBinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> property<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> _property;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * @private
		 * Updates bindings between component and model
		 *
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> updateBinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> bindingsAreEstablished <span style="color: #000000;">&#41;</span> clearBindings<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> model <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>  model.<span style="color: #004993;">hasOwnProperty</span><span style="color: #000000;">&#40;</span> field <span style="color: #000000;">&#41;</span>
				<span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #004993;">target</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #004993;">target</span>.<span style="color: #004993;">hasOwnProperty</span><span style="color: #000000;">&#40;</span> property <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				_modelWatcher = BindingUtils.bindProperty<span style="color: #000000;">&#40;</span> <span style="color: #004993;">target</span>, property, model, field <span style="color: #000000;">&#41;</span>;
				_componentWatcher = BindingUtils.bindProperty<span style="color: #000000;">&#40;</span> model, field, <span style="color: #004993;">target</span>, property <span style="color: #000000;">&#41;</span>;
				bindingsAreEstablished = <span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Clears bindings
		 *
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> clearBindings<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> _modelWatcher <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				_modelWatcher.unwatch<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				_modelWatcher = <span style="color: #0033ff; font-weight: bold;">null</span>;
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> _componentWatcher <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				_componentWatcher.unwatch<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				_componentWatcher = <span style="color: #0033ff; font-weight: bold;">null</span>;
			<span style="color: #000000;">&#125;</span>
			bindingsAreEstablished = <span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This class basically takes a model class, that has the data you would like to setup the bindings with in. The field name, the name of the property within the model class to bind to. A target, the form component to establish the view side binding with and finally you can specify an optional property that the binding should be made to on the form element. If unspecified, the &#8216;property&#8217; defaults to &#8220;text&#8221; as this is the most often used property to bind to. So for example given the following User model:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> UserModel
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> firstName <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> lastName <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> UserModel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>We could set up a binding to a TextInput as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">...
&lt;mx:Script&gt;
	&lt;![CDATA[
		public var userModel : UserModel;
	]]&gt;
&lt;/mx:Script&gt;
&lt;mx:Form&gt;
	&lt;mx:FormItem label=&quot;First Name&quot;&gt;
		&lt;mx:TextInput id=&quot;txtFirstName&quot;/&gt;
	&lt;/mx:FormItem&gt;
&lt;/mx:Form&gt;
&lt;ModelBinding model=&quot;{userModel}&quot; field=&quot;firstName&quot; target=&quot;{txtFirstName}&quot;/&gt;
...</pre></td></tr></table></div>

<p>As you can see with this class you can quickly setup two-way bindings with your models.</p>
<p><a href='http://clockobj.co.uk/wp-content/uploads/2008/10/modelbinding.as'>Download ModelBinding.as</a><br />
For more information on Binding, <a href="http://www.adobe.com/devnet/flex/quickstart/using_data_binding">check out Adobe Devnet</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=7aNa4bY0"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=nu5dJLq0"><img src="http://feeds.feedburner.com/~f/miletbaker?i=nu5dJLq0" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=PFAnWZIy"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=uoqSWw3R"><img src="http://feeds.feedburner.com/~f/miletbaker?i=uoqSWw3R" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=z1fCXbq9"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=a26lCBh0"><img src="http://feeds.feedburner.com/~f/miletbaker?i=a26lCBh0" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=QOpgSXGv"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/TpvucT7Jeo8" height="1" width="1"/>]]></content:encoded><description>A quick sorry to all my Flex readership for the lack of Flex related posts these last few months. I though I would drop a quick tip / class I often use to create a two way binding between a form to a corresponding class model.

Flex provides a one way binding through its &amp;#60;mx:Binding&amp;#62; tags, [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/10/20/creating-a-two-way-binding-between-model-and-form-in-flex/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">14</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/10/20/creating-a-two-way-binding-between-model-and-form-in-flex/</feedburner:origLink></item><item><title>Please Help Me Win Carsonified’s Golden Ticket…</title><link>http://feedproxy.google.com/~r/miletbaker/~3/Mzq0h6-WW10/</link><category>Misc..</category><category>Technology Rants and Raves</category><category>carsonified</category><category>Web Design</category><category>web development</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Mon, 15 Sep 2008 04:43:51 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=150</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p><img class="alignright float_right" style="border: 1px solid black; margin-left: 2px; margin-right: 2px;" title="Carsonifieds Golden Ticket" src="http://img.skitch.com/20080915-bhbwsxbnfpacgemgjed3bmdxee.jpg" alt="" width="376" height="241" />I am a big fan of <a href="http://www.carsonified.com/about-us">Ryan Carson</a> and the guys over at <a href="http://carsonified.com/">Carsonified</a>. They have just announced a competition to send one person to all of Carsonified&#8217;s events for 2009. To win, all one needs to do is post a blog entry (this) <a href="http://carsonified.com/events/carsonified-golden-ticket">linking back to Carsonified&#8217;s competition post</a> and then get 25 comments. So, if you are a regular reader (or your first time here) and would like to help keep me up to date on what is happening in the world of web apps, design etc as well as send me on some Carsonified workshops, then please add a comment supporting me to <span style="text-decoration: line-through;">that</span> this post. If i win I promise to share my knowledge gained on here.</p>
<p>Also, if you are a blogger yourself and entering this competition, please comment so below and I will return the favour and add a comment to your blog post entry.</p>
<p>Thanks in advance to all those that comment..!</p>
<p>Regards,</p>
<p>Jon</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=SMpfc6ue"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=aCgEQtCT"><img src="http://feeds.feedburner.com/~f/miletbaker?i=aCgEQtCT" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=iJdM5kdr"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=fGkHK5Lw"><img src="http://feeds.feedburner.com/~f/miletbaker?i=fGkHK5Lw" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=lOkOxj5S"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=CZX8VkPc"><img src="http://feeds.feedburner.com/~f/miletbaker?i=CZX8VkPc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=11TD1xz8"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/Mzq0h6-WW10" height="1" width="1"/>]]></content:encoded><description>I am a big fan of Ryan Carson and the guys over at Carsonified. They have just announced a competition to send one person to all of Carsonified&amp;#8217;s events for 2009. To win, all one needs to do is post a blog entry (this) linking back to Carsonified&amp;#8217;s competition post and then get 25 comments. [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/09/15/please-help-me-win-carsonified-golden-ticket/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">27</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/09/15/please-help-me-win-carsonified-golden-ticket/</feedburner:origLink></item><item><title>Cashbackguide.org helps UK customers save money online</title><link>http://feedproxy.google.com/~r/miletbaker/~3/zi9SJxiCIhk/</link><category>Technology Rants and Raves</category><category>cash back</category><category>plugins</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Mon, 08 Sep 2008 03:03:13 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=89</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p><a href="http://www.cashbackguide.org/"><img class="alignright float_right size-medium wp-image-137" style="border: 1px solid black; margin-left: 5px; margin-right: 5px;" title="CashBack Guardian" src="http://clockobj.co.uk/wp-content/uploads/2008/09/1-300x218.png" alt="" width="270" height="196" /></a>I just wanted to drop a quick post to my UK readership about <a href="http://www.cashbackguide.org/">CashBackGuide</a> a great site I found the other day. I have recently got into using Cash Back sites when making online purchases. The concept is a simple one, these site are registered as affiliates with the online stores you use and by visiting them before you make a purchase, they get an affiliate fee for redirecting you to make the purchase. Rather than keep this fee, they pass it on to you (taking a very small cut themselves). <a href="http://www.cashbackguide.org/">Cashbackguide</a> offers a really nice clean interface that allows you to enter a retailer and check who offers cash back for that retailer, for example you could <a href="http://www.cashbackguide.org/retailer+offers.aspx?SiteId=-536719718">search for Amazon.co.uk</a> and it will return a list of Cash Back sites that provide cash back, and how much they offer.</p>
<p>But this is not the killer feature! &#8211; The guys over at Cashbackguide have created <a href="http://www.cashbackguide.org/downloads.aspx">plugins for both Firefox and IE called Cashback Guardian</a> and basically if you visit an online store that has a cash back scheme, it will notify you before making a purchase and notifying you how much cash back you could get.</p>
<p>I think this is a great use of technology that helps save a few pennies and well worth a look.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=Jkbz84l4"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=l2qfzUfa"><img src="http://feeds.feedburner.com/~f/miletbaker?i=l2qfzUfa" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=6loK1SWE"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=JOPgikUa"><img src="http://feeds.feedburner.com/~f/miletbaker?i=JOPgikUa" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=886Dnq7L"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=kjaua1Bd"><img src="http://feeds.feedburner.com/~f/miletbaker?i=kjaua1Bd" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=bzfzeoFq"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/zi9SJxiCIhk" height="1" width="1"/>]]></content:encoded><description>I just wanted to drop a quick post to my UK readership about CashBackGuide a great site I found the other day. I have recently got into using Cash Back sites when making online purchases. The concept is a simple one, these site are registered as affiliates with the online stores you use and by [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/09/08/cashbackguideorg-helps-uk-customers-save-money-online/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/09/08/cashbackguideorg-helps-uk-customers-save-money-online/</feedburner:origLink></item><item><title>Ruby on Rails, PayPal Express Recurring Payments using Active Merchant</title><link>http://feedproxy.google.com/~r/miletbaker/~3/WxDwPijiR0M/</link><category>Ruby on Rails</category><category>PayPal</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Mon, 08 Sep 2008 02:31:52 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=128</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I recently needed to setup recurring payments through PayPal&#8217;s express checkout for a subscription based site I have writen using Ruby on Rails. There is already an excellent framework for interacting with most payment gateways, including PayPal, for Ruby called <a href="http://www.activemerchant.org/">Active Merchant</a>. Unfortunately recurring payments support in Active Merchant for PayPal Express Checkout is limited to a <a href="http://jadedpixel.lighthouseapp.com/projects/11599-active-merchant/tickets/17-patch-creating-paypal-recurring-payments-profile-with-activemerchant#ticket-17-4">script pasted into their lighthous bug tracking system</a>. The trouble is that this script only covers creating subscription profiles and also later getting details of that profile, but I needed to be able to suspend and cancel subscriptions profiles as well as make changes to the subscription from my site.</p>
<p><span id="more-128"></span></p>
<p><strong>**** UPDATE: ActiveMerchant recently removed the functionality to use PayPal&#8217;s NVP API and so this code will no longer work with the latest ActiveMerchant. Raymond Law has kindly ported the code to use the SOAP API and <a href="http://rayvinly.com/articles/2009/02/20/paypal-recurring-billing-with-activemerchant-in-ruby-on-rails/">you can find out more information and usage on his blog</a>. ****</strong></p>
<p>Active Merchant is very easy to extend so I have written a Ruby class that can be dropped into /vendor/plugins/active_merchant/billing/gateways/ within your Rails project (assuming you have AM installed as a plugin)</p>
<p>Below is the code: (I have also attached the .rb file: <a href="http://clockobj.co.uk/wp-content/uploads/2008/09/paypal_express_recurring_nv.rb">paypal_express_recurring_nv.rb</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># simple extension to ActiveMerchant for basic support of recurring payments with Express Checkout API</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># See http://http://clockobj.co.uk/2008/09/07/ruby-on-rails-paypal-express-recurring-payments-using-active-merchant/</span>
<span style="color:#008000; font-style:italic;"># for details on getting started with this gateway</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#9966CC; font-weight:bold;">module</span> ActiveMerchant <span style="color:#008000; font-style:italic;">#:nodoc:</span>
  <span style="color:#9966CC; font-weight:bold;">module</span> Billing <span style="color:#008000; font-style:italic;">#:nodoc:</span>
    <span style="color:#9966CC; font-weight:bold;">class</span> PaypalExpressRecurringNvGateway <span style="color:#006600; font-weight:bold;">&amp;</span>lt; Gateway
      <span style="color:#9966CC; font-weight:bold;">include</span> PaypalNvCommonAPI
&nbsp;
      LIVE_REDIRECT_URL = <span style="color:#996600;">'https://www.paypal.com/cgibin/webscr?cmd=_customer-billing-agreement&amp;amp;token='</span>
      TEST_REDIRECT_URL = <span style="color:#996600;">'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_customer-billing-agreement&amp;amp;token='</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> redirect_url
        test? ? TEST_REDIRECT_URL : LIVE_REDIRECT_URL
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> redirect_url_for<span style="color:#006600; font-weight:bold;">&#40;</span>token<span style="color:#006600; font-weight:bold;">&#41;</span>
          <span style="color:#996600;">&quot;#{redirect_url}#{token}&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> setup_agreement<span style="color:#006600; font-weight:bold;">&#40;</span>description, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        requires!<span style="color:#006600; font-weight:bold;">&#40;</span>options, <span style="color:#ff3333; font-weight:bold;">:return_url</span>, <span style="color:#ff3333; font-weight:bold;">:cancel_return_url</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        commit <span style="color:#996600;">'SetCustomerBillingAgreement'</span>, build_setup_agreement<span style="color:#006600; font-weight:bold;">&#40;</span>description, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> get_agreement<span style="color:#006600; font-weight:bold;">&#40;</span>token<span style="color:#006600; font-weight:bold;">&#41;</span>
        commit <span style="color:#996600;">'GetBillingAgreementCustomerDetails'</span>, build_get_agreement<span style="color:#006600; font-weight:bold;">&#40;</span>token<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> create_profile<span style="color:#006600; font-weight:bold;">&#40;</span>money, token, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        commit <span style="color:#996600;">'CreateRecurringPaymentsProfile'</span>, build_create_profile<span style="color:#006600; font-weight:bold;">&#40;</span>money, token, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> get_profile_details<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id<span style="color:#006600; font-weight:bold;">&#41;</span>
        commit <span style="color:#996600;">'GetRecurringPaymentsProfileDetails'</span>, build_get_profile_details<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> manage_profile<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, action, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        commit <span style="color:#996600;">'ManageRecurringPaymentsProfileStatus'</span>, build_manage_profile<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, action, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> update_profile<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        commit <span style="color:#996600;">'UpdateRecurringPaymentsProfile'</span>, build_update_profile<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> bill_outstanding<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, money, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        commit <span style="color:#996600;">'BillOutstandingAmount'</span>, build_bill_outstanding<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, money, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      private
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> build_setup_agreement<span style="color:#006600; font-weight:bold;">&#40;</span>description, options<span style="color:#006600; font-weight:bold;">&#41;</span>
        post = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:billingagreementdescription</span>, description<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:returnurl</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:return_url</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:cancelurl</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:cancel_return_url</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:billingtype</span>, <span style="color:#996600;">&quot;RecurringPayments&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:paymenttype</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:payment_type</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:payment_type</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:localecode</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:locale</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:locale</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:billingagreementcustom</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:custom_code</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:custom_code</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        post
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> build_get_agreement<span style="color:#006600; font-weight:bold;">&#40;</span>token<span style="color:#006600; font-weight:bold;">&#41;</span>
        post = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:token</span>, token<span style="color:#006600; font-weight:bold;">&#41;</span>
        post
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> build_create_profile<span style="color:#006600; font-weight:bold;">&#40;</span>money, token, options<span style="color:#006600; font-weight:bold;">&#41;</span>
        post = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:token</span>, token<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_amount<span style="color:#006600; font-weight:bold;">&#40;</span>post, money, options<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:subscribername</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:subscriber_name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:subscriber_name</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:initamt</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:initamt</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:initamt</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:failedinitamtaction</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:failedinitamtaction</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span>  options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:failedinitamtaction</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:profilestartdate</span>, <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">utc</span>.<span style="color:#9900CC;">iso8601</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:billingperiod</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:billing_period</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:billing_period</span><span style="color:#006600; font-weight:bold;">&#93;</span> : <span style="color:#996600;">&quot;Month&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:billingfrequency</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:billing_frequency</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:billing_frequency</span><span style="color:#006600; font-weight:bold;">&#93;</span> : <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:totalbillingcycles</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:billing_cycles</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:billing_cycles</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:profilereference</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:reference</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:reference</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:autobillamt</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:auto_bill_amt</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:auto_bill_amt</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:maxfailedpayments</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:max_failed_payments</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:max_failed_payments</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:shippingamt</span>, amount<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:shipping_amount</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:shipping_amount</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:taxamt</span>, amount<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tax_amount</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tax_amount</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_shipping_address<span style="color:#006600; font-weight:bold;">&#40;</span>post, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:shipping_address</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:shipping_address</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        post
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> build_get_profile_details<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id<span style="color:#006600; font-weight:bold;">&#41;</span>
        post = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:profileid</span>, profile_id<span style="color:#006600; font-weight:bold;">&#41;</span>
        post
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> build_manage_profile<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, action, options<span style="color:#006600; font-weight:bold;">&#41;</span>
        post = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:profileid</span>, profile_id<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:action</span>, action<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:note</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:note</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:note</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        post
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> build_update_profile<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, options<span style="color:#006600; font-weight:bold;">&#41;</span>
        post = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:profileid</span>, profile_id<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:note</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:note</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:note</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:desc</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:description</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:description</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:subscribername</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:subscriber_name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:subscriber_name</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:profilereference</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:reference</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:reference</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:additionalbillingcycles</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:additional_billing_cycles</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:additional_billing_cycles</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_amount<span style="color:#006600; font-weight:bold;">&#40;</span>post, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:money</span><span style="color:#006600; font-weight:bold;">&#93;</span>, options<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:shippingamt</span>, amount<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:shipping_amount</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:shipping_amount</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:autobillamt</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:auto_bill_amt</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:auto_bill_amt</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:maxfailedpayments</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:max_failed_payments</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:max_failed_payments</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:taxamt</span>, amount<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tax_amount</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tax_amount</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        add_shipping_address<span style="color:#006600; font-weight:bold;">&#40;</span>post, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:shipping_address</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:shipping_address</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        post
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> build_bill_outstanding<span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, money, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        post = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:profileid</span>, profile_id<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_amount<span style="color:#006600; font-weight:bold;">&#40;</span>post, money, options<span style="color:#006600; font-weight:bold;">&#41;</span>
        add_pair<span style="color:#006600; font-weight:bold;">&#40;</span>post, <span style="color:#ff3333; font-weight:bold;">:note</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:note</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:note</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        post
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> build_response<span style="color:#006600; font-weight:bold;">&#40;</span>success, message, response, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        PaypalExpressNvResponse.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>success, message, response, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>With this class installed using Active Merchant to set up a subscription / recurring payment through PayPal Express Checkout is easy. Firstly setup your gateway object:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">gw = <span style="color:#6666ff; font-weight:bold;">ActiveMerchant::Billing::PaypalExpressRecurringNvGateway</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:login</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'PAYPALEMAIL'</span>, <span style="color:#ff3333; font-weight:bold;">:password</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'PASSWORD'</span>, <span style="color:#ff3333; font-weight:bold;">:signature</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'PAYPALAPISIGNATURE'</span> <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Then make a request to PayPal to setup the recurring payment. At this stage you pass through a description (which is what is shown to the user when they are asked to authorise the subscription so make it descriptive) and you also need to provide URLs on your site, that PayPal should redirect the subscriber back to when they either complete the payment, or alternatively if they choose to cancel.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">response = gw.<span style="color:#9900CC;">setup_agreement</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Subscription £25 per month&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:cancel_return_url</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;https://mysite.com/cancel&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:return_url</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;https://mysite.com/complete&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>The request above returns us a token in the response from paypal and at this point we need to redirect the user to PayPal to authorise this subscription. The user will see the description &#8220;Subscription £25 per month&#8221; as sent in the previous request. We need to redirect the subscriber to PayPal using the following line of ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">redirect_to gw.<span style="color:#9900CC;">redirect_url_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>response.<span style="color:#9900CC;">token</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Once the user has authorised the subscription they are returned to the :return_url we specified earlier, at which point we can create the actual subscription using the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">response = gw.<span style="color:#9900CC;">create_profile</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2500</span>, response.<span style="color:#9900CC;">token</span>, <span style="color:#ff3333; font-weight:bold;">:currency</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;GBP&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:reference</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;34&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Note: PayPal are really confusing having one API for the US and another for the UK but if you are using PayPal Express (which is free) independently of PayPal Website Payments Pro (Which you need to pay for) the US PayPal Express API works for all countries (apart from Germany I believe) and as you can see above I am passing in the UK currency. I am using the US API and I have a UK PayPal account. Also note that I have passed in a reference (I have an IPN URL setup in my PayPal account &#8211; Unfortunately you cannot pass an IPN URL with the request) to be sent in the IPN.</p>
<p>The previous step completes the set up of our Subscription. However if we need to later get information on the subscription or change it, we need to extract the Profile ID from the response as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">profile_id = response.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;profileid&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>With this profile_id we can then later use these additional methods that I have included, such as getting details of the subscription profile using:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">gw.<span style="color:#9900CC;">get_profile_details</span><span style="color:#006600; font-weight:bold;">&#40;</span>profile_id<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Update the subscription using various options (i.e. changing subscription amount shown below):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">gw.<span style="color:#9900CC;">update_profile</span><span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, <span style="color:#ff3333; font-weight:bold;">:money</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">3000</span>, <span style="color:#ff3333; font-weight:bold;">:currency</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;GBP&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Manage the subscription, for example cancel it as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">gw.<span style="color:#9900CC;">manage_profile</span><span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, <span style="color:#996600;">&quot;Cancel&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:note</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;Your subscription has been cancelled by us&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>And finally bill any outstanding subscription balance:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">gw.<span style="color:#9900CC;">bill_outstanding</span><span style="color:#006600; font-weight:bold;">&#40;</span>profile_id, <span style="color:#006666;">2500</span>, <span style="color:#ff3333; font-weight:bold;">:currency</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;GBP&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:note</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;£20 Overdue Subscription&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Please note that as of yet this class is not part of Active Merchant, however it has been added to <a href="http://jadedpixel.lighthouseapp.com/projects/11599-active-merchant/tickets/17-patch-creating-paypal-recurring-payments-profile-with-activemerchant#ticket-17-4">Active Merchants case #17</a> If you want to use this you will have to add it manually as above.</p>
<p>I recommend reading <a href="https://www.paypal.com/en_US/pdf/PP_ExpressCheckout_IntegrationGuide.pdf">PayPals Express Checkout Integration Guide</a> and the <a href="https://www.paypal.com/en_US/pdf/PP_NVPAPI_DeveloperGuide.pdf">Name Value Pair API Developer Guide and Reference</a> for more information on what variables can be passed in each request to PayPal.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=uoLMJLtU"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=ynadIeQW"><img src="http://feeds.feedburner.com/~f/miletbaker?i=ynadIeQW" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=SxyTqC3y"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=whDsmFYB"><img src="http://feeds.feedburner.com/~f/miletbaker?i=whDsmFYB" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=qhOVXcnD"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=WrmsObLn"><img src="http://feeds.feedburner.com/~f/miletbaker?i=WrmsObLn" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=pYcpZyHj"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/WxDwPijiR0M" height="1" width="1"/>]]></content:encoded><description>I recently needed to setup recurring payments through PayPal&amp;#8217;s express checkout for a subscription based site I have writen using Ruby on Rails. There is already an excellent framework for interacting with most payment gateways, including PayPal, for Ruby called Active Merchant. Unfortunately recurring payments support in Active Merchant for PayPal Express Checkout is limited [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/09/08/ruby-on-rails-paypal-express-recurring-payments-using-active-merchant/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">37</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/09/08/ruby-on-rails-paypal-express-recurring-payments-using-active-merchant/</feedburner:origLink></item><item><title>Objective-J &amp; Cappuccino</title><link>http://feedproxy.google.com/~r/miletbaker/~3/I1nbF92yWFM/</link><category>Javascript</category><category>Misc..</category><category>Objective-C and Cocoa</category><category>Technology Rants and Raves</category><category>AJAX</category><category>Cocoa</category><category>Objective-C</category><category>RIA</category><category>web development</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Sun, 07 Sep 2008 05:32:47 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=113</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p><a href="http://cappuccino.org/"><img class="float_right alignright" style="border: 1px solid black; margin-left: 5px; margin-right: 5px;" title="Cappuccino Framework" src="http://cappuccino.org/images/cappuccino-icon.png" alt="" width="180" height="180" /></a>This may be an unusual first post in my Objective-C and Cocoa categories however it is quite relevant as the guys behind <a href="http://280slides.com/">280 Slides</a> have released a <a href="http://cappuccino.org/">new open source extension</a> to the Javascript language known as Objective-J and a new Javascript framework based on Cocoa named Cappuccino.</p>
<p>Other than having a very nice logo designed by the guys at <a href="http://madebysofa.com/">Sofa</a> my first impressions are they have implemented Objective-C in javascript. To me this seems an unusual choice as I can&#8217;t image there are that many developers (within the web development industry) who are that familiar with Objective-C. Maybe I am wrong, certainly with the current gold rush to develop for the iPhone this will increase. I must admit I have been toying with Objective-C recently and once I got the hang of the syntax am really starting to enjoy it. So maybe there is method to their madness?<span id="more-113"></span></p>
<p>The <a href="http://cappuccino.org/">Cappuccino framework</a> has been likened to the recently released (and overhyped in my opinion &#8211; seems slow and clunky to me) <a href="http://www.sproutcore.com/">SproutCore</a> framework. However I am extreamly impressed with how quick <a href="http://280slides.com/">280 Slides</a> responds to user interactions and in addition to this the set of controls provided with Cappuccino have a nicer OS X quality to them.</p>
<p>My personal opinion is that the future of Rich Internet Applications does not lie with Javascript (though I am biased to Flex). It is not that I dislike Javascript, quite the oposite in fact. My reservations mainly lie in Javascript relying too heavily on the HTML DOM and is at the mercy of browsers and their stakeholders (for which there are too many). One of the nices things with technologies such as Flex and Silverlight is the cross browser consistency. Not only this but also the many rich media features such as image manipulation &amp; processing, the ability to do advanced animation including 3D animation, video features etc. which to me put the Rich in Rich Internet Applications.</p>
<p>I may well eat my words as two major players in the form of Apple and Google are backing Javascript as the future standard for RIA development. Google&#8217;s <a href="http://www.google.com/chrome">Chrome</a> browser addresses some of the performance and stability issues and Apple has recently based it&#8217;s online MobileMe business on Javascript (aparently using <a href="http://www.sproutcore.com/">SpoutCore</a>) as well as introducing new extensions to Javascript such as the Canvas tag that help overcome some of Javascripts shortfalls.</p>
<p>One thing is sure I take my hat off to these guys for pushing the boundaries of Javascript and in particular for implementing Objective-C in Javascript. If you are an Objective-C developer, it is well worth a look as you will be able to quickly develop javascript web applications using a near identical language. If not, check it out anyway. These guys can certainly claim that this is Cocoa for Web Development.</p>
<h3>Update</h3>
<p>I wanted to include a couple of code snippets (taken from Cappuccino.org) just to illustrate how similar to Objective-C, Objective J is.</p>
<p>In Objective-J classes are declared much like an Objective-C header file:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> Person <span style="color: #002200;">:</span> CPObject
<span style="color: #002200;">&#123;</span>
   CPString name;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Methods are declared using the identical Objective-C syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CPString<span style="color: #002200;">&#41;</span>aName
<span style="color: #002200;">&#123;</span>
	name <span style="color: #002200;">=</span> aName;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>CPString<span style="color: #002200;">&#41;</span>name
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> name;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>And class methods can be called using a once again similar syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>myPerson setJobTitle<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">&quot;Founder&quot;</span> company<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">&quot;280 North&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p><a href="http://theocacao.com/document.page/593">Cocoa Master Scott Stevenson has done a nice comparison between Cocoa and Cappuccino, well worth a read..</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=iE6Ryd8g"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=RMejXYqO"><img src="http://feeds.feedburner.com/~f/miletbaker?i=RMejXYqO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=Jv9pOsFJ"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=Pibwkmbs"><img src="http://feeds.feedburner.com/~f/miletbaker?i=Pibwkmbs" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=Tx6C8OQ0"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=WAQe1B1B"><img src="http://feeds.feedburner.com/~f/miletbaker?i=WAQe1B1B" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=CsgNLmbW"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/I1nbF92yWFM" height="1" width="1"/>]]></content:encoded><description>This may be an unusual first post in my Objective-C and Cocoa categories however it is quite relevant as the guys behind 280 Slides have released a new open source extension to the Javascript language known as Objective-J and a new Javascript framework based on Cocoa named Cappuccino.
Other than having a very nice logo designed [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/09/07/objective-j-cappuccino/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">3</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/09/07/objective-j-cappuccino/</feedburner:origLink></item><item><title>Apology and Blog migrated..</title><link>http://feedproxy.google.com/~r/miletbaker/~3/GbGsIgWMVHQ/</link><category>Misc..</category><category>Django</category><category>Flex and Air</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Sun, 07 Sep 2008 03:46:37 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=111</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Firstly an apology about the lack of post lately. Like most of us I have been extremely busy and have not had much time to post but I will be writing some new articles shortly. I have a fair bit to post about, mostly flex but also some new posts on Ruby on Rails and some new topics such as Python&#8217;s excellent <a href="http://www.djangoproject.com/">Django framework</a> which has recently reached it&#8217;s 1.0 release milestone.</p>
<p>Also I have migrated my blog over from a shared Windows host to a Linux VPS machine which should allow me to use some of Wordpress&#8217; better plugins such as WP-SuperCache</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=BWpS790b"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=j60povKG"><img src="http://feeds.feedburner.com/~f/miletbaker?i=j60povKG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=NEy8jJdQ"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=8qz5fKbF"><img src="http://feeds.feedburner.com/~f/miletbaker?i=8qz5fKbF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=42OD5pjg"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=KSBzMpLT"><img src="http://feeds.feedburner.com/~f/miletbaker?i=KSBzMpLT" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=hF8VR8pX"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/GbGsIgWMVHQ" height="1" width="1"/>]]></content:encoded><description>Firstly an apology about the lack of post lately. Like most of us I have been extremely busy and have not had much time to post but I will be writing some new articles shortly. I have a fair bit to post about, mostly flex but also some new posts on Ruby on Rails and [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/09/07/apology-and-blog-migrated/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/09/07/apology-and-blog-migrated/</feedburner:origLink></item><item><title>Poor Blog Performance</title><link>http://feedproxy.google.com/~r/miletbaker/~3/fkofQprTH5w/</link><category>Misc..</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Tue, 10 Jun 2008 15:24:18 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=109</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Please accept my appologies if my blog appears slow at busy times. I am in the process of moving the blog to a more powerful hosting solution and implementing better caching.</p>
<p>Regards,</p>
<p>Jon</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=KSGcE3m2"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=ROMXOrAD"><img src="http://feeds.feedburner.com/~f/miletbaker?i=ROMXOrAD" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=5AHOaHxU"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=AFdSB52g"><img src="http://feeds.feedburner.com/~f/miletbaker?i=AFdSB52g" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=SdT2hDq2"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=w3IrB3QV"><img src="http://feeds.feedburner.com/~f/miletbaker?i=w3IrB3QV" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=5UWzqyyg"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/fkofQprTH5w" height="1" width="1"/>]]></content:encoded><description>Please accept my appologies if my blog appears slow at busy times. I am in the process of moving the blog to a more powerful hosting solution and implementing better caching.
Regards,
Jon</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/06/10/poor-blog-performance/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/06/10/poor-blog-performance/</feedburner:origLink></item><item><title>Building a medium to large scale Flex App using Cairngorm (Part 4)</title><link>http://feedproxy.google.com/~r/miletbaker/~3/--LOKgjOZrQ/</link><category>Flex and Air</category><category>AIR</category><category>as3</category><category>cairngorm</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Tue, 10 Jun 2008 15:06:12 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=107</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>In this final part on building a medium to large scale flex or Air app using Cairngorm, I will look at how I approach the service locator and use flex builders built in responder mechanism to handle service call responses.<br />
<span id="more-107"></span></p>
<h2>Services</h2>
<p>In <a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">part 1</a> we created a ServiceLocator singleton using the same method as we did for our ModelLocator. We will use this in a minute when we register our Service with the ServiceLocator.</p>
<p>I like to create a proxy class for my services.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">services</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">AsyncToken</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">IResponder</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">remoting</span>.<span style="color: #006600;">RemoteObject</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserService
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> ro : RemoteObject;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> UserService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			ro = <span style="color: #000000; font-weight: bold;">new</span> RemoteObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			ro.<span style="color: #006600;">destination</span> = <span style="color: #ff0000;">&quot;userService&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> logInUser<span style="color: #66cc66;">&#40;</span> username : <span style="color: #0066CC;">String</span>, <span style="color: #0066CC;">password</span> : <span style="color: #0066CC;">String</span>, responder : IResponder<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> at : AsyncToken = ro.<span style="color: #006600;">logInUser</span><span style="color: #66cc66;">&#40;</span> username, <span style="color: #0066CC;">password</span> <span style="color: #66cc66;">&#41;</span>;
			at.<span style="color: #006600;">addResponder</span><span style="color: #66cc66;">&#40;</span> responder <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>In this example we want to call a destination method called logInUser() passing a username and password as parameters. Here I am using the RemoteObject class to work with a backend server such as <a href="http://www.adobe.com/products/livecycle/">LiveCycle</a>, <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS">BlazeDS</a>, <a href="http://www.exadel.com/web/portal/flamingo">Flamingo</a>, <a href="http://www.themidnightcoders.com/weborb/">WebOrb</a> etc, via AMF (Actionscript Message Format), but you can use this with HTTPService, WebService, etc.</p>
<p>Notice that along with the two parameters that our service call will need, I have added a responder of type IResponder. I am going to use the <a href="http://www.darronschall.com/weblog/archives/000234.cfm">method championed by Darron Schall</a> where we use Flex&#8217;s built in responder and AsyncToken mechanism.</p>
<p>We need to now register this service on our ServiceLocator.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">services</span>.<span style="color: #006600;">ProductService</span>;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">services</span>.<span style="color: #006600;">UserService</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ServiceLocator
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _instance:ServiceLocator;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:ServiceLocator <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_instance == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_instance = <span style="color: #000000; font-weight: bold;">new</span> ServiceLocator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> _instance;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ServiceLocator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> _instance <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">throw</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Singleton class has already been instantiated&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">// Instantiate services here</span>
				userService = <span style="color: #000000; font-weight: bold;">new</span> UserService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				productService = <span style="color: #000000; font-weight: bold;">new</span> ProductService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> userService : UserService;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> productService : ProductService;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<h2>IResponder</h2>
<p>The IResponder interface that we used in our service enforces any class that implements it to provide a result( data : Object ) and fault( info : Object ) method. Due to the Asynchronous nature of Actionscript 3, the AsyncToken ensures the responder we provide handles that particular service call. Regular Event handlers to not offer this.</p>
<p>We are going to get all the commands we create (that make service calls) to implement this IResponder interface, in addition to the ICommand interface. We can then pass the command to the service as the responder for the service call:</p>
<p>So for a command that gets the ProductDTOs we used in <a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">Part 2</a>, using for example a getProducts() method call on a productService destination.</p>
<p><em>Service:</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">services</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">AsyncToken</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">IResponder</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">remoting</span>.<span style="color: #006600;">RemoteObject</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ProductService
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> ro : RemoteObject;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ProductService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			ro = <span style="color: #000000; font-weight: bold;">new</span> RemoteObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			ro.<span style="color: #006600;">destination</span> = <span style="color: #ff0000;">&quot;productService&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getProducts<span style="color: #66cc66;">&#40;</span> responder : IResponder <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> at : AsyncToken = ro.<span style="color: #006600;">getProducts</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			at.<span style="color: #006600;">addResponder</span><span style="color: #66cc66;">&#40;</span> responder <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>(We register this with our ServiceLocator as we did for the UserService)</p>
<p><em>GetAllProductsCommand:</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">commands</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #006600;">commands</span>.<span style="color: #006600;">ICommand</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #0066CC;">control</span>.<span style="color: #006600;">CairngormEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">IResponder</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">ServiceLocator</span>;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">ModelLocator</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GetAllProductsCommand <span style="color: #0066CC;">implements</span> ICommand, IResponder
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> GetAllProductsCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #66cc66;">&#40;</span>event:CairngormEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			ServiceLocator.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">productService</span>.<span style="color: #006600;">getProducts</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> result<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			ModelLocator.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">product</span>.<span style="color: #006600;">dtos</span> = ResultEvent<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">data</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">result</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fault<span style="color: #66cc66;">&#40;</span>info:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Fault handler code</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Once this command is registered with our controller we can dispatch the relevant event form anywhere in our application to load all the products into our model.</p>
<p>Notice above how the command implements the IResponder interface and passes itself to the service to act as the responder for the service call. We then get to handle the service response and fault from within the command.</p>
<h2>Chaining Commands Together (Revisited)</h2>
<p>With this knowledge, we can return to our SequenceCommand example where we want to log a user in and then call the ChangeApplicationStateCommand to change the view state of Main.mxml to the logged in user state or logged in Admin state</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">commands</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #006600;">commands</span>.<span style="color: #006600;">SequenceCommand</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #0066CC;">control</span>.<span style="color: #006600;">CairngormEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">IResponder</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">AppController</span>;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">ServiceLocator</span>;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">LoginEvent</span>;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">ModelLocator</span>;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">dto</span>.<span style="color: #006600;">UserDTO</span>;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">session</span>.<span style="color: #006600;">SessionModel</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LogUserInCommand <span style="color: #0066CC;">extends</span> SequenceCommand <span style="color: #0066CC;">implements</span> IResponder
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> LogUserInCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">nextEvent</span> = <span style="color: #000000; font-weight: bold;">new</span> CairngormEvent<span style="color: #66cc66;">&#40;</span>AppController.<span style="color: #006600;">CHANGE_APP_STATE</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #66cc66;">&#40;</span>event:CairngormEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">le</span> : LoginEvent = LoginEvent<span style="color: #66cc66;">&#40;</span> event <span style="color: #66cc66;">&#41;</span>;
			ServiceLocator.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">userService</span>.<span style="color: #006600;">logInUser</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">le</span>.<span style="color: #006600;">username</span>, <span style="color: #0066CC;">le</span>.<span style="color: #0066CC;">password</span>, <span style="color: #0066CC;">this</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> result<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			ModelLocator.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">session</span>.<span style="color: #006600;">userDTO</span> = UserDTO<span style="color: #66cc66;">&#40;</span> ResultEvent<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">data</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">result</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> ModelLocator.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">session</span>.<span style="color: #006600;">loggedInUser</span>.<span style="color: #006600;">isAdmin</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">nextEvent</span>.<span style="color: #0066CC;">data</span> = SessionModel.<span style="color: #006600;">APP_STATE_ADMIN</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">nextEvent</span>.<span style="color: #0066CC;">data</span> = SessionModel.<span style="color: #006600;">APP_STATE_LOGGED_IN</span>;
			<span style="color: #66cc66;">&#125;</span>
			executeNextCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fault<span style="color: #66cc66;">&#40;</span>info:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Fault handler code goes here</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>To use Cairngorm&#8217;s SequenceCommand feature, our command has to extend SequenceCommand. SequenceCommand already implements ICommand but this means we need to override the execute() method and we still need to implement IResponder as we want this class to handle the response from the userService.</p>
<p>In the commands constructor we set the SequenceCommands nextEvent property which takes the CairngormEvent you want to dispatch from this command. When you are ready you can dispatch the event using the SequenceCommand&#8217;s executeNextCommand() method.</p>
<p>Our ChangeApplicationStateCommand looks for the state we want to change to in the data property of the CairngormEvent so we set the relevant one in the result handler and dispatch.</p>
<p>As I previously demonstrated for the Product model, I have implemented similar code to convert the UserDTO returned from the service to a User model item object. The User object has some business logic in it to identify whether the user is an Admin (which is not in the DTO). </p>
<p>As you can see although Cairngorm adds a fair bit of code, in the long run we have a more organised and consistently centralised configuration which makes it easier to maintain, test etc. <a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">As I stated in Part 1</a> my method is not the documented way of using Cairngorm but has been adapted over use on several large projects to the solution that works best for us. I hope this series is useful to anyone starting out with Cairngorm and I do recommend you look at <a href="http://clockobj.co.uk/2007/10/17/simplified-cairngorm-easy-mvc-for-adobe-flex/">EasyMVC</a> and alternatives to Cairngorm such as <a href="http://puremvc.org/">PureMVC</a> ( I have never used this but only because Cairngorm meets my needs ).</p>
<p>I have also attached the source files I used to write this article which i hope will help you see how everything hangs together.: <a href='http://clockobj.co.uk/wp-content/uploads/2008/06/cairngormdemo.zip'>Cairngorm Demo Srource Files</a></p>
<h2>Contents:</h2>
<p><a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">Part 1 &#8211; Setting up a project for Cairngorm</a><br />
<a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">Part 2 &#8211; The Model</a><br />
<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/">Part 3 &#8211; Commands</a><br />
Part 4 &#8211; Services<br />
<a href="http://clockobj.co.uk/wp-content/uploads/2008/06/cairngormdemo.zip">Cairngorm Demo Source Files</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=N8csBWMY"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=NbUf1YtG"><img src="http://feeds.feedburner.com/~f/miletbaker?i=NbUf1YtG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=LhQBLjIU"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=1ZoiTFBD"><img src="http://feeds.feedburner.com/~f/miletbaker?i=1ZoiTFBD" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=2TKsHlNV"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=jdHqlthl"><img src="http://feeds.feedburner.com/~f/miletbaker?i=jdHqlthl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=cAizjGZ4"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/--LOKgjOZrQ" height="1" width="1"/>]]></content:encoded><description>In this final part on building a medium to large scale flex or Air app using Cairngorm, I will look at how I approach the service locator and use flex builders built in responder mechanism to handle service call responses.

Services
In part 1 we created a ServiceLocator singleton using the same method as we did for [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-4/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">7</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-4/</feedburner:origLink></item><item><title>Building a medium to large scale Flex App using Cairngorm (Part 3)</title><link>http://feedproxy.google.com/~r/miletbaker/~3/j_TO-fpHyqU/</link><category>Flex and Air</category><category>AIR</category><category>as3</category><category>cairngorm</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Tue, 10 Jun 2008 12:49:16 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=105</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>In <a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">Parts 1</a> &amp; <a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">2</a> we setup Cairngorm and our models. In Part 3 we will look at how we will make use of the controller, using commands to handle events, chaining together a series of commands using Cairngorm&#8217;s SequenceCommand and creating custom CairngormEvents.<br />
<span id="more-105"></span></p>
<h2>Controller</h2>
<p>In <a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">part 1</a> we created a class that extends Cairngorm&#8217;s FrontController. This controller allows us to register event handlers on Cairngorm&#8217;s custom event dispatcher. But rather than creating each event handler directly in Cairngorm&#8217;s front controller (as we would in EasyMVC) we use the command pattern to organise our event handlers into separate classes.</p>
<p>As our app grows, this separation into commands helps keep our application easily maintainable.</p>
<h2>Commands</h2>
<p>Cairngorm provides an interface named ICommand, that command classes must implement. This interface enforces an execute() function which passes in a a CairngormEvent.</p>
<p>As an example, we are now going to create a command for changing the application&#8217;s state between it&#8217;s default logged out state, logged in state and admin state. If you remember back to <a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">Part 2</a>, we created a Session model and stored Main.mxml&#8217;s view state here using binding. We will now create a command that will change this state.</p>
<p>Firstly we start with the actual command class that will handle this event by creating a new ActionScript class that implements ICommand in the controller/commands folder. This command will fire when we dispatch the appropriate CairngormEvent. By default the CairngormEvent class has a data property that allows us to pass information to the command, in this case we want to pass the state that we want the command to change our Main.mxml viewstate to.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">commands</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #006600;">commands</span>.<span style="color: #006600;">ICommand</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #0066CC;">control</span>.<span style="color: #006600;">CairngormEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">ModelLocator</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ChangeApplicationStateCommand <span style="color: #0066CC;">implements</span> ICommand
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ChangeApplicationStateCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #66cc66;">&#40;</span>event:CairngormEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			ModelLocator.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">session</span>.<span style="color: #006600;">appState</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span> event.<span style="color: #0066CC;">data</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Once we have written our command, we need to register the class with our controller. The FrontController that we extended provides an addCommand method that registers our command as an event listener for a specific named event.</p>
<p>Like native flex events, Cairngorm uses a name property on the event (of type string) to track which command will handle which event. By convention we store our event names as static string constants in the Controller.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #0066CC;">control</span>.<span style="color: #006600;">FrontController</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">commands</span>.<span style="color: #006600;">ChangeApplicationStateCommand</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AppController <span style="color: #0066CC;">extends</span> FrontController
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AppController<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			initialiseCommands<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initialiseCommands<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			addCommand<span style="color: #66cc66;">&#40;</span>CHANGE_APP_STATE, ChangeApplicationStateCommand<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const CHANGE_APP_STATE : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;changeAppState&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>With our command registered we can now call it globally within our application using the following code. Note: If you remember back to <a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">part 2</a> we stored the three view states for Main.mxml as static constants on our Session model.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> ce : CairngormEvent = <span style="color: #000000; font-weight: bold;">new</span> CairngormEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
ce.<span style="color: #0066CC;">data</span> = SessionModel.<span style="color: #006600;">APP_STATE_LOGGED_IN</span>;
CairngormEventDispatcher.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span> ce <span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>If we were not passing any data, we could obviously do this in one line. Cairngorm&#8217;s data property is useful for passing all kinds of data, however in some cases you may need to pass more that one bit of data. For example a username and password, to a login command.</p>
<p>There are many ways we could do this, one of the easiest is to create a dynamic object instance to send the data over in. i.e.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> ce : CairngormEvent = <span style="color: #000000; font-weight: bold;">new</span> CairngormEvent<span style="color: #66cc66;">&#40;</span>AppController.<span style="color: #006600;">LOGIN_COMMAND</span><span style="color: #66cc66;">&#41;</span>
ce.<span style="color: #0066CC;">data</span> = <span style="color: #66cc66;">&#123;</span> username : <span style="color: #ff0000;">&quot;jon&quot;</span> , <span style="color: #0066CC;">password</span>: <span style="color: #ff0000;">&quot;baker&quot;</span> <span style="color: #66cc66;">&#125;</span>;
CairngormEventDispatcher.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span> ce <span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Then in our command we can extract these values:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>14
15
16
17
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #66cc66;">&#40;</span> event : CairngormEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> username : <span style="color: #0066CC;">String</span> = event.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">username</span>;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">password</span> : <span style="color: #0066CC;">String</span> = event.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">password</span>;</pre></td></tr></table></div>

<h2>Custom events</h2>
<p>The above method is fine for ad hoc requirements but if you need to formalise this, we need to create a custom CairngormEvent.</p>
<p>We do this by extending the CairngormEvent and including (in this case) a username and password property to our extended class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>.<span style="color: #006600;">events</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #0066CC;">control</span>.<span style="color: #006600;">CairngormEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoginEvent <span style="color: #0066CC;">extends</span> CairngormEvent
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> username : <span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">password</span> : <span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> LoginEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, username : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>, <span style="color: #0066CC;">password</span> : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">username</span> = username;
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">password</span> = <span style="color: #0066CC;">password</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><em>Note:</em> I have added code to allow the username and password to the constructor, this is useful for dispatching the event from one line of code.</p>
<h2>Chaining Commands Together</h2>
<p>There are times when developing an application that we will want to run a command from within another command. For this we need to use Cairngorm&#8217;s built in SequenceCommand class.</p>
<p>So for example on logging into our application, we will want to change the application state to either the logged in state or the admin state, based on the user&#8217;s role. We could do this directly from our login command but we have an event for this so we want to reuse that command.</p>
<p>For any command that wants to make a call to an additional command, the calling class must extend SequenceCommand;</p>
<p><em>Note:</em> With the example above we are making use of a service call to log a user in. I will first cover Services and the Service Locator classes in the next part, so to avoid confusion, I will cover these in <a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">Part 4</a> and finish up by returning to the example sequence command discussed above.</p>
<p>In Part 4, I will discuss how we use our ServiceLocator class we created in Part 1 to locate our services and how we will call and respond to these service calls from our commands.</p>
<h2>Contents:</h2>
<p><a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">Part 1 &#8211; Setting up a project for Cairngorm</a><br />
<a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">Part 2 &#8211; The Model</a><br />
Part 3 &#8211; Commands<br />
<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-4/">Part 4 &#8211; Services</a><br />
<a href="http://clockobj.co.uk/wp-content/uploads/2008/06/cairngormdemo.zip">Cairngorm Demo Source Files</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=5Zvj1Kmd"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=X8XCC1tB"><img src="http://feeds.feedburner.com/~f/miletbaker?i=X8XCC1tB" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=EppM9QlR"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=gIv70aJl"><img src="http://feeds.feedburner.com/~f/miletbaker?i=gIv70aJl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=xsf9jaaM"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=KC22bqgP"><img src="http://feeds.feedburner.com/~f/miletbaker?i=KC22bqgP" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=JEB1jEV7"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/j_TO-fpHyqU" height="1" width="1"/>]]></content:encoded><description>In Parts 1 &amp;#38; 2 we setup Cairngorm and our models. In Part 3 we will look at how we will make use of the controller, using commands to handle events, chaining together a series of commands using Cairngorm&amp;#8217;s SequenceCommand and creating custom CairngormEvents.

Controller
In part 1 we created a class that extends Cairngorm&amp;#8217;s FrontController. This [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/</feedburner:origLink></item><item><title>Building a medium to large scale Flex App using Cairngorm (Part 2)</title><link>http://feedproxy.google.com/~r/miletbaker/~3/NDE4GsSlpqQ/</link><category>Flex and Air</category><category>AIR</category><category>as3</category><category>cairngorm</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Sun, 08 Jun 2008 11:19:16 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=104</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>In <a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">Part 1</a> we created a new Flex project and setup the classes we that will be used to support our application architecture. In this part we will look at how we build our application around these classes.<br />
<span id="more-104"></span><br />
Having set up our project in Step 1 we are ready to start building our app. Like many flex developers, I don&#8217;t generally start building the view in the default application mxml file (CairngormDemo.mxml in the example I have been using). Instead I create a new MXML Component called Main.mxml file in the View folder (often based on a VBox or Canvas, 100% wide x 100% high). From here, all my other views hang off this. The main reason for this is that the application file needs to sit in the source root, while the rest of our application sits in our namespace folders. This avoids having code here.</p>
<p>There are various ways to implement the different application states. One approach which is popular, is to have a view state (within Main.mxml) for each top level state of the application, so for example I may have a default logged out state, a logged in state and possibly and admin state for example.</p>
<p>We need to ensure that we have nested our Main.mxml view into the application. While we are editing our application file, I place the Caringorm controller (App Controller we created in Part 1 here too). For purpose of example, my CairngormDemo.mxml file looks like this:</p>
<p>I may also add an mx:style tag referencing an external style sheet here but other than that nothing else goes here.</p>
<h2>A model for session and state</h2>
<p>I like to create a session model to hold session state data such as view states and depending on our apps perhaps the currently logged in user etc.</p>
<p>I create this model, as I would any other model (so it will be a good example). I firstly create a folder for this session model under the model directory (in this case called session) and create my new simple ActionScript class called SessionModel in that folder that will hold my model data.</p>
<p>As we are going to bind to data in this model directly from our mxml files, so we need to use the [Bindable] Meta tag.</p>
<p>For now we will add a property to hold the current view state for Main.mxml and store the name of each state as static properties on the model. As our app grows we will add other view states that need we want to make globally accessible here.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">session</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SessionModel
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SessionModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const APP_STATE_LOGGED_OUT : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const APP_STATE_LOGGED_IN : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;appStateLoggedIn&quot;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const APP_STATE_ADMIN : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;appStateAdmin&quot;</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> appState : <span style="color: #0066CC;">String</span> = APP_STATE_LOGGED_OUT;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>We now want to make this locatable via our Model Locator. We can make the following modifications to the ModelLocater we created in <a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">Part 1</a> as as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ModelLocator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> instance <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">throw</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Singleton class has already been instantiated&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">// Instantiate the model when the Locator is Instantiated</span>
				session = <span style="color: #000000; font-weight: bold;">new</span> SessionModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> session : SessionModel;</pre></div></div>

<p>Once we have done this we can add our bindings to Main.mxml&#8217;s currentState property using Flex&#8217;s binding mechanism, as in the following example:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:VBox</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">currentState</span>=<span style="color: #ff0000;">&quot;{ ModelLocator.getInstance().session.appState }&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;appStateLoggedIn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #808080; font-style: italic;">&lt;!-- Changes to mxml when logged in --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:State<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;appStateAdmin&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #808080; font-style: italic;">&lt;!-- Changes to mxml when admin logged in --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:State<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">			import uk.co.clockobj.cairngormdemo.model.ModelLocator;</span>
<span style="color: #339933;">		]]&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- Default view --&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:VBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Once setup, we can now change the application&#8217;s state by doing something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">ModelLocator.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">session</span>.<span style="color: #006600;">appState</span> = SessionModel.<span style="color: #006600;">APP_STATE_LOGGED_IN</span>;</pre></div></div>

<p>However, RESIST the temptation to do this all over the place. We want to maintain a convention and as this is an MVC framework, the controller should manage these state changes. Instead to change application state we will dispatch a CairngormEvent. (<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/">We will look at dispatching and handling Cairngorm events in Part 3</a>)</p>
<h2>More on Models and Data Transfer Objects</h2>
<p>The <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html">Cairngorm guide by Steven Webster</a> suggests storing Value Objects, or Data Transfer Objects, directly in the ModelLocator and binding to these directly. There are two schools of though here and your approach will depend on your project.</p>
<p>One is to do this and store the DTOs directly in the model, the other is to have separate model classes. The advantage of the latter is obviously less code, however by creating separate model classes to the DTOs may seem like duplication of work, you have the added advantage of being able to add business logic into your models, for example validation, conversions, etc. Secondly if the DTOs signatures change, you don&#8217;t have to re-factor your entire app changing all your bindings. You need to only to this in the translation methods between your DTOs and model. You also overcome an issue I encountered recently when returning remote objects received from a backend Java AMF server where you have to ensure all the data in cast to the correct DTOs (<a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&amp;productId=2&amp;postId=8323">See this article</a>) as the translation process overcomes this.</p>
<p>An example, if we had to work with product data, I would have a product model which held product items. I would build a method into my model to translate DTOs into the model and back.</p>
<p>Note: if you are using soap / xml you could pass in the untyped object or xml to build the class from.</p>
<p>With the following DTO:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">dto</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span>RemoteClass<span style="color: #66cc66;">&#40;</span>alias=<span style="color: #ff0000;">&quot;namespace.to.some.server.dto&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ProductDTO
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> id				: <span style="color: #0066CC;">int</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> price 			: <span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> description		: <span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ProductDTO<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Our product items (stored in our product model) would take an optional ProductDTO class passed to the constructor to build itself from. As an example, I have also added simple business logic to ensure the price is never negative. In a future article i want to show how validation logic can be put here (Which to me seems a more appropriate place than the view):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">product</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">dto</span>.<span style="color: #006600;">ProductDTO</span>;
&nbsp;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Product
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> id			: <span style="color: #0066CC;">int</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _price 		: <span style="color: #0066CC;">Number</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> description	: <span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> price<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Number</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _price;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> price<span style="color: #66cc66;">&#40;</span> value : <span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> value <span style="color: #66cc66;">&amp;</span>lt; <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span>
				value = <span style="color: #cc66cc;">0</span>;
			_price = value;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Product<span style="color: #66cc66;">&#40;</span> productDTO : ProductDTO = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> productDTO <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">price</span> = productDTO.<span style="color: #006600;">price</span>;
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">description</span> = productDTO.<span style="color: #006600;">description</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Finally we create our product model, as we did for our session model, but with a dto translation function (here implemented via a property setter / getter):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">product</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">dto</span>.<span style="color: #006600;">ProductDTO</span>;
&nbsp;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ProductModel
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> products : ArrayCollection;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ProductModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			products = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> dtos<span style="color: #66cc66;">&#40;</span> value : ArrayCollection <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> pdto : ProductDTO <span style="color: #b1b100;">in</span> value <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				products.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Product<span style="color: #66cc66;">&#40;</span> pdto <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> dtos<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : ArrayCollection
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> dtos : ArrayCollection;
			<span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> p : Product <span style="color: #b1b100;">in</span> products <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> pdto : ProductDTO = <span style="color: #000000; font-weight: bold;">new</span> ProductDTO<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
				pdto.<span style="color: #006600;">id</span> = p.<span style="color: #006600;">id</span>;
				pdto.<span style="color: #006600;">description</span> = p.<span style="color: #006600;">description</span>;
				pdto.<span style="color: #006600;">price</span> = p.<span style="color: #006600;">price</span>;
				dtos.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> pdto <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> dtos;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>We would also need to put this product model into our model locator, exactly as we did for the session model.</p>
<h2>Binding</h2>
<p>We can now bind to our product data from throughout our application. We would do this as we bound the currentState property of Main.mxml. You can obviously use this approach when binding to editable controls (such as form fields) but, depending on the project, one thing I do is setup a two way binding (I have a custom component that uses the BindingUtils.bindProperty() method to bind the model to the form and the form back to the model). Again I hope to add an article about this in the future.</p>
<p>In <a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/">Part 3</a> I will look at how we will make use of the controller, use commands to handle events, chain together a series of commands using Cairngorm&#8217;s SequenceCommand and also create custom events that extend CairngormEvents.</p>
<h2>Contents:</h2>
<p><a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">Part 1 &#8211; Setting up a project for Cairngorm</a><br />
Part 2 &#8211; The Model<br />
<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/">Part 3 &#8211; Commands</a><br />
<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-4/">Part 4 &#8211; Services</a><br />
<a href="http://clockobj.co.uk/wp-content/uploads/2008/06/cairngormdemo.zip">Cairngorm Demo Source Files</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=9iUkfqxK"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=1yGqfxwK"><img src="http://feeds.feedburner.com/~f/miletbaker?i=1yGqfxwK" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=h9476S3f"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=JgQKlAVb"><img src="http://feeds.feedburner.com/~f/miletbaker?i=JgQKlAVb" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=sMPrzJIv"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=LoFE6c4Y"><img src="http://feeds.feedburner.com/~f/miletbaker?i=LoFE6c4Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=Zot0heAU"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/NDE4GsSlpqQ" height="1" width="1"/>]]></content:encoded><description>In Part 1 we created a new Flex project and setup the classes we that will be used to support our application architecture. In this part we will look at how we build our application around these classes.

Having set up our project in Step 1 we are ready to start building our app. Like many [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">9</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/</feedburner:origLink></item><item><title>Building a medium to large scale Flex App using Cairngorm (Part 1)</title><link>http://feedproxy.google.com/~r/miletbaker/~3/OmCoQoa_mJE/</link><category>Flex and Air</category><category>AIR</category><category>as3</category><category>cairngorm</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Fri, 06 Jun 2008 12:22:20 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=95</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>This is the first part of a four part series on my own approach to using Cairngorm to build an enterprise Rich Internet App.</p>
<p>In the first part, I cover setting up your project and creating the foundation classes that will hand our Rich Internet Application together.<br />
<span id="more-95"></span></p>
<h2>Getting Started</h2>
<p>Before we start although I am using Flex 3 and building a Flex app, this method works for Flex 2 and also Adobe Air applications.</p>
<p>Cairngorm is a Model View Controller framework and the first thing I like to do after creating a new Flex project is to create the appropriate folders in my project namespace. so for example, under uk/co/clockobj/projectname, I would create three folders named model, view and controller. Note: you don&#8217;t have to namespace or use this folder structure I use, but this is what I like to do by convention.</p>
<p>The controller folder will store my controller (Cairngorm&#8217;s Front Controller), my commands, my service locator, services and custom events.</p>
<p>The model folder will store my model locator, models and my Value Objects / Data Transfer Objects, in the screenshot above I have created a product subfolder to hold product related model classes.</p>
<p>Finally the view folder will store all our mxml.</p>
<p><img src="http://clockobj.co.uk/wp-content/uploads/2008/06/cairngorm_layout.png" alt="" title="cairngorm_layout" width="402" height="492" class="aligncenter size-full wp-image-106" /></p>
<p>Note: I have an additional folder shown above called presentation. This is entirely optional but if you use a Presentation methodology, you can mimicking the folder structure of the view folder and store your Presentation modifier classes here.</p>
<p>Note: For now the presentation layer is beyond the scope of this article but I hope to post an article on this soon.</p>
<p>Next, you will want to <a href="http://labs.adobe.com/wiki/index.php/Cairngorm">download the Cairngorm.swc file from here</a>. (If you are new to Cairngorm <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html">do read Steven Websters articles</a>, they are a little outdated but explain the rationale and thinking behind cairngorm). Once downloaded, put the cairngorm.swc file in your libs folder.</p>
<p>With the Cairngorm.swc in our libs folder we have access to the Cairngorm classes. I also really recommend looking at the source code for Cairngorm (separate download from the link above).</p>
<h2>Setting up Cairngorm</h2>
<p>First thing we can setup is our controller. This is done by extending Cairngorm&#8217;s front controller class. Cairngorm&#8217;s front controller is very similar to the controller class created in my <a href="http://clockobj.co.uk/2008/01/21/scaling-up-easymvc-as-your-flex-application-grows-part-1/">scaling up EasyMVC articles</a> except Cairngorm uses it&#8217;s own EventDispatcher. Rather than listening to native events, it listens to CairngormEvents dispatched by it&#8217;s custom event handler.</p>
<p>We create an initialiseCommands function which is called from the constructor and this function will be where we will register our command classes as event listeners for cairngorm events. (<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/">more on that in part 3</a>)</p>
<p>Your controller class should look a little like this, I have called mine AppController:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #0066CC;">control</span>.<span style="color: #006600;">FrontController</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AppController <span style="color: #0066CC;">extends</span> FrontController
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AppController<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			initialiseCommands<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initialiseCommands<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// We will register our commands as event handlers here.</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Next, I will create a Model Locator and Service Locator using the known locator pattern which yes, uses Singletons but as Steven Webster so rightly puts it:<br />
<a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_06.html">&#8220;The singleton nature of the Model Locator pattern ensures that you don&#8217;t suffer from duplicate state on the client, gives a large development team a consistent place to expose and share application-level state as instances of value objects, while ensuring that developers leverage the powerful data-binding capabilities of Flex to ensure that the view is notified when the model has changed.&#8221;</a></p>
<h2>Model Locator</h2>
<p>I create my model locator named ModelLocator, however you will get a class name clash as there is a deprecated class in Cairngorm called ModelLocator (This just means when ever you add it to a class in Flex Builder you will be asked which one to use, which may annoy you).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">model</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">cairngorm</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">IModelLocator</span>;
&nbsp;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ModelLocator <span style="color: #0066CC;">implements</span> IModelLocator
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _instance:ModelLocator;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:ModelLocator <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_instance == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_instance = <span style="color: #000000; font-weight: bold;">new</span> ModelLocator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> _instance;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ModelLocator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> _instance <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">throw</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Singleton class has already been instantiated&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>	<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">// Instantiate services here</span>
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Note: Although I implement Cairngorm&#8217;s IModelLocator interface above, it does not actually enforce any methods or properties.</p>
<p>In Steven Webster&#8217;s guide to Cairngorm, he stores the DTOs/VO as static properties of the model locator. I take a slightly different approach and I like to have models which are accessible through, and instantiated when the ModelLocator is first created, I will discuss this later (<a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">in part 2</a>)</p>
<h2>Service Locator</h2>
<p>I am also going to deviate slightly from the Cairngorm documented approach for Service Locators and implement a slightly less enforced version. Cairngorm uses an IServiceLocator interface which enforces the use of simple factory methods to access your services. You may need this so have a <a href="http://www.cairngormdocs.org/">look at the documentation</a>, but I going to keep my Service Locator consistent with my Model Locator.</p>
<p>So in the controller folder create a new ActionScript Class called ServiceLocator.as as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package uk.<span style="color: #006600;">co</span>.<span style="color: #006600;">clockobj</span>.<span style="color: #006600;">cairngormdemo</span>.<span style="color: #006600;">controller</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ServiceLocator
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _instance:ServiceLocator;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:ServiceLocator <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_instance == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_instance = <span style="color: #000000; font-weight: bold;">new</span> ServiceLocator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> _instance;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ServiceLocator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> instance <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">throw</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Singleton class has already been instantiated&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">// Instantiate services here</span>
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>For now we are not going to create any web services, <a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/">we will do this in part 3</a>.</p>
<p><a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">In the next part of this series</a> I will go into detail about how I implement models, discuss the advantages and disadvantages of accessing your DTOs directly and propose a different solution and show how we can bind our currentState view state property directly to the model.</p>
<h2>Contents:</h2>
<p>Part 1 &#8211; Setting up a project for Cairngorm<br />
<a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">Part 2 &#8211; The Model</a><br />
<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/">Part 3 &#8211; Commands</a><br />
<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-4/">Part 4 &#8211; Services</a><br />
<a href="http://clockobj.co.uk/wp-content/uploads/2008/06/cairngormdemo.zip">Cairngorm Demo Source Files</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=7qAklZjr"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=3XFydAaA"><img src="http://feeds.feedburner.com/~f/miletbaker?i=3XFydAaA" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=jNH6gy3i"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=RaDlvXO8"><img src="http://feeds.feedburner.com/~f/miletbaker?i=RaDlvXO8" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=Y51aOFdQ"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=TU65m90R"><img src="http://feeds.feedburner.com/~f/miletbaker?i=TU65m90R" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=cZcYhSUW"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/OmCoQoa_mJE" height="1" width="1"/>]]></content:encoded><description>This is the first part of a four part series on my own approach to using Cairngorm to build an enterprise Rich Internet App.
In the first part, I cover setting up your project and creating the foundation classes that will hand our Rich Internet Application together.

Getting Started
Before we start although I am using Flex 3 [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/</feedburner:origLink></item><item><title>A walkthrough on how to use Cairngorm with Flex or Air</title><link>http://feedproxy.google.com/~r/miletbaker/~3/YpxmRJ1SsFM/</link><category>Flex and Air</category><category>AIR</category><category>as3</category><category>cairngorm</category><category>mvc</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Fri, 06 Jun 2008 12:20:03 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=94</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>The Flex scene seems to be lacking in beginners&#8217; guides to Cairngorm (maybe they are just alluding my Google searches) so I have put together (larger than hoped) a four part series that guides you through how I use Cairngorm.</p>
<p>For those of you who have <a href="http://clockobj.co.uk/2007/10/17/simplified-cairngorm-easy-mvc-for-adobe-flex/">read my articles</a> on <a href="www.tombray.com/">Tom Bray&#8217;s</a> EasyMVC, this may sound surprising. I have previously posted articles on how to <a href="http://clockobj.co.uk/2008/01/21/scaling-up-easymvc-as-your-flex-application-grows-part-1/">scale up EasyMVC into a Micro-architecture similar to Cairngorm</a>. However, the rationale behind these articles was to help developers who implement EasyMVC and find their app out grows the implementation that Tom originally presented, and not as a blueprint for architecting apps. EasyMVC is a great framework for small Flex apps and Flex widgets where using Cairngorm would be the equivalent of taking a sledgehammer to a walnut. If you know in advance you application is going to be fairly sizable, use Cairngorm (or something like <a href="http://puremvc.org/">PureMVC</a> if you prefer).</p>
<p>Before I get started, there is a slight disclaimer: I am going to present my own approach to using Cairngorm which does deviate from the documented approach, namely around services. I feel it is simpler, but you may beg to differ. I do not present this as the best solution or a perfect solution, but it is a tried and tested solution which hopefully will get more developers understanding and using Cairngorm where appropriate.</p>
<p>In essence this series should give you all you need to know to get started with Cairngorm.</p>
<h2>Contents:</h2>
<p><a href="http://clockobj.co.uk/2008/06/06/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-1/">Part 1 &#8211; Setting up a project for Cairngorm</a><br />
<a href="http://clockobj.co.uk/2008/06/08/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-2/">Part 2 &#8211; The Model</a><br />
<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-3/">Part 3 &#8211; Commands</a><br />
<a href="http://clockobj.co.uk/2008/06/10/building-a-medium-to-large-scale-flex-app-using-cairngorm-part-4/">Part 4 &#8211; Services</a><br />
<a href="http://clockobj.co.uk/wp-content/uploads/2008/06/cairngormdemo.zip">Cairngorm Demo Source Files</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=VXFrKuLt"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=FQFP6dqj"><img src="http://feeds.feedburner.com/~f/miletbaker?i=FQFP6dqj" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=5L09M2Mk"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=Tx52Ifsl"><img src="http://feeds.feedburner.com/~f/miletbaker?i=Tx52Ifsl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=aT3bicaQ"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=4gtemrh6"><img src="http://feeds.feedburner.com/~f/miletbaker?i=4gtemrh6" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=p1O2W7Eq"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/YpxmRJ1SsFM" height="1" width="1"/>]]></content:encoded><description>The Flex scene seems to be lacking in beginners&amp;#8217; guides to Cairngorm (maybe they are just alluding my Google searches) so I have put together (larger than hoped) a four part series that guides you through how I use Cairngorm.
For those of you who have read my articles on Tom Bray&amp;#8217;s EasyMVC, this may sound [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/06/06/a-walkthrough-on-how-to-use-cairngorm-with-flex-or-air/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">1</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/06/06/a-walkthrough-on-how-to-use-cairngorm-with-flex-or-air/</feedburner:origLink></item><item><title>Changing Flex3 ScrollBar maxScrollPosition at runtime</title><link>http://feedproxy.google.com/~r/miletbaker/~3/KLOl_4anQWE/</link><category>Flex and Air</category><category>AIR</category><category>as3</category><category>scrollbar</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Wed, 07 May 2008 11:16:07 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=91</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>A quick tip if you have a dynamic scroll bar and want to bind it&#8217;s maxScrollPosition to a value at runtime unfortunately you can&#8217;t use the MXML binding, i.e. maxScrollPosition={value}.</p>
<p>Alternatively you need to set the value programatically in an event handler, AND importantly call updateDisplayList() on the scrollbar. i.e.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">&nbsp;
		<span style="color: #66cc66;">&lt;!</span>--<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleSlideChange<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">scroll</span>.<span style="color: #006600;">maxScrollPosition</span> = slider.<span style="color: #006600;">value</span>;
				<span style="color: #0066CC;">scroll</span>.<span style="color: #006600;">invalidateDisplayList</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>--<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p><script src="http://clockobj.co.uk/wp-content/uploads/2008/05/ac_oetags.js"></script><br />
 <script type="text/javascript"><!--
		AC_FL_RunContent(
					"src", "http://clockobj.co.uk/wp-content/uploads/2008/05/scrollbartest",
					"width", "500",
					"height", "100",
					"align", "middle",
					"id", "ScrollBarTest",
					"quality", "high",
					"bgcolor", "#869ca7",
					"name", "ScrollBarTest",
					"allowScriptAccess","sameDomain",
					"type", "application/x-shockwave-flash",
					"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
// -->
// --&gt;</script><br />
<noscript>&lt;br /&gt; 	&lt;span class=&#8221;mceItemObject&#8221;  classid=&#8221;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&#8243;&lt;br /&gt; 			id=&#8221;ScrollBarTest&#8221; width=&#8221;500&#8243; height=&#8221;100&#8243;&lt;br /&gt; 			codebase=&#8221;http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab&#8221;&gt;&lt;span  name=&#8221;movie&#8221; value=&#8221;ScrollBarTest.swf&#8221; class=&#8221;mceItemParam&#8221;&gt;&lt;/span&gt;&lt;span  name=&#8221;quality&#8221; value=&#8221;high&#8221; class=&#8221;mceItemParam&#8221;&gt;&lt;/span&gt;&lt;span  name=&#8221;bgcolor&#8221; value=&#8221;#869ca7&#8243; class=&#8221;mceItemParam&#8221;&gt;&lt;/span&gt;&lt;span  name=&#8221;allowScriptAccess&#8221; value=&#8221;sameDomain&#8221; class=&#8221;mceItemParam&#8221;&gt;&lt;/span&gt;&lt;span class=&#8221;mceItemEmbed&#8221;  src=&#8221;http://clockobj.co.uk/wp-content/uploads/2008/05/scrollbartest.swf&#8221; mce_src=&#8221;http://clockobj.co.uk/wp-content/uploads/2008/05/scrollbartest.swf&#8221; quality=&#8221;high&#8221; bgcolor=&#8221;#869ca7&#8243;&lt;br /&gt; 				width=&#8221;500&#8243; height=&#8221;100&#8243; name=&#8221;ScrollBarTest&#8221; align=&#8221;middle&#8221;&lt;br /&gt; 				play=&#8221;true&#8221;&lt;br /&gt; 				loop=&#8221;false&#8221;&lt;br /&gt; 				quality=&#8221;high&#8221;&lt;br /&gt; 				allowScriptAccess=&#8221;sameDomain&#8221;&lt;br /&gt; 				type=&#8221;application/x-shockwave-flash&#8221;&lt;br /&gt; 				pluginspage=&#8221;http://www.adobe.com/go/getflashplayer&#8221;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; </noscript></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=ca4pPiSY"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=8WQfB0LV"><img src="http://feeds.feedburner.com/~f/miletbaker?i=8WQfB0LV" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=J8PzrEBp"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=XN3QNrlb"><img src="http://feeds.feedburner.com/~f/miletbaker?i=XN3QNrlb" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=QI062MgE"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=OlhN8R7f"><img src="http://feeds.feedburner.com/~f/miletbaker?i=OlhN8R7f" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=BEaoEHAm"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/KLOl_4anQWE" height="1" width="1"/>]]></content:encoded><description>A quick tip if you have a dynamic scroll bar and want to bind it&amp;#8217;s maxScrollPosition to a value at runtime unfortunately you can&amp;#8217;t use the MXML binding, i.e. maxScrollPosition={value}.
Alternatively you need to set the value programatically in an event handler, AND importantly call updateDisplayList() on the scrollbar. i.e.

&amp;#160;
		&amp;#60;!--&amp;#91;CDATA&amp;#91;
			private function handleSlideChange&amp;#40;&amp;#41;:void &amp;#123;
				scroll.maxScrollPosition = slider.value;
				scroll.invalidateDisplayList&amp;#40;&amp;#41;;
			&amp;#125;
		&amp;#93;&amp;#93;--&amp;#62;


 
// [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/05/07/changing-flex3-scrollbar-maxscrollposition-at-runtime/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">7</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/05/07/changing-flex3-scrollbar-maxscrollposition-at-runtime/</feedburner:origLink></item><item><title>Updated WP-Flickr</title><link>http://feedproxy.google.com/~r/miletbaker/~3/KINwUkudPmo/</link><category>Misc..</category><category>php</category><category>wp-flickr</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon</dc:creator><pubDate>Mon, 28 Apr 2008 16:20:57 PDT</pubDate><guid isPermaLink="false">http://clockobj.co.uk/?p=88</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Just to let you all know I have updated WP-Flcikr, making it compatible with WordPress 2.5</p>
<p>As part of the update, I have fixed the following:</p>
<ul>
<li>Compatibility with WordPress 2.5</li>
<li>Issue where users without curl installed would get an error authenticating</li>
<li>Updated the style to match WordPress 2.5</li>
<li>AJAX enabled the plugin to stop the page refresh (which ws incompatible with WordPress 2.5) when switching Photo Sets on the write/edit post page</li>
</ul>
<p><img src="http://farm4.static.flickr.com/3214/2449667775_76fc86e339.jpg" alt="wp-flickr" /></p>
<p>If you are using WordPress 2.5, you can automatically upgrade to the latest version from the plugins page. If you are not already using WP-Flickr, you can download it here <a href="http://wordpress.org/extend/plugins/wp-flickr/">http://wordpress.org/extend/plugins/wp-flickr/</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/miletbaker?a=D2CHvFyX"><img src="http://feeds.feedburner.com/~f/miletbaker?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=gGZsB99V"><img src="http://feeds.feedburner.com/~f/miletbaker?i=gGZsB99V" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=ORvhbhEe"><img src="http://feeds.feedburner.com/~f/miletbaker?d=43" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=yRRzRkEj"><img src="http://feeds.feedburner.com/~f/miletbaker?i=yRRzRkEj" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=4anBCNN5"><img src="http://feeds.feedburner.com/~f/miletbaker?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=K8Iyd2M4"><img src="http://feeds.feedburner.com/~f/miletbaker?i=K8Iyd2M4" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/miletbaker?a=AateaQVn"><img src="http://feeds.feedburner.com/~f/miletbaker?d=232" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/miletbaker/~4/KINwUkudPmo" height="1" width="1"/>]]></content:encoded><description>Just to let you all know I have updated WP-Flcikr, making it compatible with WordPress 2.5
As part of the update, I have fixed the following:

Compatibility with WordPress 2.5
Issue where users without curl installed would get an error authenticating
Updated the style to match WordPress 2.5
AJAX enabled the plugin to stop the page refresh (which ws incompatible [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://clockobj.co.uk/2008/04/28/updated-wp-flickr/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">14</slash:comments><feedburner:origLink>http://clockobj.co.uk/2008/04/28/updated-wp-flickr/</feedburner:origLink></item></channel></rss>
