<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hi, I&#039;m Matt.</title>
	<atom:link href="http://mattbilson.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattbilson.com/blog</link>
	<description>I enjoy making things.</description>
	<lastBuildDate>Thu, 26 Jan 2012 08:42:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Awards season at The Bottom Of The World</title>
		<link>http://mattbilson.com/blog/2012/01/awards-season-at-the-bottom-of-the-world/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=awards-season-at-the-bottom-of-the-world</link>
		<comments>http://mattbilson.com/blog/2012/01/awards-season-at-the-bottom-of-the-world/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 08:40:49 +0000</pubDate>
		<dc:creator>mattbilson</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[awards]]></category>
		<category><![CDATA[camry]]></category>
		<category><![CDATA[fwa]]></category>
		<category><![CDATA[mobile of the day]]></category>
		<category><![CDATA[people's champ]]></category>
		<category><![CDATA[pixel award]]></category>
		<category><![CDATA[portfolio]]></category>
		<category><![CDATA[resn]]></category>
		<category><![CDATA[RNZAF]]></category>
		<category><![CDATA[site of the day]]></category>
		<category><![CDATA[threaded]]></category>
		<category><![CDATA[toyota]]></category>

		<guid isPermaLink="false">http://mattbilson.com/blog/?p=139</guid>
		<description><![CDATA[January seems as good a time as any to recap the last year or so of work I&#8217;ve been doing at Resn. And whilst awards certainly aren&#8217;t everything, they&#8217;re the jam that holds this review of the year together. As &#8230; <a href="http://mattbilson.com/blog/2012/01/awards-season-at-the-bottom-of-the-world/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>January seems as good a time as any to recap the last year or so of work I&#8217;ve been doing at Resn. And whilst awards certainly aren&#8217;t everything, they&#8217;re the jam that holds this review of the year together. As mentioned in numerous Resn <a href="http://www.resn.co.nz/#/about/jobs" target="_blank">job ads</a>, &#8220;we love awards because the people who pay us love awards&#8221;.</p>
<p><span id="more-139"></span></p>
<h2>RNZAF &#8211; Step Up</h2>
<p>Firstly, towards the end of last year, the <a href="http://www.youtube.com/rnzaf" target="_blank" alt="RNZAF Challenges : Step Up">game we built for RNZAF</a> &#8211; the Royal New Zealand Air force &#8211; was awarded an <a href="http://www.thefwa.com/site/rnzaf-challenges"  alt="RNZAF Challenges : Step Up - FWA Site of the Day" target="_blank">FWA Site of the Day</a> and a <a href="http://bestawards.co.nz/entries/interactive/rnzaf-challenges/" target="_blank" alt="RNZAF Challenges : Step Up - New Zealand's Best Interactive Design - Bronze">Bronze in New Zealand&#8217;s Best Interactive Design awards</a>.</p>
<p><iframe width="649" height="365" src="http://www.youtube.com/embed/-qxVk7PXiMQ?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>The site allows you to practice being a search and rescue pilot by remotely connecting to a robot on an airbase in <a href="http://maps.google.co.nz/maps?q=blenheim+new+zealand&#038;um=1&#038;ie=UTF-8&#038;hq=&#038;hnear=0x6d390e0080e269bd:0xa00ef88e796a530,Blenheim&#038;gl=nz&#038;ei=TeAXT4RlxbeJB5bqqZ8L&#038;sa=X&#038;oi=geocode_result&#038;ct=image&#038;resnum=1&#038;ved=0CEAQ8gEwAA" target="_blank" alt="just in case you want to visit Blenheim yourself">Blenheim, New Zealand</a> and flying around a specially designed landscape.<br />
Online for only a little longer, <a href="http://www.youtube.com/rnzaf" target="_blank" alt="RNZAF Challenges : Step Up">check it out</a>.</p>
<p><iframe width="649" height="365" src="http://www.youtube.com/embed/0n5-5QB4Gac?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<h2>Threaded</h2>
<p><img src="http://mattbilson.com/blog/wp-content/uploads/2012/01/threaded-e1327563724682.jpg" alt="Profanity, Crude Humor, Horror, Fear, Mature/Suggestive Themes. Free." title="threaded" width="649" height="414" class="size-full wp-image-172" /></p>
<p>Next up, after <a href="https://twitter.com/search/threaded%20resn" target="_blank" alt="It really freaked Twitter out">bending and melting minds on Twitter</a>, the internal Resn creation <a href="http://resn.co.nz/threaded" target="_blank" alt="Threaded : You have been warned">Threaded</a> was awarded an <a href="http://www.thefwa.com/site/threaded" target="_blank" alt="Threaded : FWA Site of the Day">FWA Site of the Day</a>, <a href="http://www.pixelawards.com/nom_win_2011.php" target="_blank" alt="Threaded - Pixel award multi-nominee... Imma let you finish, but...">nominated numerous times at the Pixel Awards</a> and <a href="http://www.netmagazine.com/features/2011-review-years-best-flash-sites" alt="#1 FTW">heralded as the #1 Flash site of 2011</a>.</p>
<p>Originally created as an accompaniment to a magazine and now unleashed <a href="http://resn.co.nz/threaded" target="_blank" alt="Threaded : You have been warned">online</a> and in the <a href="http://itunes.apple.com/us/app/threaded/id491164629?mt=8" target="_blank" alt="iThreaded - get it on your iPad">App Store</a>, it&#8217;s probably best described by Apple :
</p>
<blockquote style="width:75%;"><p>Profanity, Crude Humor, Horror, Fear, Mature/Suggestive Themes. Free.</p></blockquote>
<h2>The Camry Effect</h2>
<p><img src="http://mattbilson.com/blog/wp-content/uploads/2012/01/Screen-Shot-2012-01-26-at-21.02.34-e1327565136266.png" alt="A collection of Camry stories connecting nearly 7 million drivers" title="The Camry Effect" width="648" height="405" class="aligncenter size-full wp-image-178" /><br />
Not content with Pixel Award nominations, <a href="http://www.thefwa.com/site/rnzaf-challenges" target="_blank" alt="The Camry Effect - Sharing the Camry love">The Camry Effect</a> and <a href="http://rhizopods.com/" alt="Rhizopods are for life, not just for Christmas">Rhizopods</a> were selected as <a href="http://www.pixelawards.com/nom_win_2011.php" target="_blank" alt="Humbled by the people">Pixel Award People&#8217;s Champs</a>. And then <a href="http://toyota.com/camryeffect" target="_blank" alt="The Camry Effect - Sharing the Camry love">The Camry Effect</a> received an <a href="http://www.thefwa.com/mobile/the-camry-effect-gqq" target="_blank" alt="The Camry Effect - FWA Mobile of the Day">FWA Mobile of the Day award</a>. Built to target both multiple languages and multiple devices using HTML and Flash, The Camry Effect is a place for Toyota Camry owners to share their stories and experience the global effect that the car has had on so many lives. </p>
<h2>2012</h2>
<p>Far from being the &#8220;difficult second album&#8221;, 2012 is already set up to blow 2011 out of the water. Stay tuned.</p>
<p class="small">FYI, my role in these projects was technical director-ing and prototyping, along with a sprinkling of production code. No risqu&eacute; serious dev needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattbilson.com/blog/2012/01/awards-season-at-the-bottom-of-the-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Refactoring with Sass &amp; Compass &#8211; the CSS of your dreams</title>
		<link>http://mattbilson.com/blog/2011/12/refactoring-with-sass-and-compass-the-css-of-your-dreams/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=refactoring-with-sass-and-compass-the-css-of-your-dreams</link>
		<comments>http://mattbilson.com/blog/2011/12/refactoring-with-sass-and-compass-the-css-of-your-dreams/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 07:53:21 +0000</pubDate>
		<dc:creator>mattbilson</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Compass]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[Sass]]></category>

		<guid isPermaLink="false">http://mattbilson.com/blog/?p=122</guid>
		<description><![CDATA[Having themed this blog in fleeting moments spread over a few months, the CSS was in need of a healthy dose of refactoring. I had been keen to try out Sass and Compass after having heard about them at WDCNZ, &#8230; <a href="http://mattbilson.com/blog/2011/12/refactoring-with-sass-and-compass-the-css-of-your-dreams/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Having themed this blog in fleeting moments spread over a few months, the CSS was in need of a healthy dose of refactoring. I had been keen to try out <a title="Sass" href="http://sass-lang.com/" target="_blank">Sass</a> and <a title="Compass" href="http://compass-style.org/" target="_blank">Compass</a> after having heard about them at <a title="WDCNZ" href="http://lanyrd.com/2011/wdcnz/" target="_blank">WDCNZ</a>, and this seemed like a perfect scenario.</p>
<p><span id="more-122"></span></p>
<h2>Getting up and running</h2>
<p>Installation was super easy :</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> compass
compass create <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>project <span style="color: #c20cb9; font-weight: bold;">dir</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p><small>(There are more detailed steps <a title="Detailed steps to install Sass and Compass" href="http://thesassway.com/beginner/getting-started-with-sass-and-compass" target="_blank">here</a> if you&#8217;re sans-Ruby or still getting to grips with the command line.)</small></p>
<p>By default, compass auto-generates scss and corresponding css files for IE, print and screen. For this WordPress theme, I needed just a styles.css file in the root of the theme, so I removed the default files and tweaked the config.rb file to show Compass who&#8217;s boss:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">http_path = <span style="color:#996600;">&quot;/&quot;</span>
css_dir = <span style="color:#996600;">&quot;&quot;</span>
sass_dir = <span style="color:#996600;">&quot;sass&quot;</span>
images_dir = <span style="color:#996600;">&quot;images&quot;</span>
javascripts_dir = <span style="color:#996600;">&quot;javascripts&quot;</span></pre></div></div>

<p>One of the best bits of Sass, or more specifically the scss syntax, is that a regular css file is already an scss file. So I moved my style.css file into the sass directory and renamed it to style.scss.</p>
<p>Next, I told compass to watch the sass directory, and compile my scss into css whenever it detects a change :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">compass <span style="color: #c20cb9; font-weight: bold;">watch</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>project <span style="color: #c20cb9; font-weight: bold;">dir</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>And Bob&#8217;s your uncle&#8230; a new CSS file. We&#8217;re up and running.</p>
<h2>Refactoring</h2>
<p>Up until this adventure with Sass, the CSS for this blog had been full of small experiments and fragments of long forgotten layouts. The finer points of the design were made up as I went along, and there was only ever time to work on it every now and then.<br />
So the first thing I did was to organise the code a little better using partials and nesting.</p>
<h3>Partials &amp; Nesting</h3>
<p><a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#partials">Partials</a> allow you to break your scss file up in to numerous files. I created _tables.scss and _typography.scss &#8211; styles for data tables within an old post and the site-wide typography styles. Naming the file with an underscore tells Sass not to compile it into a css file, but just to import it as scss when requested, like so :</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@import &quot;typography&quot;;</span>
<span style="color: #a1a100;">@import &quot;tables&quot;;</span></pre></div></div>

<p>This is clearly a nicer way to organise groups of rules that are relatively independent. Have you ever worked on a seemingly endless CSS file that contained multi-line comments full of uppercase text trying to grab your attention and separate the different sections of the file? This fixes that.</p>
<p>And because Sass compiles these partials up in to the file they&#8217;re imported by, you only end up with one CSS file and your number of HTTP requests stays low. Double win.</p>
<p><a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#nested_rules">Nesting</a> helps you keep these individual files in even better shape and make your code an order of magnitude more readable. I went to town with these, starting with small tweaks to readability :</p>
<div class="before-and-after">
<div class="before">

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/** Before - CSS **/</span>
th<span style="color: #00AA00;">,</span> td <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">6px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> $tableBorder<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
th<span style="color: #3333ff;">:last-child</span><span style="color: #00AA00;">,</span> td<span style="color: #3333ff;">:last-child </span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

</div>
<div class="after">

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/** After - SCSS **/</span>
th<span style="color: #00AA00;">,</span> td <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">6px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> $tableBorder<span style="color: #00AA00;">;</span>
  &amp;<span style="color: #3333ff;">:last-child </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

</div>
</div>
<p>and then moving on to organising related styles together under one parent rule.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#latest-tweet</span> <span style="color: #00AA00;">&#123;</span>
  word-wrap<span style="color: #3333ff;">:break-</span>word<span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span>
&nbsp;
  p <span style="color: #00AA00;">&#123;</span>
    &amp;<span style="color: #3333ff;">:BEFORE </span><span style="color: #00AA00;">&#123;</span>  <span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span><span style="color: #993333;">open-quote</span><span style="color: #00AA00;">;</span>  <span style="color: #00AA00;">&#125;</span>
    &amp;<span style="color: #3333ff;">:AFTER </span><span style="color: #00AA00;">&#123;</span>   <span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span><span style="color: #993333;">close-quote</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  a <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    &amp;<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Much nicer.</p>
<p>Using partials and nesting was a great help in refactoring the code to make it more organised and readable. These features are also invaluable at making it clear which old styles need removing and re-writing, and also making the process of doing this painless.</p>
<p>Just don&#8217;t take it to the extreme and break <a href="http://thesassway.com/beginner/the-inception-rule" title"The Inception Rule">the Inception rule</a>. You&#8217;ve been warned.</p>
<h3>SassScript &#8211; variables and logic</h3>
<p>Spending most of my days writing programming code rather than CSS, there were often moments when it seemed like variables, logic, math, conditionals or loops could make CSS less of a beast. Yet another thing that Sass has under control.</p>
<p>Variables helped reduce the repetition in the file too. <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a> FTW :</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">$color1<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#33c9f4</span><span style="color: #00AA00;">;</span>
$color2<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#37c7bd</span><span style="color: #00AA00;">;</span>
$color3<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fccd0d</span><span style="color: #00AA00;">;</span>
$color4<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ff8e10</span><span style="color: #00AA00;">;</span>
$color5<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ef4b1a</span><span style="color: #00AA00;">;</span>
$color6<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#897f7e</span><span style="color: #00AA00;">;</span>
&nbsp;
$darkgrey<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#444</span><span style="color: #00AA00;">;</span>
$borderStyle<span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">dotted</span> <span style="color: #cc00cc;">#C9C9C9</span><span style="color: #00AA00;">;</span>
$totalWidth<span style="color: #00AA00;">:</span><span style="color: #933;">800px</span><span style="color: #00AA00;">;</span>
$sidebarWidth<span style="color: #00AA00;">:</span><span style="color: #933;">209px</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>Next up was a <a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#id11">for loop</a> to help manage the color blocks. I already had some selectors which used the color variables, so I referenced these using the <a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#extend" title="@extend directive" target="_blank">@extend directive</a>. Here&#8217;s the before and after :</p>
<div class="before-and-after">
<div class="before">

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/** Before - CSS **/</span>
.color-<span style="color: #993333;">block</span> .<span style="color: #000000; font-weight: bold;">color</span><span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>5n<span style="color: #00AA00;">+</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
   <span style="color: #a1a100;">@extend .color1;</span>
   <span style="color: #808080; font-style: italic;">/** ... **/</span>
<span style="color: #00AA00;">&#125;</span>
.color-<span style="color: #993333;">block</span> .<span style="color: #000000; font-weight: bold;">color</span><span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>5n<span style="color: #00AA00;">+</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #a1a100;">@extend .color2;</span>
  <span style="color: #808080; font-style: italic;">/** ... **/</span>
<span style="color: #00AA00;">&#125;</span>
.color-<span style="color: #993333;">block</span> .<span style="color: #000000; font-weight: bold;">color</span><span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>5n<span style="color: #00AA00;">+</span><span style="color: #cc66cc;">3</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #a1a100;">@extend .color3;</span>
  <span style="color: #808080; font-style: italic;">/** ... **/</span>
<span style="color: #00AA00;">&#125;</span>
.color-<span style="color: #993333;">block</span> .<span style="color: #000000; font-weight: bold;">color</span><span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>5n<span style="color: #00AA00;">+</span><span style="color: #cc66cc;">4</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #a1a100;">@extend .color4;</span>
  <span style="color: #808080; font-style: italic;">/** ... **/</span>
<span style="color: #00AA00;">&#125;</span>
.color-<span style="color: #993333;">block</span> .<span style="color: #000000; font-weight: bold;">color</span><span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>5n<span style="color: #00AA00;">+</span><span style="color: #cc66cc;">5</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #a1a100;">@extend .color5;</span>
  <span style="color: #808080; font-style: italic;">/** ... **/</span>
<span style="color: #00AA00;">&#125;</span>
.color-<span style="color: #993333;">block</span> .<span style="color: #000000; font-weight: bold;">color</span><span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>5n<span style="color: #00AA00;">+</span><span style="color: #cc66cc;">6</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #a1a100;">@extend .color6;</span>
  <span style="color: #808080; font-style: italic;">/** ... **/</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

</div>
<div class="after">

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/** After - SCSS **/</span>
<span style="color: #a1a100;">@for $i from 1 through 6 {</span>
  .color-<span style="color: #993333;">block</span> .<span style="color: #000000; font-weight: bold;">color</span><span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>5n<span style="color: #00AA00;">+</span>#<span style="color: #00AA00;">&#123;</span>$i<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #a1a100;">@extend .color#{$i};</span>
    <span style="color: #808080; font-style: italic;">/** ... **/</span>
  <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

</div>
</div>
<h3>Mixins</h3>
<p>I experimented with <a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixins">mixins</a> and other notable Sass features which seemed very useful. However in the case of this simple blog I found that refactoring my CSS even further meant these features were un-needed and that I could accomplish the same result with a more basic approach. Credit again to Sass for making this refactoring super easy and improving the clarity of what was previously a monster css file.</p>
<h2>Tools</h2>
<div class="quote">
<blockquote cite="http://pragprog.com/the-pragmatic-programmer"><p>Every craftsman starts his or her journey with a basic set of good-quality tools.</p></blockquote>
<p><cite><a title="The Pragmatic Programmer" href="http://pragprog.com/the-pragmatic-programmer" target="_blank">The Pragmatic Programmer</a></cite></p>
</div>
<p>Great book, wise words. Tools that I found useful for Sass development included:</p>
<ul>
<li>
<h4><a title="Aptana" href="http://aptana.com/" target="_blank">Aptana</a></h4>
<p>Sometimes seems to slow Eclipse to a crawl, but it comes with Sass code highlighting and includes a Terminal view, which is super handy when using Compass to compile your code. If you do this in a regular Terminal window behind Eclipse, you&#8217;ll miss any errors it throws, and wonder why your site hasn&#8217;t updated with your changes when you switch to your browser. With the Terminal view in Aptana, you can see the Compass output right below your code.<br />
Also, the default colour theme uses a black background. This will make you look super-professional in front of your friends.</li>
<li>
<h4><a title="Codekit" href="http://incident57.com/codekit/" target="_blank">CodeKit</a></h4>
<p>This app lurks in the background watching you. When you update a file it will perform all sorts of pre-processing and compilation and then refresh the site in your browser. By the time you&#8217;ve switched to the browser, your code is already there. May only save you a second or two each time, but every little helps.<br />
As well as Sass and Compass, it also includes support for Less, Coffeescript, minifying and error-checking Javascript, optimising images and more.</li>
<li>
<h4>css_parser</h4>
<p>I like a good stat, and using compass stats on the command line gives me my fix. It shows the number of rules, properties and mixins for each sass file. Installing the css_parser gem (gem install css_parser) takes this a step further and shows you how many CSS rules and properties this is compiled in to.</li>
<li>
<h4><a title="Sass Documentation" href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html" target="_blank">Documentation</a></h4>
<p>The Sass documentation is clear, comprehensive and also highlights relatively minor features, such as <a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#comments" title="Single line vs. multiline" target="_blank">Sass comments vs. CSS comments</a>.</li>
</ul>
<h2>Next steps</h2>
<p>Now the building blocks are in place, my next steps will be to delve deeper into Compass and to use Sass variables and media queries to make implementing a responsive design even easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattbilson.com/blog/2011/12/refactoring-with-sass-and-compass-the-css-of-your-dreams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Font Embedding Using MXMLC Compilation</title>
		<link>http://mattbilson.com/blog/2010/08/flash-font-embedding-using-mxmlc-compilation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=flash-font-embedding-using-mxmlc-compilation</link>
		<comments>http://mattbilson.com/blog/2010/08/flash-font-embedding-using-mxmlc-compilation/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 20:33:12 +0000</pubDate>
		<dc:creator>mattbilson</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[multi-language]]></category>
		<category><![CDATA[mxmlc]]></category>
		<category><![CDATA[rolex]]></category>
		<category><![CDATA[specialmoves]]></category>

		<guid isPermaLink="false">http://localhost/Blog/?p=53</guid>
		<description><![CDATA[Ever since the early days of Flash, embedding fonts and supporting both multiple and large characters sets has been somewhat of a sticking point. Whilst support for various intricacies of font loading and embedding has gradually improved with each version, &#8230; <a href="http://mattbilson.com/blog/2010/08/flash-font-embedding-using-mxmlc-compilation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ever since the early days of Flash, embedding fonts and supporting both multiple and large characters sets has been somewhat of a sticking point. Whilst support for various intricacies of font loading and embedding has gradually improved with each version, there are some inherent difficulties.</p>
<p>One big difficulty is handling the embedding of large character sets such as Japanese and Chinese.</p>
<p>This post will present the fully automated font embedding solution we used for a 500 page site available in eleven languages (including Traditional Chinese and Japanese) which is regularly updated by users of a bespoke CMS.</p>
<p><span id="more-57"></span></p>
<h2>The problem</h2>
<p>Generally, a Flash site in English will need to embed the characters a to z (upper and lowercase), 0 to 9 and punctuation. A SWF containing just these characters in Arial comes in at 12kb. Supporting other Western European languages, such as French, Spanish and Italian requires adding only a handful more accented characters. The problem comes when building a Flash site in languages such as Traditional Chinese and Japanese which have much larger character sets.</p>
<p>As you can see from the table below, if you were to embed all the characters, the user would have to wait a substantial amount of time before they can see any text on your site.</p>
<div id="flash-font-embedding-comparison-table">
<div id="table-container">
<table>
<thead>
<tr>
<th>Character set</th>
<th>Number of glyphs</th>
<th>SWF File size*</th>
<th>Font used</th>
</tr>
</thead>
<tbody>
<tr>
<td>Traditional Chinese</td>
<td>18439</td>
<td>6mb</td>
<td>DF Hei HK</td>
</tr>
<tr>
<td>Japanese</td>
<td>7517</td>
<td>2.9mb</td>
<td>A-OTF Midashi MB31 Pro</td>
</tr>
<tr>
<td>English</td>
<td>114</td>
<td>12kb</td>
<td>Arial</td>
</tr>
</tbody>
</table>
<div class="footnote">* with all glyphs in this character set embedded.</div>
</div>
</div>
<p>There are numerous approaches to this problem, which include:</p>
<ul>
<li>Using a font of your choice for languages with small character sets, and defaulting to a system font (_sans or _serif in Flash) for languages with large character sets. However this means that styled, designed and intricately laid out typography is sacrificed in the name of convenience. Also, it&#8217;s not possible to adjust the rotation properties of text in a system font, so this approach limits animations and transitions that can be applied to the text without a work around such as converting it to a bitmap.</li>
<li>Manually telling Flash which characters to embed. However, if the copy in the site is likely to change, this approach will make deploying changes painful and impossible to automate.</li>
<li>Create a custom font which contains just the characters used in the site, and embed the whole custom font in the site. However, similarly to above, if the copy in the site is likely to change, deploying an update becomes a laborious, manual process involving font editing software.</li>
</ul>
<p>A quick Google search reveals many other approaches and whilst at the end of the day it depends on the nature of the site being created, here is the approach we took.</p>
<h2>Our approach &#8211; automated, server-side, command line embedding</h2>
<p>This approach was developed to meet the following requirements :</p>
<ul>
<li>The site should display text in custom fonts wherever possible.</li>
<li>The font file downloaded by the user should be as small as possible &#8211; no superfluous characters increasing loading times.</li>
<li>There should be no manual aspect to the process &#8211; as developers, we shouldn&#8217;t need to be involved in the deployment process, this is something the client can do themselves using our bespoke CMS. The font handling system should also be invisible to the CMS user. When previewing and deploying updates, they should instantly see new characters in the custom font. As <a title="Apple - It just works" href="http://apple.com" target="_blank">Steve</a> would say, &#8220;It just works”.</li>
</ul>
<p>The process currently runs on .NET 3.5 on an IIS 7.5 server, and goes like this&#8230;</p>
<ol>
<li>A .NET application, running as a scheduled task, polls the database for changes made by a user of the CMS. N.B. For other sites, the script could just as easily check for changes in XML or JSON files.</li>
<li>Upon finding a change, the .NET application takes all the user-facing text from the database for the version of the site being updated (i.e. if the content of the site being updated is a Chinese page, only the Chinese font is updated.)</li>
<li>It then parses this text to remove duplicate characters, leaving a comprehensive list of all the characters which could be displayed to a user viewing the site in this language.</li>
<li>Next, it converts this to a list of comma separated unicode values which represent the characters.</li>
<li>The application then inserts this comma separated list of unique unicode values into a template ActionScript file which is used as the document class for the font library SWF. There are different ActionScript templates for each version (language) of the site, due to different fonts being used in each. Here&#8217;s an example of the Japanese file :
<div class="wide-code">

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>example <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: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>CLASSNAME<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;../../fonts/A-OTF-FutoGoB101Pro-Bold.otf&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">fontName</span> = <span style="color: #990000;">&quot;HeadingFont&quot;</span><span style="color: #000066; font-weight: bold;">,</span> fontWeight=<span style="color: #990000;">&quot;bold&quot;</span><span style="color: #000066; font-weight: bold;">,</span> mimeType = <span style="color: #990000;">&quot;application/x-font&quot;</span><span style="color: #000066; font-weight: bold;">,</span> unicodeRange = <span style="color: #990000;">&quot;[[CHARLIST]]&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> headingFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;../../fonts/A-OTF-GothicBBBPro-Medium.otf&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">fontName</span> = <span style="color: #990000;">&quot;BodyFont&quot;</span><span style="color: #000066; font-weight: bold;">,</span> mimeType = <span style="color: #990000;">&quot;application/x-font&quot;</span><span style="color: #000066; font-weight: bold;">,</span> unicodeRange = <span style="color: #990000;">&quot;[[CHARLIST]]&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> bodyFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;../../fonts/A-OTF-MidashiGoPro-MB31.otf&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">fontName</span> = <span style="color: #990000;">&quot;MinorFont&quot;</span><span style="color: #000066; font-weight: bold;">,</span> mimeType = <span style="color: #990000;">&quot;application/x-font&quot;</span><span style="color: #000066; font-weight: bold;">,</span> unicodeRange = <span style="color: #990000;">&quot;[[CHARLIST]]&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> minorFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>CLASSNAME<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">registerFont</span><span style="color: #000000;">&#40;</span>headingFont<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">registerFont</span><span style="color: #000000;">&#40;</span>bodyFont<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">registerFont</span><span style="color: #000000;">&#40;</span>minorFont<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div>
<p>The application searches the file for double square brackets, and replaces these with the necessary values for this class; [[CLASSNAME]] is replaced with the language, and [[CHARLIST]] is replaced with the list of unicode values. The template ActionScript files use Embed meta-tags to embed the font into this SWF at compile time. The parameters of the meta tag can restrict the characters being embedded to just those needed &#8211; the list of Unicode values representing every character needed in the site &#8211; rather than the whole font. Also in the meta-tag, each font is given a fontName &#8211; HeadingFont, BodyFont or MinorFont &#8211; depending on where they will be used in the site. This name is how the font is referred to by CSS or TextFormat objects within Flash. Each language version of the site uses slightly differing fonts to ensure good readability and complete character set coverage. Using the fontName attribute ensures that the code of the site can use this generic name, rather than using the specific name of the font, which will change depending on which language the site is being viewed in. When run, the constructor of the class registers the font with the global Font object, ensuring that the embedded glyphs will be available to any site SWF which loads in this font library SWF.
</li>
<li>The application then uses command line compilation (<a title="Flex 4 Documentation for mxmlc" href="http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fcc.html" target="_blank">mxmlc</a>) to compile this class into a SWF. Here&#8217;s an example mxmlc command :
<div class="wide-code">

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mxmlc <span style="color: #660033;">-o</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>rootDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>Webrootfonts<span style="color: #7a0874; font-weight: bold;">&#123;</span>lang<span style="color: #7a0874; font-weight: bold;">&#125;</span>.swf
	<span style="color: #660033;">-sp</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>rootDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>FontGeneratorsrccomexample
	<span style="color: #660033;">-library-path</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>flexSDKDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>frameworkslocaleen_US
	<span style="color: #660033;">-library-path</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>flexSDKDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>frameworkslibsplayer10playerglobal.swc
	<span style="color: #660033;">-library-path</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>flexSDKDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>frameworkslibsflex.swc
	<span style="color: #660033;">-library-path</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>flexSDKDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>frameworkslibsframework.swc
	<span style="color: #660033;">-library-path</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>flexSDKDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>frameworkslibsrpc.swc
	<span style="color: #660033;">-library-path</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>flexSDKDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>frameworkslibsutilities.swc
	<span style="color: #660033;">-managers</span>=flash.fonts.AFEFontManager
	<span style="color: #660033;">-default-size</span> <span style="color: #000000;">550</span> <span style="color: #000000;">400</span>
	<span style="color: #660033;">-default-frame-rate</span> <span style="color: #000000;">31</span>
	<span style="color: #660033;">-default-background-color</span> 0xFFFFFF
	<span style="color: #660033;">-target-player</span>=<span style="color: #000000;">10</span>
	<span style="color: #660033;">-debug</span>=<span style="color: #c20cb9; font-weight: bold;">false</span>
	<span style="color: #660033;">--</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>rootDir<span style="color: #7a0874; font-weight: bold;">&#125;</span>FontGeneratorsrccomexample<span style="color: #7a0874; font-weight: bold;">&#123;</span>lang<span style="color: #7a0874; font-weight: bold;">&#125;</span>.as</pre></div></div>

</div>
</li>
<li>Finally, the application uploads the SWF into the appropriate location on the server and increments a font file version number property.</li>
<li>The code which loads this SWF into the site appends this version number to the SWF&#8217;s url as part of a query string &#8211; e.g. <em>&#8220;fonts/japanese.swf?fv=15&#8243;</em>. This ensures the SWF is cached by the user&#8217;s browser between visits, until it is superseded by a new version.</li>
</ol>
<h2>Advantages of this approach</h2>
<p>The main advantage of this approach is the file size; only necessary characters are embedded, keeping file size as low as possible. The Japanese font file used was 1.6mb, this contains 3 fonts, and if the whole Japanese character set was embedded in each font, the file size would be 9.8mb.</p>
<p>Secondly, the process is entirely automated. Triggered by a CMS user&#8217;s actions, .NET compiles and deploys the font file. It involves no human interaction. As well as reducing the time it takes to update and deploy the site, this also reduces the opportunity for human error.</p>
<h2>Disadvantages</h2>
<p>One disadvantage is that the font compilation system needs to know the characters which need to be displayed in the site before it can compile them into a SWF.</p>
<p>This means that for input fields, we use a system font. This is an extremely minor issue due to the rare use of input fields in this site, and due to the nature of system fonts, it also ensures that input fields are as clear and readable as possible.</p>
<h2>The future</h2>
<p>One improvement we&#8217;re working on is to only embed characters in the fonts they will be shown in. For example, if the character &#8216;Z&#8217; is only used in headings in a site, why embed it in the body font?</p>
<p>Hopefully knowledge of this approach will help others in creating similar sites in the future. If you have a unique approach to font embedding, have worked on a site that would benefit from this system, or have any tips, thoughts or recommendations, then let us know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattbilson.com/blog/2010/08/flash-font-embedding-using-mxmlc-compilation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Data Transfer using FluorineFx</title>
		<link>http://mattbilson.com/blog/2010/05/flash-data-transfer-using-fluorinefx/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=flash-data-transfer-using-fluorinefx</link>
		<comments>http://mattbilson.com/blog/2010/05/flash-data-transfer-using-fluorinefx/#comments</comments>
		<pubDate>Wed, 19 May 2010 21:27:14 +0000</pubDate>
		<dc:creator>mattbilson</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://localhost/Blog/?p=20</guid>
		<description><![CDATA[Recently at specialmoves, we&#8217;ve worked on some very large, multi-language, bespoke CMS driven sites. The Flash versions of these sites require many calls to the back-end (.NET) to send and retrieve data. One approach would have been to transfer all &#8230; <a href="http://mattbilson.com/blog/2010/05/flash-data-transfer-using-fluorinefx/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently at specialmoves, we&#8217;ve worked on some very large, multi-language, bespoke CMS driven sites. The Flash versions of these sites require many calls to the back-end (.NET) to send and retrieve data.</p>
<p>One approach would have been to transfer all of this data in XML or JSON. However we turned to <a title="FluorineFX" href="http://www.fluorinefx.com/" target="_blank">FluorineFx</a> which is a Flash (and Flex) remoting framework for .NET which facilitates data transfer using <a title="Wikipedia page on AMF - also links to the spec" href="http://en.wikipedia.org/wiki/Action_Message_Format" target="_blank">AMF</a> (ActionScript Message Format.) It is similar in functionality to <a title="BlazeDS on Adobe.com" href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/" target="_blank">BlazeDS</a> (for Java) and <a title="ZendAMF" href="http://framework.zend.com/download/amf" target="_blank">ZendAMF</a> (for PHP).</p>
<p>This article is going to show how easy it is to use Fluorine in a Flash site, and introduce the ActionScript classes we&#8217;ve written to make it even simpler!</p>
<p><span id="more-56"></span></p>
<h2>Why?</h2>
<p>Fluorine removes the need for coding your own serialization (converting back-end data into XML or JSON) and deserialization (converting the XML or JSON into ActionScript objects) by transferring data in AMF &#8211; a binary form of ActionScript. Because Fluorine takes care of this &#8216;behind the scenes&#8217;, there are two fewer steps of the data transfer process for you to build, which saves time and reduces the opportunity for errors.</p>
<p>Also, due to the structure of the data (raw binary ActionScript &#8211; no XML or JSON markup) it is smaller in size, improving the speed of communication with the back-end.</p>
<p>More general information on FluorineFX can be found at the <a title="FluorineFx" href="http://fluorinefx.com/" target="_blank">main site</a> (including information on using Fluorine with Silverlight and AJAX.)</p>
<h2>How?</h2>
<h3><strong>Configure .NET</strong></h3>
<p>So, to set Fluorine up within your .NET project, you just need to add a .dll to your project and a few lines to your web.config file :</p>
<div class="wide-code">

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- Reflection optimizer provider=&quot;codedom|il&quot; debug=&quot;true|false&quot; --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- &lt;optimizer provider=&quot;codedom&quot; debug=&quot;true&quot; /&gt; --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdlGenerateProxyClasses<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdlGenerateProxyClasses<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdlProxyNamespace<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FluorineFx.Proxy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdlProxyNamespace<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- Time Zone Compensation =&quot;none|auto&quot; --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- &lt;timezoneCompensation&gt;none&lt;/timezoneCompensation&gt;  --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- Any value-type that is not explicitly initialized with a value will contain the default value for that object type --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;acceptNullValueTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/acceptNullValueTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- value=&quot;browse|access&quot; --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- &lt;remotingServiceAttribute&gt;browse&lt;/remotingServiceAttribute&gt; --&gt;</span></pre></div></div>

</div>
<p>Merge these nodes into the equivalent nodes in your web.config file, and you should be good to go.</p>
<h3><strong>ActionScript &#8211; Class Mapping</strong></h3>
<p>Within Flash, the first step is to map the .NET classes to their equivalent ActionScript classes.</p>
<p>This is done using flash.net.registerClassAlias :</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">registerClassAlias<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;com.specialmoves.example.Cake&quot;</span>, CakeVO<span style="color: #66cc66;">&#41;</span>;
registerClassAlias<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;com.specialmoves.example.Slice&quot;</span>, SliceVO<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This code tells Fluorine that our ActionScript class CakeVO is equivalent to the .NET class com.specialmoves.example.Cake.</p>
<p>N.B. In Flex this can be done using a meta tag above the class definition :</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>RemoteClass<span style="color: #66cc66;">&#40;</span>alias=<span style="color: #ff0000;">&quot;com.specialmoves.example.Cake&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span></pre></div></div>

<h3><strong>ActionScript &#8211; Connecting to .NET</strong></h3>
<p>To make a connection, we use Flash&#8217;s NetConnection object, making sure to specify the correct encoding.</p>
<p>Here we are connecting to a hypothetical Fluorine gateway at http://www.specialmoves.com/example/Gateway.aspx.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">_connection = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
_connection.<span style="color: #006600;">objectEncoding</span> = ObjectEncoding.<span style="color: #006600;">AMF3</span>;
_connection.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.specialmoves.com/example/Gateway.aspx&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Now we have an open connection, we can start making some calls.</p>
<h3><strong>Call and Response</strong></h3>
<p>Here&#8217;s an example of making a call and receiving a response :</p>
<div class="wide-code">

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getSlice<span style="color: #66cc66;">&#40;</span>sliceType : <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">var</span> getSliceResponder : Responder = <span style="color: #000000; font-weight: bold;">new</span> Responder<span style="color: #66cc66;">&#40;</span>getSliceSuccessHandler, getSliceFailHandler<span style="color: #66cc66;">&#41;</span>;
   _connection.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;com.specialmoves.example.Cake.GetSlice&quot;</span>, getSliceResponder, sliceType<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> getSliceSuccessHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">slice</span> : SliceVO<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
   <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;We have cake! Is it iced? &quot;</span> + <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">hasIcing</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onFailed<span style="color: #66cc66;">&#40;</span>result : <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: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;What? Why no cake? &quot;</span> + result<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'description'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</div>
<p>Firstly, in the getSlice function, we create a responder, which defines 2 handlers; a function for a successful call, and a function for a failed call.</p>
<p>Next we make the call using the connection instance which is connected to our Fluorine gateway. The first argument in the _connection.call method is the method name to call on the back-end (the GetSlice method of the Cake class), the second is the responder, and any arguments after this are used as arguments in the GetSlice method.</p>
<p>The C#, .NET implementation of the Cake class would look something like this :</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">FluorineFx</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> com<span style="color: #008000;">.</span><span style="color: #0000FF;">specialmoves</span><span style="color: #008000;">.</span><span style="color: #0000FF;">example</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cake</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #008000;">&#91;</span>RemotingService<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Cake&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Cake <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">public</span> Slice<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> slices <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> Slice GetSlice<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sliceType<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">//get the slice from the database...</span>
			<span style="color: #008080; font-style: italic;">//and then return it</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> slice<span style="color: #008000;">;</span>
        	<span style="color: #008000;">&#125;</span>
    	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The main things to note here are that line 5 lets Fluorine know that this class contains methods for Flash to call, and that the GetSlice method returns a Slice object, rather than a serialized, XML or JSON representation of a Slice object.</p>
<p>As for handing this returned object in Flash, that&#8217;s simple&#8230;</p>
<p>A failed call returns an object to the failHandler which contains information about the error to aid debugging and error handling.</p>
<p>The success handler receives a typed object &#8211; SliceVO, ready to be used in ActionScript, rather than a chunk of XML or JSON which needs deserializing.</p>
<p>Whilst this may seem like a trivial example, when developing a 500 page Flash site available in 11 languages, a fast, simple and reliable approach to data transfer can save a lot of time and headaches!</p>
<p>As can a good tool for debugging, introducing Charles&#8230;</p>
<h3><strong>Debugging AMF data transfer</strong></h3>
<p><a title="Charles Web Debugging Proxy" href="http://www.charlesproxy.com/" target="_blank">Charles</a> is a web proxy &#8211; it lets you view web traffic being sent and received by your machine. A tool such as this is essential when working on sites which depend on custom data structures and bespoke CMS&#8217;s &#8211; it can help you diagnose and fix bugs quickly and easily. What sets Charles apart from tools like <a title="Firebug" href="http://getfirebug.com/" target="_blank">Firebug</a> is that it understands AMF and shows AMF requests/responses in a clear tree structure. This makes it incredibly useful when working with Fluorine connections (and any other form of Flash Remoting.) Charles also provides connection throttling, repeat requests and request editing, as well as many other useful features.</p>
<h2><strong>Specialmoves Labs Libraries : FluorineConnection</strong></h2>
<p>Whilst implementing Fluorine connectivity in our own projects, we’ve created a few classes which make creating, configuring and debugging Fluorine connections incredibly simple :</p>
<div class="wide-code">

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> fluorineConnection : IFluorineConnection = <span style="color: #000000; font-weight: bold;">new</span> FluorineConnection<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> FluorineConfig<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/Gateway.aspx&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
fluorineConnection.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FluorineErrorEvent.<span style="color: #006600;">CONNECT_ERROR</span>, errorHandler, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
fluorineConnection.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FluorineErrorEvent.<span style="color: #006600;">CALL_ERROR</span>, errorHandler, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> responder : Responder = <span style="color: #000000; font-weight: bold;">new</span> Responder<span style="color: #66cc66;">&#40;</span>onSuccess, FluorineUtils.<span style="color: #006600;">onError</span><span style="color: #66cc66;">&#41;</span>;
fluorineConnection.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Cake.GetSlice&quot;</span>, responder, sliceType<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

</div>
<p>To find out more, see full examples and download these classes to use in your own projects, view the project on <a title="FluorineConnection on GitHub" href="http://github.com/specialmoves/FluorineConnection" target="_blank">GitHub</a>.</p>
<p>And if you have any comments, questions or ideas let us know below.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattbilson.com/blog/2010/05/flash-data-transfer-using-fluorinefx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

