<?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>BiofusionDesign &#187; Programming</title>
	<atom:link href="http://www.biofusiondesign.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.biofusiondesign.com</link>
	<description>Data you can touch</description>
	<lastBuildDate>Thu, 26 Aug 2010 19:36:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Visualization of our solar system in CSS3</title>
		<link>http://www.biofusiondesign.com/2010/05/31/visualization-of-our-solar-system-in-css3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=visualization-of-our-solar-system-in-css3</link>
		<comments>http://www.biofusiondesign.com/2010/05/31/visualization-of-our-solar-system-in-css3/#comments</comments>
		<pubDate>Mon, 31 May 2010 15:30:30 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Alex Girón]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[solar system]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://biofusiondesign.com/?p=824</guid>
		<description><![CDATA[Click on image to view the page. You may need a more up-to-date browser to view this. Alex Girón of nclud created this visualization of our solar system by using only HTML and CSS3. In his words: These past few months I’ve been exploring CSS3, trying to learn some of it’s new fea­tures and getting [...]


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/' rel='bookmark' title='Permanent Link: Visualization of HTML5 &amp; CSS3 readiness on different browsers'>Visualization of HTML5 &amp; CSS3 readiness on different browsers</a></li>
<li><a href='http://www.biofusiondesign.com/2010/06/20/world-cup-twitter-visualization-from-the-guardian/' rel='bookmark' title='Permanent Link: World Cup twitter visualization from the Guardian'>World Cup twitter visualization from the Guardian</a></li>
<li><a href='http://www.biofusiondesign.com/2008/12/17/handmade-fonts/' rel='bookmark' title='Permanent Link: Handmade fonts'>Handmade fonts</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://neography.com/experiment/circles/solarsystem/"><img src="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/oursolarsystem-590x505.png" alt="" title="oursolarsystem" width="590" height="505" class="alignnone size-large wp-image-825" /></a></p>
<p><em>Click on image to view the page. You may need a more <a href="http://www.google.com/chrome">up-to-date browser</a> to view this.</em></p>
<p><a href="http://neography.com/journal/our-solar-system-in-css3/">Alex Girón</a> of <a href="http://nclud.com/">nclud</a> created this visualization of our solar system by  using only HTML and CSS3. In his words: </p>
<blockquote><p>These past few months I’ve been exploring CSS3, trying to learn some of it’s new fea­tures and getting a feel for which browsers support it. A few weeks back I put out my first experiment exploring @font-face and transforms. This time, I set out to experiment with border-radius, and what I thought was going to be a boring little project turned out to be quite interesting.
</p></blockquote>
<p>via <a href="http://veerle.duoh.com/design">Veerle Pieters</a></p>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/' rel='bookmark' title='Permanent Link: Visualization of HTML5 &amp; CSS3 readiness on different browsers'>Visualization of HTML5 &amp; CSS3 readiness on different browsers</a></li>
<li><a href='http://www.biofusiondesign.com/2010/06/20/world-cup-twitter-visualization-from-the-guardian/' rel='bookmark' title='Permanent Link: World Cup twitter visualization from the Guardian'>World Cup twitter visualization from the Guardian</a></li>
<li><a href='http://www.biofusiondesign.com/2008/12/17/handmade-fonts/' rel='bookmark' title='Permanent Link: Handmade fonts'>Handmade fonts</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/31/visualization-of-our-solar-system-in-css3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google celebrates Pacman’s 30th birthday with playable logo</title>
		<link>http://www.biofusiondesign.com/2010/05/21/google-celebrates-pacmans-30th-birthday-with-playable-logo/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=google-celebrates-pacmans-30th-birthday-with-playable-logo</link>
		<comments>http://www.biofusiondesign.com/2010/05/21/google-celebrates-pacmans-30th-birthday-with-playable-logo/#comments</comments>
		<pubDate>Fri, 21 May 2010 17:37:32 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[30th birthday]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[pacman]]></category>

		<guid isPermaLink="false">http://biofusiondesign.com/?p=834</guid>
		<description><![CDATA[Click image to play the game Related posts:Adobe and Google Announce Flash Analytics 2010 UEFA Champions League game tracker from Adidas


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2008/11/18/adobe-and-google-announce-flash-analytics/' rel='bookmark' title='Permanent Link: Adobe and Google Announce Flash Analytics'>Adobe and Google Announce Flash Analytics</a></li>
<li><a href='http://www.biofusiondesign.com/2010/06/03/2010-uefa-champions-league-game-tracker-from-adidas/' rel='bookmark' title='Permanent Link: 2010 UEFA Champions League game tracker from Adidas'>2010 UEFA Champions League game tracker from Adidas</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="www.google.com"><img src="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/google-pacman-logo.png" alt="" title="google-pacman-logo" width="557" height="280" class="alignnone size-full wp-image-835" /></a></p>
<p><em>Click image to play the game</em></p>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2008/11/18/adobe-and-google-announce-flash-analytics/' rel='bookmark' title='Permanent Link: Adobe and Google Announce Flash Analytics'>Adobe and Google Announce Flash Analytics</a></li>
<li><a href='http://www.biofusiondesign.com/2010/06/03/2010-uefa-champions-league-game-tracker-from-adidas/' rel='bookmark' title='Permanent Link: 2010 UEFA Champions League game tracker from Adidas'>2010 UEFA Champions League game tracker from Adidas</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/21/google-celebrates-pacmans-30th-birthday-with-playable-logo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe Flash to eliminate bandwidth costs with P2P</title>
		<link>http://www.biofusiondesign.com/2010/05/19/adobe-flash-to-eliminate-bandwidth-costs-with-p2p/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=adobe-flash-to-eliminate-bandwidth-costs-with-p2p</link>
		<comments>http://www.biofusiondesign.com/2010/05/19/adobe-flash-to-eliminate-bandwidth-costs-with-p2p/#comments</comments>
		<pubDate>Wed, 19 May 2010 18:21:32 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[p2p]]></category>

		<guid isPermaLink="false">http://biofusiondesign.com/?p=809</guid>
		<description><![CDATA[From TorrentFreak: Adobe is getting serious about their implementation of peer-to-peer technology to assist Flash-based video streaming and applications. The upcoming release of Adobe’s Flash Player 10.1 will enable publishers to dramatically reduce bandwidth costs by outsourcing media distribution to users. The system Adobe is offering to support P2P Flash is called Stratus. It is [...]


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2008/11/18/adobe-and-google-announce-flash-analytics/' rel='bookmark' title='Permanent Link: Adobe and Google Announce Flash Analytics'>Adobe and Google Announce Flash Analytics</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/09/iphone-sdk-4-0-license-agreement-bans-ported-flash-apps/' rel='bookmark' title='Permanent Link: Iphone SDK 4.0 license agreement bans ported Flash apps'>Iphone SDK 4.0 license agreement bans ported Flash apps</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/29/steve-jobs-on-flash/' rel='bookmark' title='Permanent Link: Steve Jobs on Flash'>Steve Jobs on Flash</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://torrentfreak.com/adobe-flash-to-eliminate-bandwidth-costs-with-p2p-100519/">TorrentFreak</a>:</p>
<blockquote><p>Adobe is getting serious about their implementation of peer-to-peer technology to assist Flash-based video streaming and applications. The upcoming release of Adobe’s Flash Player 10.1 will enable publishers to dramatically reduce bandwidth costs by outsourcing media distribution to users.</p></blockquote>
<blockquote><p>The system Adobe is offering to support P2P Flash is called Stratus. It is offered to developers free of charge and can support both live and on-demand video streaming. Besides video, Stratus can also be used for Flash based multi-player games and other forms of real time communication.</p>
<p>For broadcasters and video services, Stratus has the capacity to eliminate a significant amount of bandwidth costs. Instead of serving the media from a central server, users will provide the necessary bandwidth. Adobe’s Stratus system serves as an intermediary in this process, managing the communications between Flash players much like a BitTorrent tracker does for BitTorrent transfers.</p></blockquote>
<p>Via <a href="http://jimray.tumblr.com/">Jim Ray</a></p>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2008/11/18/adobe-and-google-announce-flash-analytics/' rel='bookmark' title='Permanent Link: Adobe and Google Announce Flash Analytics'>Adobe and Google Announce Flash Analytics</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/09/iphone-sdk-4-0-license-agreement-bans-ported-flash-apps/' rel='bookmark' title='Permanent Link: Iphone SDK 4.0 license agreement bans ported Flash apps'>Iphone SDK 4.0 license agreement bans ported Flash apps</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/29/steve-jobs-on-flash/' rel='bookmark' title='Permanent Link: Steve Jobs on Flash'>Steve Jobs on Flash</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/19/adobe-flash-to-eliminate-bandwidth-costs-with-p2p/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cooking an MVC framework for data visualization: Models</title>
		<link>http://www.biofusiondesign.com/2010/05/19/cooking-an-mvc-framework-for-data-visualization-models/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cooking-an-mvc-framework-for-data-visualization-models</link>
		<comments>http://www.biofusiondesign.com/2010/05/19/cooking-an-mvc-framework-for-data-visualization-models/#comments</comments>
		<pubDate>Wed, 19 May 2010 14:30:37 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[model view controller]]></category>
		<category><![CDATA[models]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[visualization framework]]></category>

		<guid isPermaLink="false">http://www.biofusiondesign.com/?p=757</guid>
		<description><![CDATA[Last time we learned how to create a dynamic bar chart with data that we had to type in manually. That data entry part was tedious and unnecessary. Today we will solve that problem by creating a model that can load and parse data from an external file. Although in this example we only use [...]


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Views part 1'>Cooking an MVC framework for data visualization: Views part 1</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/27/cooking-an-mvc-framework-for-data-visualization-hello-world/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Hello World!'>Cooking an MVC framework for data visualization: Hello World!</a></li>
<li><a href='http://www.biofusiondesign.com/2008/12/19/notable-people-and-companies-in-the-field-data-visualization/' rel='bookmark' title='Permanent Link: Notable people in the field data visualization'>Notable people in the field data visualization</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Last time we learned how to <a href="http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/">create a dynamic bar chart</a> with data that we had to type in manually. That data entry part was tedious and unnecessary. Today we will solve that problem by creating a model that can load and parse data from an external file. Although in this example we only use the model to parse comma delimited file (CSV), we will build it in a way that allow us to parse tab delimited file as well. CSV is a very popular and compact format for storing data. It is also very easy to parse.  </p>
<p>If you didn’t follow the <a href="http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/">previous tutorial</a>, you can <a href='http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/03-models.zip'>download the project from here</a>. </p>
<p><span id="more-757"></span></p>
<p>Before we create our CSV model, we need to modify the base <strong>Model</strong> class slightly to make it ready for external data.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// Model.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package models <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;&nbsp; &nbsp; <br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Model <span style="color: #0066CC;">extends</span> EventDispatcher <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// EVENT CONSTANTS</span><br />
<span style="color: #808080; font-style: italic;">//----------------------------------------------------------------- </span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOADING:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;loading&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const <span style="color: #0066CC;">LOADED</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;loaded&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LOAD_ERROR:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;loadError&quot;</span>;&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Model<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The <strong>Model</strong> class now inherits from <strong>EventDispatcher</strong> allowing all of its subclasses to dispatch events. We will use this capability to notify the rest of the application when the file is loaded. We also added three event strings (line 9, 10, 11) that our parser will dispatch at different stages of loading data. The last thing we added to the <strong>Model</strong> class is the <strong><em>loadData()</em></strong> method.</p>
<p>Now we are ready for the <strong>DelimitedTextParser</strong> class. It is relatively long, but most of the code has to do with setting up the events.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// DelimitedTextParser.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package models <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">errors</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> models.<span style="color: #006600;">Model</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DelimitedTextParser <span style="color: #0066CC;">extends</span> Model <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTANTS </span><br />
<span style="color: #808080; font-style: italic;">//----------------------------------------------------------------- &nbsp; </span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const <span style="color: #0066CC;">TAB</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const COMMA:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;,&quot;</span>;<br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// PROPERTIES</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> delimiter:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">Array</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loader:URLLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> DelimitedTextParser<span style="color: #66cc66;">&#40;</span>delimiter:<span style="color: #0066CC;">String</span> = COMMA<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">delimiter</span> = delimiter; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; setEventListeners<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> loadData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">throw</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;Error:DelimitedTextParser invalid url.&quot;</span> <span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">data</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// EVENT HANDLERS</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onLoading<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>Model.<span style="color: #006600;">LOADING</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onLoaded<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; parseData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>loader.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>Model.<span style="color: #0066CC;">LOADED</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onLoadError</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>Model.<span style="color: #006600;">LOAD_ERROR</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// PRIVATE METHODS</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> parseData<span style="color: #66cc66;">&#40;</span>rawData:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">data</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; split data into rows using \n or \r character</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rows:<span style="color: #0066CC;">Array</span> = rawData.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>rows.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rows = rawData.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; get column names</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> columnsName:<span style="color: #0066CC;">Array</span> = rows<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span> delimiter <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; Loop that create an array of data objects</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1</span> ; i <span style="color: #66cc66;">&lt;</span> rows.<span style="color: #0066CC;">length</span>; i++ <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> RecordArray:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; RecordArray = rows<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span> delimiter <span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> record:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> j:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>; j<span style="color: #66cc66;">&lt;</span>columnsName.<span style="color: #0066CC;">length</span>;j++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; record<span style="color: #66cc66;">&#91;</span>columnsName<span style="color: #66cc66;">&#91;</span>j<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span> = RecordArray<span style="color: #66cc66;">&#91;</span>j<span style="color: #66cc66;">&#93;</span>;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>record<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setEventListeners<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ProgressEvent.<span style="color: #006600;">PROGRESS</span>, onLoading<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onLoaded<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>IOErrorEvent.<span style="color: #006600;">IO_ERROR</span>, <span style="color: #0066CC;">onLoadError</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>You may notice that the constructor takes a parameter <strong><em>delimiter</em></strong> that has a default value of <strong><em>COMMA</em></strong>. We will use this <strong><em>delimiter</em></strong> string to parse the text we load from the external file. The constructor also sets up all the event handlers related to loading files from an url. We are using the <strong>URLLoader</strong> class (line 20) from Flash to load files from an external location, so the events we are handling are the events dispatched by that class.</p>
<p>Once the file is loaded, the <strong><em>onLoaded()</em></strong> (line 46) method is called. The model then parses the data and dispatches a <strong><em>Model.LOADED</em></strong> event. The <strong><em>parseData()</em></strong> (line 56) method is what does the actual job. It splits the text by lines and then by columns (line 64) based on the delimiter. It then creates an array of objects with each object representing the data on each line. It will convert raw text that looks like this:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// data.csv</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
year,period,value<br />
<span style="color: #cc66cc;">2000</span>,M01,<span style="color: #cc66cc;">4.0</span><br />
<span style="color: #cc66cc;">2000</span>,M02,<span style="color: #cc66cc;">4.1</span></div></td></tr></tbody></table></div>
<p>To an array of objects that looks like this:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// Array of objects</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #66cc66;">&#91;</span><br />
&nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;year&quot;</span>:<span style="color: #cc66cc;">2000</span>,<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;period&quot;</span>:M01,<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;value&quot;</span>:<span style="color: #cc66cc;">4.0</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span>,<br />
&nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;year&quot;</span>:<span style="color: #cc66cc;">2000</span>,<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;period&quot;</span>:M02,<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;value&quot;</span>:<span style="color: #cc66cc;">4.1</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#93;</span></div></td></tr></tbody></table></div>
<p>Now let’s put all the pieces together.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// Main.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> models.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #006600;">barchart</span>.<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">//&nbsp; CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; createSimpleBarChart<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// PRIVATE METHODS </span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createSimpleBarChart<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create a parser model</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myModel:Model = <span style="color: #000000; font-weight: bold;">new</span> DelimitedTextParser<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create a chart view</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myChart:SimpleBarChart = <span style="color: #000000; font-weight: bold;">new</span> SimpleBarChart<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add to stage</span><br />
&nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>myChart<span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Send data to the chart once it is loaded &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; myModel.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Model.<span style="color: #0066CC;">LOADED</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Send data to chart</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span> myModel.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Load the data from a csv file</span><br />
&nbsp; &nbsp; &nbsp; myModel.<span style="color: #006600;">loadData</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;unemployment.csv&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The <strong>Main</strong> class looks almost the same. We now wait for the data to be loaded and parsed (line 29) before sending it to the view (line 31). We will also need to make a small change to the <strong>SimpleBarChart</strong> view. It used to take an array of numbers to draw the bars, now it will take an array of objects (line 43 below). Pay attention to this part <strong><em>content[i][“value”]</em></strong>. The chart view looks for the “value” property in the data object, so we need to have a column called “value” in the original csv file.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// SimpleBarChart.as</span><br />
<span style="color: #808080; font-style: italic;">//----------------------------------------------------------------</span><br />
package views.<span style="color: #006600;">barchart</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #006600;">View</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #006600;">barchart</span>.<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleBarChart <span style="color: #0066CC;">extends</span> View <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTANTS</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Padding between bars</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const PADDING:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">1</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Default sizes for the chart</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const DEFAULT_WIDTH:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">430</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const DEFAULT_HEIGHT:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">200</span>;<br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// GLOBAL VARIABLES</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// store references to all bars on stage</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bars:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;<br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SimpleBarChart<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//----------------------------------------------------------------- &nbsp; </span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render the view</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #66cc66;">&#40;</span>content:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span>content<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create the bars and add them to the stage</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> maxValue = getMaxValue<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> maxBarWidth:<span style="color: #0066CC;">Number</span> = DEFAULT_WIDTH<span style="color: #66cc66;">/</span>content.<span style="color: #0066CC;">length</span> - PADDING;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> content.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// data that each bar will need to render itself </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">height</span> = content<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">/</span>maxValue<span style="color: #66cc66;">*</span>DEFAULT_HEIGHT;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">width</span> = maxBarWidth;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create and render a bar</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> = <span style="color: #000000; font-weight: bold;">new</span> Bar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// position the bar</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> = <span style="color: #66cc66;">&#40;</span>maxBarWidth + PADDING<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> = DEFAULT_HEIGHT - bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">height</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; <br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// PRIVATE METHODS</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getMaxValue<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> maxValue:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> content.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>maxValue <span style="color: #66cc66;">&lt;</span> content<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> maxValue = content<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> maxValue;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; <br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>That’s it, we are done. If you publish your application now, you should see something like this: </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_myApp_449694069"
			class="flashmovie"
			width="430"
			height="200">
	<param name="movie" value="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/myApp.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/myApp.swf"
			name="fm_myApp_449694069"
			width="430"
			height="200">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The chart shows monthly unemployment rate since 2000 from the <a href="http://www.bls.gov/">U.S. Bureau of Labor Statistics</a>.</p>
<p>We covered a very important concept in this tutorial. Following this pattern you should be able to build models that load data from a server and use the data to power your views. Next time we will go over how to add interactions to your view. We will also cover a very important design pattern called Singleton. </p>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Views part 1'>Cooking an MVC framework for data visualization: Views part 1</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/27/cooking-an-mvc-framework-for-data-visualization-hello-world/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Hello World!'>Cooking an MVC framework for data visualization: Hello World!</a></li>
<li><a href='http://www.biofusiondesign.com/2008/12/19/notable-people-and-companies-in-the-field-data-visualization/' rel='bookmark' title='Permanent Link: Notable people in the field data visualization'>Notable people in the field data visualization</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/19/cooking-an-mvc-framework-for-data-visualization-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eddy is the new Twitter aggregation platform from Stamen</title>
		<link>http://www.biofusiondesign.com/2010/05/14/eddy-is-the-new-twitter-aggregation-platform-from-stamen/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=eddy-is-the-new-twitter-aggregation-platform-from-stamen</link>
		<comments>http://www.biofusiondesign.com/2010/05/14/eddy-is-the-new-twitter-aggregation-platform-from-stamen/#comments</comments>
		<pubDate>Fri, 14 May 2010 17:30:01 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Social networks]]></category>
		<category><![CDATA[aggregation]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[interactive media designers]]></category>
		<category><![CDATA[streams]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.biofusiondesign.com/?p=765</guid>
		<description><![CDATA[From the product page: Eddy is a media aggregation platform built for the public display of up-to-the-minute activity on realtime services like Twitter. It offers three primary features: rapid collection and curation of what people are saying about an event, moderation of acceptable material, and speedy, reliable republishing of these conversational streams. Setup of the [...]


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/06/20/world-cup-twitter-visualization-from-the-guardian/' rel='bookmark' title='Permanent Link: World Cup twitter visualization from the Guardian'>World Cup twitter visualization from the Guardian</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/stamen-eddy-590x254.png" alt="Eddy from Stamen design" title="stamen-eddy" width="590" height="254" class="alignnone size-large wp-image-771" /></p>
<p>From <a href="http://eddy.stamen.com/">the product</a> page:</p>
<blockquote><p>Eddy is a media aggregation platform built for the public display of up-to-the-minute activity on realtime services like Twitter. It offers three primary features: rapid collection and curation of what people are saying about an event, moderation of acceptable material, and speedy, reliable republishing of these conversational streams. Setup of the application is fast and easy, and made specifically for use by interactive media designers. Eddy makes data available in formats specifically designed for publishing on the web, allowing developers to quickly iterate design concepts with real world data and to launch without fuss.
</p></blockquote>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/06/20/world-cup-twitter-visualization-from-the-guardian/' rel='bookmark' title='Permanent Link: World Cup twitter visualization from the Guardian'>World Cup twitter visualization from the Guardian</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/14/eddy-is-the-new-twitter-aggregation-platform-from-stamen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualization of HTML5 &amp; CSS3 readiness on different browsers</title>
		<link>http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=visualization-of-html5-css3-readiness-on-different-browsers</link>
		<comments>http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/#comments</comments>
		<pubDate>Fri, 14 May 2010 16:30:35 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[browsers compatibility]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://www.biofusiondesign.com/?p=762</guid>
		<description><![CDATA[Click on image to view the site This visualization is compact and pretty. I like the idea behind it, but it is not necessarily the best way to present this kind of information. You can't quickly scan the information since you have to mouse over each bar to see what feature it represents. The color [...]


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/31/visualization-of-our-solar-system-in-css3/' rel='bookmark' title='Permanent Link: Visualization of our solar system in CSS3'>Visualization of our solar system in CSS3</a></li>
<li><a href='http://www.biofusiondesign.com/2010/06/23/john-steward-on-bp-oil-spill/' rel='bookmark' title='Permanent Link: Jon Stewart on BP oil spill'>Jon Stewart on BP oil spill</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Views part 1'>Cooking an MVC framework for data visualization: Views part 1</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://html5readiness.com/"><img src="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/html5-readiness-590x338.png" alt="html5 readiness chart" title="html5-readiness" width="590" height="338" class="alignnone size-large wp-image-776" /></a></p>
<p><em>Click on image to view the site</em></p>
<p>This <a href="http://html5readiness.com/">visualization</a> is compact and pretty. I like the idea behind it, but it is not necessarily the best way to present this kind of information. You can’t quickly scan the information since you have to mouse over each bar to see what feature it represents. The color coded bars are stacking toward the center instead of remaining in their own circle, which makes it harder to follow. I think a regular matrix table would be nicer. </p>
<p>via <a href="http://infosthetics.com/archives/2010/05/html5_and_css3_readiness_visualized.html">infosthetics</a></p>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/31/visualization-of-our-solar-system-in-css3/' rel='bookmark' title='Permanent Link: Visualization of our solar system in CSS3'>Visualization of our solar system in CSS3</a></li>
<li><a href='http://www.biofusiondesign.com/2010/06/23/john-steward-on-bp-oil-spill/' rel='bookmark' title='Permanent Link: Jon Stewart on BP oil spill'>Jon Stewart on BP oil spill</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Views part 1'>Cooking an MVC framework for data visualization: Views part 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Flash is still relevant in the HTML5 world</title>
		<link>http://www.biofusiondesign.com/2010/05/10/why-flash-is-still-relevant-in-the-html5-world/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=why-flash-is-still-relevant-in-the-html5-world</link>
		<comments>http://www.biofusiondesign.com/2010/05/10/why-flash-is-still-relevant-in-the-html5-world/#comments</comments>
		<pubDate>Mon, 10 May 2010 17:00:01 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[insights]]></category>

		<guid isPermaLink="false">http://biofusiondesign.com/?p=727</guid>
		<description><![CDATA[Gonzalo Rubio gives a few very good reasons about why we shouldn't ditch Flash quite yet. Being a Flash developer, I admit to having my own biases, but I am also impressed by what HTML5 can do. I have been digging around the web for the last few days trying to figure out if at [...]


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/06/jeremy-keith%e2%80%99s-html5-for-web-designers-book-is-out/' rel='bookmark' title='Permanent Link: Jeremy Keith’s HTML5 for web designers book is out'>Jeremy Keith’s HTML5 for web designers book is out</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/05/when-can-i-use-html5/' rel='bookmark' title='Permanent Link: When can I use HTML5?'>When can I use HTML5?</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/09/iphone-sdk-4-0-license-agreement-bans-ported-flash-apps/' rel='bookmark' title='Permanent Link: Iphone SDK 4.0 license agreement bans ported Flash apps'>Iphone SDK 4.0 license agreement bans ported Flash apps</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.gonchuki.com/">Gonzalo Rubio</a> gives a few very good reasons about why we shouldn’t ditch Flash quite yet. Being a Flash developer, I admit to having my own biases, but I am also impressed by what HTML5 can do. I have been digging around the web for the last few days trying to figure out if at its current stage, HTML5 is capable enough to do heavy interactive data visualization work. The short answer is no. There are, of course, a lot of <a href="http://datavisualization.ch/tools/13-javascript-libraries-for-visualizations">Javascript charting engines</a> out there, but for performance-heavy things like maps, Flash is still better. As to the Flash vs HTML5 argument, I think a few of us only see black and white. Gonzalo seems to think that each tool has its own place in the future of web development. I agree. Below is the summary of the points he talks about in his article. Head over to his blog to <a href="http://blog.gonchuki.com/archives/6-reasons-why-the-html5-vs-flash-debate-is-idiotic/">read the complete post</a>.  </p>
<ol>
<li>The HTML5 spec won’t be ready for consumption for at least another 2 years.</li>
<li>Flash is a mature platform, HTML5 is just in its initial implementation phase.</li>
<li>Flash is made by a single vendor, HTML5 sees duplicate efforts by at least 5 different companies on at least 4 different platforms.</li>
<li>Flash is built as a multimedia and animation platform, HTML5 is a progressive enhancement over a content centric and descriptive language</li>
<li>Flash is good at what Flash does, HTML5 is good at what HTML does</li>
<li>The Flash vs. HTML5 argument will implode after every Flash feature is ported into an HTML5/Canvas equivalent</li>
</ol>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/06/jeremy-keith%e2%80%99s-html5-for-web-designers-book-is-out/' rel='bookmark' title='Permanent Link: Jeremy Keith’s HTML5 for web designers book is out'>Jeremy Keith’s HTML5 for web designers book is out</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/05/when-can-i-use-html5/' rel='bookmark' title='Permanent Link: When can I use HTML5?'>When can I use HTML5?</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/09/iphone-sdk-4-0-license-agreement-bans-ported-flash-apps/' rel='bookmark' title='Permanent Link: Iphone SDK 4.0 license agreement bans ported Flash apps'>Iphone SDK 4.0 license agreement bans ported Flash apps</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/10/why-flash-is-still-relevant-in-the-html5-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When can I use HTML5?</title>
		<link>http://www.biofusiondesign.com/2010/05/05/when-can-i-use-html5/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=when-can-i-use-html5</link>
		<comments>http://www.biofusiondesign.com/2010/05/05/when-can-i-use-html5/#comments</comments>
		<pubDate>Wed, 05 May 2010 21:36:37 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[compatibility]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://biofusiondesign.com/?p=655</guid>
		<description><![CDATA[Click on image to go to the guide Ready to move your site to HTML5? Better check this browsers compatibility guide out before you call the shot. Related posts:Jeremy Keith’s HTML5 for web designers book is out Why Flash is still relevant in the HTML5 world Visualization of HTML5 &#38; CSS3 readiness on different browsers


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/06/jeremy-keith%e2%80%99s-html5-for-web-designers-book-is-out/' rel='bookmark' title='Permanent Link: Jeremy Keith’s HTML5 for web designers book is out'>Jeremy Keith’s HTML5 for web designers book is out</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/10/why-flash-is-still-relevant-in-the-html5-world/' rel='bookmark' title='Permanent Link: Why Flash is still relevant in the HTML5 world'>Why Flash is still relevant in the HTML5 world</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/' rel='bookmark' title='Permanent Link: Visualization of HTML5 &amp; CSS3 readiness on different browsers'>Visualization of HTML5 &amp; CSS3 readiness on different browsers</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/canvas-support-590x183.png" alt="html5 canvas support" title="canvas-support" width="590" height="183" class="alignleft size-large wp-image-656" /><br />
<em>Click on image to go to the guide</em></p>
<p>Ready to move your site to HTML5? Better check this <a href="http://caniuse.com/">browsers compatibility guide</a> out before you call the shot.</p>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/06/jeremy-keith%e2%80%99s-html5-for-web-designers-book-is-out/' rel='bookmark' title='Permanent Link: Jeremy Keith’s HTML5 for web designers book is out'>Jeremy Keith’s HTML5 for web designers book is out</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/10/why-flash-is-still-relevant-in-the-html5-world/' rel='bookmark' title='Permanent Link: Why Flash is still relevant in the HTML5 world'>Why Flash is still relevant in the HTML5 world</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/' rel='bookmark' title='Permanent Link: Visualization of HTML5 &amp; CSS3 readiness on different browsers'>Visualization of HTML5 &amp; CSS3 readiness on different browsers</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/05/when-can-i-use-html5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cooking an MVC framework for data visualization: Views part 1</title>
		<link>http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cooking-an-mvc-framework-for-data-visualization-views-part-1</link>
		<comments>http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/#comments</comments>
		<pubDate>Tue, 04 May 2010 15:00:53 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[model view controller]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[visualization framework]]></category>

		<guid isPermaLink="false">http://www.biofusiondesign.com/?p=615</guid>
		<description><![CDATA[In this second tutorial on MVC we will learn how to create a simple bar chart view. We will also cover a new concept called composite view. It is an important concept in the MVC world that allows a view to contain other views. It will let you build complex views out of small interchangeable [...]


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/19/cooking-an-mvc-framework-for-data-visualization-models/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Models'>Cooking an MVC framework for data visualization: Models</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/27/cooking-an-mvc-framework-for-data-visualization-hello-world/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Hello World!'>Cooking an MVC framework for data visualization: Hello World!</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/' rel='bookmark' title='Permanent Link: Visualization of HTML5 &amp; CSS3 readiness on different browsers'>Visualization of HTML5 &amp; CSS3 readiness on different browsers</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this second tutorial on MVC we will learn how to create a simple bar chart view. We will also cover a new concept called composite view. It is an important concept in the MVC world that allows a view to contain other views. It will let you build complex views out of small <strong>interchangeable</strong> pieces. When your application grows, it is crucial to write code that is reusable, so your application remains maintainable. Breaking views into small reusable chunks of code is one way to do that. Below is the result of what we are going to build in this tutorial.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_myApp1_690973119"
			class="flashmovie"
			width="430"
			height="200">
	<param name="movie" value="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/myApp1.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/myApp1.swf"
			name="fm_myApp1_690973119"
			width="430"
			height="200">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The chart shows monthly unemployment rate since 2005 from the <a href="http://www.bls.gov/">U.S. Bureau of Labor Statistics</a>.</p>
<p><span id="more-615"></span></p>
<h4>Preparation</h4>
<p><img src="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/02-project-overview.png" alt="mvc views project overview" title="02 project overview" width="184" height="207" class="alignleft size-full wp-image-616" /></p>
<p>Here is an overview of what we are going to build in this tutorial. If you followed the <a href="http://www.biofusiondesign.com/2010/04/27/cooking-an-mvc-framework-for-data-visualization-hello-world/">last tutorial</a>, you should have the <strong>Model</strong> and the <strong>View</strong> class ready. If not, you can <a href="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/02-views-part-1.zip">download the whole project from here</a>. We will write the <strong>SimpleModel</strong> class that is used to feed data to the chart. The <strong>SimpleBarChart</strong> class and the <strong>Bar</strong> class are parts of the bar chart view. We will talk about the relationship between them in the next section.  </p>
<p> </p>
<h4>Building a composite view</h4>
<p>To make the composite view work, we have to make sure that all of its pieces work together. That means they have to speak a common language. We have been doing that all along with our base <strong>View</strong> class. Essentially every view that inherits from the <strong>View</strong> class will have a <strong>render(content:Object)</strong> method. We don’t care about the specific implementation of that method, all we care about is that we can call it. Below is a diagram that explains this concept. </p>
<p><img src="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/05/02-diagram2.gif" alt="views project overview" title="02-diagram2" width="184" height="289" class="alignleft size-full wp-image-637" /></p>
<p>The application contains <strong><em>myView</em></strong>, an instance of the <strong>ParentView</strong> class, and communicates with it through the <strong><em>render()</em></strong> method. The parent view then calls <strong><em>render()</em></strong> on its child view. The application doesn’t know or care about the child view nor the other way around. This makes it easy to swap the child view when needed. Note that in this system, the parent view also doesn’t know how the child view operates, it only knows that the child view expects a data object. Below is the code that will put this concept to practice.</p>
<p> </p>
<p> </p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// Bar.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package views.<span style="color: #006600;">barchart</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #006600;">View</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Bar <span style="color: #0066CC;">extends</span> View <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTANTS</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const DEFAULT_COLOR:<span style="color: #0066CC;">int</span> = 0x000000;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const DEFAULT_ALPHA:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.2</span>;<br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Bar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; Render the view</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #66cc66;">&#40;</span>content:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// A call to the base View's render() method </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// to store the content</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span>content<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// draw the bar</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>DEFAULT_COLOR,DEFAULT_ALPHA<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">0</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">0</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">width</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">height</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The <strong><em>render()</em></strong> method of the <strong>Bar</strong> class doesn’t do anything complex. It takes an object that has <strong><em>width</em></strong> and <strong><em>height</em></strong> properties and draws itself on the stage.</p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// SimpleBarChart.as</span><br />
<span style="color: #808080; font-style: italic;">//----------------------------------------------------------------- &nbsp; </span><br />
package views.<span style="color: #006600;">barchart</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #006600;">View</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #006600;">barchart</span>.<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleBarChart <span style="color: #0066CC;">extends</span> View <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTANTS</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Padding between bars</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const PADDING:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">10</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Default sizes for the chart</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const DEFAULT_WIDTH:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">430</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const DEFAULT_HEIGHT:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">200</span>;<br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// GLOBAL VARIABLES</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// store references to all bars on stage</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bars:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;<br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SimpleBarChart<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//----------------------------------------------------------------- &nbsp; </span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render the view</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #66cc66;">&#40;</span>content:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span>content<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create the bars and add them to the stage</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> maxValue = getMaxValue<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> maxBarWidth:<span style="color: #0066CC;">Number</span> = DEFAULT_WIDTH<span style="color: #66cc66;">/</span>content.<span style="color: #0066CC;">length</span> - PADDING;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> content.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// data that each bar will need to render itself </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">height</span> = content<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">/</span>maxValue<span style="color: #66cc66;">*</span>DEFAULT_HEIGHT;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">width</span> = maxBarWidth;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create and render a bar</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> = <span style="color: #000000; font-weight: bold;">new</span> Bar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// position the bar</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> = <span style="color: #66cc66;">&#40;</span>maxBarWidth + PADDING<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> = DEFAULT_HEIGHT - bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">height</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>bars<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; <br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// PRIVATE METHODS</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getMaxValue<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> maxValue:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> content.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>maxValue <span style="color: #66cc66;">&lt;</span> content<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> maxValue = content<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> maxValue;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; <br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The <strong>SimpleBarChart</strong> class contains the most code we have written so far, but most of it is pretty straight forward. The <strong><em>render()</em></strong> method takes an array of numbers, loops through it to find the max value, calculates the bar width and creates instances of the <strong>Bar</strong> class. Line 37 to 40 is where the magic happens. We create the content object for the <strong>Bar</strong> class there.</p>
<p>Now that we have the bar chart view ready, let’s feed it data to see how it works.</p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// SimpleModel.as</span><br />
<span style="color: #808080; font-style: italic;">//----------------------------------------------------------------- &nbsp; </span><br />
package models <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> models.<span style="color: #006600;">Model</span>;<br />
&nbsp; <br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleModel <span style="color: #0066CC;">extends</span> Model <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SimpleModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">5.3</span>, <span style="color: #cc66cc;">5.4</span>, <span style="color: #cc66cc;">5.2</span>, <span style="color: #cc66cc;">5.2</span>, <span style="color: #cc66cc;">5.1</span>, <span style="color: #cc66cc;">5.0</span>, <span style="color: #cc66cc;">5.0</span>, <span style="color: #cc66cc;">4.9</span>, <span style="color: #cc66cc;">5.0</span>, <span style="color: #cc66cc;">5.0</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">5.0</span>, <span style="color: #cc66cc;">4.9</span>, <span style="color: #cc66cc;">4.7</span>, <span style="color: #cc66cc;">4.8</span>, <span style="color: #cc66cc;">4.7</span>, <span style="color: #cc66cc;">4.7</span>, <span style="color: #cc66cc;">4.6</span>, <span style="color: #cc66cc;">4.6</span>, <span style="color: #cc66cc;">4.7</span>, <span style="color: #cc66cc;">4.7</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">4.5</span>, <span style="color: #cc66cc;">4.4</span>, <span style="color: #cc66cc;">4.5</span>, <span style="color: #cc66cc;">4.4</span>, <span style="color: #cc66cc;">4.6</span>, <span style="color: #cc66cc;">4.5</span>, <span style="color: #cc66cc;">4.4</span>, <span style="color: #cc66cc;">4.5</span>, <span style="color: #cc66cc;">4.4</span>, <span style="color: #cc66cc;">4.6</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">4.6</span>, <span style="color: #cc66cc;">4.6</span>, <span style="color: #cc66cc;">4.7</span>, <span style="color: #cc66cc;">4.7</span>, <span style="color: #cc66cc;">4.7</span>, <span style="color: #cc66cc;">5.0</span>, <span style="color: #cc66cc;">5.0</span>, <span style="color: #cc66cc;">4.8</span>, <span style="color: #cc66cc;">5.1</span>, <span style="color: #cc66cc;">5.0</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">5.4</span>, <span style="color: #cc66cc;">5.5</span>, <span style="color: #cc66cc;">5.8</span>, <span style="color: #cc66cc;">6.1</span>, <span style="color: #cc66cc;">6.2</span>, <span style="color: #cc66cc;">6.6</span>, <span style="color: #cc66cc;">6.9</span>, <span style="color: #cc66cc;">7.4</span>, <span style="color: #cc66cc;">7.7</span>, <span style="color: #cc66cc;">8.2</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">8.6</span>, <span style="color: #cc66cc;">8.9</span>, <span style="color: #cc66cc;">9.4</span>, <span style="color: #cc66cc;">9.5</span>, <span style="color: #cc66cc;">9.4</span>, <span style="color: #cc66cc;">9.7</span>, <span style="color: #cc66cc;">9.8</span>, <span style="color: #cc66cc;">10.1</span>, <span style="color: #cc66cc;">10.0</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">10.0</span>, <span style="color: #cc66cc;">9.7</span>, <span style="color: #cc66cc;">9.7</span>, <span style="color: #cc66cc;">9.7</span> &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span>;&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The <strong>SimpleModel</strong> class just returns an array of numbers. All we have left is the Main class that puts everything together.</p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// Main.as</span><br />
<span style="color: #808080; font-style: italic;">//----------------------------------------------------------------- &nbsp; </span><br />
package <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> models.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #006600;">barchart</span>.<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">//&nbsp; CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; createSimpleBarChart<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// PRIVATE METHODS </span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createSimpleBarChart<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Get data from simple model</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myModel:Model = <span style="color: #000000; font-weight: bold;">new</span> SimpleModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create a chart view</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myChart:SimpleBarChart = <span style="color: #000000; font-weight: bold;">new</span> SimpleBarChart<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Send data to chart</span><br />
&nbsp; &nbsp; &nbsp; myChart.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span> myModel.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add to stage</span><br />
&nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>myChart<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Voilà! If you have typed everything correctly, you should see something like this.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_myApp1_89164709"
			class="flashmovie"
			width="430"
			height="200">
	<param name="movie" value="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/myApp1.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/myApp1.swf"
			name="fm_myApp1_89164709"
			width="430"
			height="200">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>We have gone over a very important concept today. Please spend some time playing around with this and let me know if you have any questions. Next time we will learn how to create a model class that can parse data from a CSV file, so we don’t have to type all the data manually.  </p>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/19/cooking-an-mvc-framework-for-data-visualization-models/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Models'>Cooking an MVC framework for data visualization: Models</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/27/cooking-an-mvc-framework-for-data-visualization-hello-world/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Hello World!'>Cooking an MVC framework for data visualization: Hello World!</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/14/visualization-of-html5-css3-readiness-on-different-browsers/' rel='bookmark' title='Permanent Link: Visualization of HTML5 &amp; CSS3 readiness on different browsers'>Visualization of HTML5 &amp; CSS3 readiness on different browsers</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cooking an MVC framework for data visualization: Hello World!</title>
		<link>http://www.biofusiondesign.com/2010/04/27/cooking-an-mvc-framework-for-data-visualization-hello-world/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cooking-an-mvc-framework-for-data-visualization-hello-world</link>
		<comments>http://www.biofusiondesign.com/2010/04/27/cooking-an-mvc-framework-for-data-visualization-hello-world/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 15:00:59 +0000</pubDate>
		<dc:creator>Vu Nguyen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[model view controller]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[visualization framework]]></category>

		<guid isPermaLink="false">http://www.biofusiondesign.com/?p=587</guid>
		<description><![CDATA[For the last few years MVC frameworks have become a hot topic in the developer community. Many people love them and for a good reason. They make writing code much easier and more fun to do. The programs written in MVC are more scalable and easier to maintain. One of the biggest benefits is that [...]


Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Views part 1'>Cooking an MVC framework for data visualization: Views part 1</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/19/cooking-an-mvc-framework-for-data-visualization-models/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Models'>Cooking an MVC framework for data visualization: Models</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/20/world-bank-releases-its-data-to-the-public/' rel='bookmark' title='Permanent Link: World Bank releases its data to the public'>World Bank releases its data to the public</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>For the last few years MVC frameworks have become a hot topic in the developer community. Many people love them and for a good reason. They make writing code much easier and more fun to do. The programs written in MVC are more scalable and easier to maintain. One of the biggest benefits is that if you learn one, you can probably learn others pretty quickly. </p>
<h4>A few words about my background</h4>
<p>I am a web developer and designer who specializes in data visualization. I have been using a few MVC frameworks such as Django, ASP.NET MVC and more recently iPhone SDK for my work and I can tell you, they are very similar. Since I am still learning these concepts myself, please let me know if I don’t make sense or I am completely wrong. I promise I won’t feel bad about it <img src='http://www.biofusiondesign.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h4>Preparation</h4>
<p>In this series of tutorials I will introduce you to the MVC world. You will learn how to make your code cleaner and your applications more modular. Along the way you will learn a few useful design patterns, one of which is MVC, and how to apply them to your work. Although the main focus is on building a data visualization framework, many techniques are applicable to any kind of work.</p>
<p>These tutorials assume that you have general knowledge of object oriented programming and understand AS3 syntax. If you are not familiar with these, please go <a href="http://www.adobe.com/devnet/actionscript/articles/oop_as3.html">here</a> and <a href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ec7.html">here</a>. </p>
<p><span id="more-587"></span></p>
<h4>Ingredients</h4>
<p>So what is MVC and why is it so useful? MVC stands for Model-View-Controller and it is a design pattern in programming. When you structure an application in MVC, you break it down into small pieces and group them into distinct areas based on their function. In the most basic sense, a model deals with data. You can load, get and store data using the model. A view, on the other hand, is what you see and interact with on a screen. The view doesn’t know about the model, nor the other way around. They talk to each other through a controller. A typical flow of an MVC application goes like this:</p>
<ul>
<li>The user starts the application </li>
<li>The application creates and sends a request to the controller.</li>
<li>The controller goes to the model, asks for data and sends it to the view. </li>
<li>The view renders the data on the screen and waits for user interaction.</li>
<li>When the view receives the user interaction, it sends a new request to the controller and the cycle continues. </li>
</ul>
<p>A good example of an MVC in real life is a newspaper. The reporter is the model, the designer is the view, and the editor is the controller. The editor receives a request for a story and tells the reporter to write it. The reporter then goes out to the world, fetches the information and carefully organizes it into a draft. The editor receives the draft, edits its and sends the final story to the designer. The designer then figures out the layout and adds the story to the page.</p>
<h4>Preparing the sauce</h4>
<p>I hope I didn’t put you to sleep with the theory. Now we are going to write some code.</p>
<p><img src="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/01-project-overview2.jpg" alt="mvc project overview" title="01-project-overview2" width="146" height="184" class="alignleft size-full wp-image-599" /></p>
<p>A typical MVC application can have more than one model, one view and one controller. In fact, a large application can have hundreds of them. That is why we need to keep things organized. We will put the source code in the “/src” folder and the project files in the “/deploy” folder. It looks like we will be writing a lot of classes, but don’t be scared, most of the classes are just for initial setup. You can <a href="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/01-mvc-setup.zip">download the project here</a>. You may notice that there is a <em>myApp.tmproj</em> file included. If you don’t have <a href="http://macromates.com/">TextMate</a>, just ignore it.   </p>
<p>The first thing we write is the <strong>Model</strong> class. It is the base class for all models in an MVC application. It provides common functionality shared across all models. Every model we write from now on will inherit from this one.</p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// Model.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package models <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Model <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Model<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>As you can see, the <strong>Model</strong> class has public method <strong><em>getData()</em></strong>. Right now it doesn’t do much, it just returns null. We will provide actual implementation for this method in a subclass. </p>
<p>Similar to the <strong>Model</strong> class, the <strong>View</strong> class encapsulates common functionality across all views. Every view we write from now on will inherit from this one.</p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// View.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package views <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> View <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// INSTANCE VARIABLES</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">var</span> content:<span style="color: #0066CC;">Object</span>;<br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> View<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render the view</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #66cc66;">&#40;</span>content:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">content</span> = content;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The <strong>View</strong> base class has an instance variable <strong><em>content</em></strong> that we will use to store the content of a view. The <strong><em>render()</em></strong> method stores the content that you pass to it. We will override it to provide specific rendering routines. </p>
<p>We are done with the setup. You may notice that we don’t have a <strong>Controller</strong> base class. For the purpose of this tutorial, we won’t need one.</p>
<h4>Putting it all together</h4>
<p>Now that we have the foundation in place, we can go ahead and write our first MVC application. Yay!</p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// TextModel.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package models <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> models.<span style="color: #006600;">Model</span>;<br />
&nbsp; <br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TextModel <span style="color: #0066CC;">extends</span> Model <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TextModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;Hello world!!!&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The <strong>TextModel</strong> class extends the <strong>Model</strong> class. It overrides the <strong><em>getData()</em></strong> method from the parent class to provide a specific implementation. In this care, the method creates a string and returns it.</p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// TextView.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package views <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TextView <span style="color: #0066CC;">extends</span> View <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// INSTANCE VARIABLES</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">textField</span>:<span style="color: #0066CC;">TextField</span>;&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TextView<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textField</span>.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">180</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textField</span>.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">40</span>; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textField</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">// API</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render the TextView</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #66cc66;">&#40;</span>content:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span>content<span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textField</span>.<span style="color: #0066CC;">text</span> = content as <span style="color: #0066CC;">String</span>; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The <strong>TextView</strong> class extends the <strong>View</strong> class and overrides the <strong><em>render()</em></strong> method. It creates a text field and centers it on the stage. The <strong><em>render()</em></strong> method uses the text field to display whatever string you give it. Note that it also takes advantage of the functionality provided in the parent class by calling the <strong><em>super.render()</em></strong> method to store the string in the <strong><em>content</em></strong> variable . </p>
<p>The last class we will write is the <strong>Main</strong> class. It acts as the glue that connects the <strong>TextModel</strong> and the <strong>TextView</strong> together. Sounds familiar? It is actually the main controller of your application. When your application starts, the <strong>Main</strong> class takes over and is responsible for creating the initial view.</p>
<div class="codecolorer-container actionscript twitlight hang-left" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:430px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// Main.as</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
package <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> models.<span style="color: #66cc66;">*</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> views.<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; * @langversion : ActionScript 3.0, Flash Player 10.0<br />
&nbsp; *<br />
&nbsp; * @author &nbsp; &nbsp; &nbsp;: Vu Nguyen<br />
&nbsp; * @description : Intro to Model-View-Controller system <br />
&nbsp; */</span>&nbsp; <br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
<span style="color: #808080; font-style: italic;">//&nbsp; CONSTRUCTOR</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create a model</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myModel:Model = <span style="color: #000000; font-weight: bold;">new</span> TextModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create a view</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myView:View = <span style="color: #000000; font-weight: bold;">new</span> TextView<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render the view</span><br />
&nbsp; &nbsp; &nbsp; myView.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span> myModel.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add to stage</span><br />
&nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>myView<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//-----------------------------------------------------------------</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>In our case, the <strong>Main</strong> class doesn’t do much. It creates an instance of the <strong>TextModel</strong> class. The controller then creates an instance of the <strong>TextView</strong> class, calls its <strong><em>render()</em></strong> method, and passes it the data from the model by calling the model’s <strong><em>getData()</em></strong> method. </p>
<h4>The result</h4>
<p>If you publish the application now, you should see something like this: </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_myApp_2110261484"
			class="flashmovie"
			width="430"
			height="100">
	<param name="movie" value="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/myApp.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.wp.biofusiondesign.com/wp-content/uploads/2010/04/myApp.swf"
			name="fm_myApp_2110261484"
			width="430"
			height="100">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Yes, I know it is disappointing. “We wrote all this code just to print ‘Hello World!!!’ on the screen?”, you may ask. What we did here was to build the foundation of a truly scalable framework. The power of the MVC pattern is that different models can work with different views. A lot of the code you write will be reusable. In the next few tutorials, we will build real visualization views such as charts and maps. We will also build models that can load data from an external source such as XML, JSON or CSV files. </p>
<!-- PHP 5.x -->

<p>Related posts:<ol><li><a href='http://www.biofusiondesign.com/2010/05/04/cooking-an-mvc-framework-for-data-visualization-views-part-1/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Views part 1'>Cooking an MVC framework for data visualization: Views part 1</a></li>
<li><a href='http://www.biofusiondesign.com/2010/05/19/cooking-an-mvc-framework-for-data-visualization-models/' rel='bookmark' title='Permanent Link: Cooking an MVC framework for data visualization: Models'>Cooking an MVC framework for data visualization: Models</a></li>
<li><a href='http://www.biofusiondesign.com/2010/04/20/world-bank-releases-its-data-to-the-public/' rel='bookmark' title='Permanent Link: World Bank releases its data to the public'>World Bank releases its data to the public</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.biofusiondesign.com/2010/04/27/cooking-an-mvc-framework-for-data-visualization-hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
