<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Gareth Shapiro | London Based Freelance Web &amp; Mobile Consultant, Developer &amp; Trainer</title>
    <link>http://www.garethshapiro.com/</link>
    <description></description>
    <language>en-us</language>           
    <generator>Nucleus CMS v3.51</generator>
    <copyright>©</copyright>             
    <category>Weblog</category>
    <docs>http://backend.userland.com/rss</docs>
    <image>
      <url>http://www.garethshapiro.com//nucleus/nucleus2.gif</url>
      <title>Gareth Shapiro | London Based Freelance Web &amp; Mobile Consultant, Developer &amp; Trainer</title>
      <link>http://www.garethshapiro.com/</link>
    </image>
    <item>
 <title>Simple iOS Viewstack</title>
 <link>http://www.garethshapiro.com/index.php?itemid=73</link>
<descriptionnnn><![CDATA[<div class='item_list_rightbox'><a href="http://www.garethshapiro.com/media/1/20130412-xcode-logo.png">Xcode Logo</a></div>One of the central mechanisms in the architecture of an iPhone or iPad  app is a <i>UINavigationController</i>, there is at least one in most apps.  This class is similar to a view stack found in other application frameworks and for the most part works very well.  One drawback, and this has as much to do with iPhone and iPad application architecture as much as the <i>UINavigationController</i> itself is the decentralised approach to navigating between children <i>UIViewController</i>s.  Not having details that relate to something in one place in your code can make things hard to find and this frustrating situation can be made more so by the use of storyboards, but that's another conversation entirely.<br />
<br />
The situation can very easily be improved ...
<i>SimpleIOSViewStackController</i> is an Objective-C utility which extends <i>UINavigationController</i> so that details about the children <i>UIViewController</i>s, can all be found in one place.  This greatly improves the ease at which a programmer can find where in the code the changes to current application view originate from and delivers an added benefit of being able to start your app in a particular view state.  This becomes a great production benefit later in a project, helping to remove the need to click through several screens to get to the one you are wanting to work on.<br />
<br />
]]></descriptionnnn>
 <category>Developer</category>
<comments>http://www.garethshapiro.com/index.php?itemid=73</comments>
 <pubDate>Wed, 29 May 2013 19:17:06 +0000</pubDate>
</item><item>
 <title>Simple Objective-C API service</title>
 <link>http://www.garethshapiro.com/index.php?itemid=69</link>
<descriptionnnn><![CDATA[<div class='item_list_rightbox'><a href="http://www.garethshapiro.com/media/1/20130412-xcode-logo.png">Xcode Logo</a></div>I am sure many Objective-C developers, iOS or OSX, have been in the situation where the backend API needed for the project they are working on has not been developed by the time they need to start writing the code that will access it.  In organisations such as creative agencies, startups and software companies it is not always possible to synchronise resources to perfectly suit all the current projects' timelines but with a mixture of creativity and technology, conveniently wrapped up in a utility called <i>SimpleObjectiveCAPIService</i>, this simple bottle neck can be negotiated.  <br />
<br />
It is only correct that I point out now that this utility has been created more to assist with iOS app development rather than provide production ready network utility.  If you are developing an enterprise iPad app or an iPhone app that has to cope with dynamic connectivity situations this utility is more than likely going to fall short of your needs.
<div style='border: 1px dotted #CCCCCC; margin: 0px auto; width : 544px; height: 298px'><a href="http://www.garethshapiro.com/media/1/20130521-objective-c-ios-api-service.png">Objective-C iOS API Service</a></div><br />
There are a few ways of solving the issue of providing a local version of an API.  You could use a local web server on your machine, mock objects in your unit tests or as I was recently asked by a Technical Director while freelancing you could choose to include JSON files in the project to replicate API responses.  <br />
<br />
The advantage to this approach is the dependancies to get the local solution working are simple text files and are included in the project are backed up in Git/SVN and as such the situation can be easily replicated.  Another advantage is realised when the stub files are named in a way that describe the API calls.  These can then be supplied to the back end developer as part of communicating what is needed for them to produce the API, cutting down on the project documentation burden. <br />
]]></descriptionnnn>
 <category>Developer</category>
<comments>http://www.garethshapiro.com/index.php?itemid=69</comments>
 <pubDate>Thu, 23 May 2013 11:30:37 +0000</pubDate>
</item><item>
 <title>Dual : Adobe Air Database Update &amp; Access Layer</title>
 <link>http://www.garethshapiro.com/index.php?itemid=49</link>
<descriptionnnn><![CDATA[<div class='item_list_rightbox'><a href="http://www.garethshapiro.com/media/1/20111208adobe-air-icon.png">Adobe Air Runtime</a></div>We've all been in this situation.  You have developed a mobile app, or desktop application. It has been accepted to the Android Marketplace / Apple's App Store, or you have uploaded it onto your website or intranet for distribution.  People have installed it and are using it.<br />
<br />
It's time for version 2 and you make the inevitable changes to the database.  You have to write code, in the model of your MVC pattern usually, that copes both with a upgrading the database from version 1 and creating a database from scratch for a user who is using your application for the first time at version 2.<br />
<br />
And so the pattern continues, and the problem grows, for each version.  In version 3 you have to write code that handles people upgrading from version 2 to version 3, version 1 to version 3 and people installing the app for the first time.<br />
<br />
What a pain!  Not anymore …
<b>Introduction</b><br />
<br />
Dual is a library written in AS3 that provides an improvement to many database tasks in an Adobe Air application whether the app is intended for an Android phone, iPhone, iPad or desktop.  Dual was written to make the task of database version control across many different versions of your application easy to manage but that's not all it does ...<br />
<br />
Dual is :<ul><li>Lightweight, adding about 100k to your application.</li><li>Easy to use.  Honest.  It's really easy.</li><li>Part of my AS3 utilities.</li></ul>Dual helps you : <ul><li>Easily upgrade your application database from one version to another.</li><li>Run more than one query in one go on your database, this is not currently supported in Air.</li><li>Listen to only one set of events when accessing your database.</li><li>Implement robust and secure database code..</li></ul><b>Licensing</b> <br />
<br />
There is no license restrictions at all.  Obviously if you let me know, or even better let other people know that you are using it and where to get it, that would be great.  <br />
<br />
If you really need a license for legal reasons then I am happy for you to <a href=' http://sam.zoy.org/wtfpl/' target='blank'>apply this one</a>. <br />
<br />
Dual is open source and if you would like to improve it please feel free.  I have taken care to make sure that it is constructed well, there are no memory leaks caused by using the library and it is both easy to use and understand.  <br />
<br />
<b>Where I can you get it?</b><br />
<br />
Dual is available as part of my <a href='https://github.com/GarethShapiro/Actionscript-3-Utilities/tree/master/utilities/air/dual' target='blank'>Actionscript 3 /Air Utilities on GitHub<a/>, grab the <a href='https://github.com/GarethShapiro/Actionscript-3-Utilities/zipball/master'>zip</a>.<br />
<br />
]]></descriptionnnn>
 <category>Developer</category>
<comments>http://www.garethshapiro.com/index.php?itemid=49</comments>
 <pubDate>Tue, 3 Jan 2012 12:31:44 +0000</pubDate>
</item><item>
 <title>ActionScript 3 Frame Buffer</title>
 <link>http://www.garethshapiro.com/index.php?itemid=44</link>
<descriptionnnn><![CDATA[<div class='item_list_rightbox'><a href="http://www.garethshapiro.com/media/1/adobe_flash_logo.png">Flash Platform</a></div>All AS3 programmers have had to cope with situations where what they can see on the screen is different to what their code is telling them.  Within Air, Flex and Flash applications the two main contributors to this are; the Flash Player is single threaded, apart from a few exceptions in Air, and internally is based around a frame rate.<br />
<br />
Have you ever tried to measure something you have just added to the Display List and even though you can see it on the screen your measurement, something like width or height, is coming back as 0?  How about when you are preloading, does your preloader get stuck at 10% and then jump to 100% at the end?<b>Elastic Racetrack Cure</b><br />
<br />
First things first, download my <a href='https://github.com/GarethShapiro/Actionscript-3-Utilities/archives/master' target='blank'>Actionscript 3 utilities</a>.<br />
<br />
The reason why sometimes you can't measure items you have just added to the Display List in AS3 is because of the "Elastic Racetrack".  If you don't know what that is then I recommend you <a href='http://www.craftymind.com/2008/04/18/updated-elastic-racetrack-for-flash-9-and-avm2/' target='blank'>scoot off and read up about it first</a>.  Understanding this is <i>essential</i> for intermediate / advanced Actionscripters.<br />
<br />
One cure for the Elastic Racetrack is to use <a href='http://gskinner.com/libraries/' target='blank'>Grant Skinner's excellent Chunker</a> approach.  It's not always suitable for all situations though and a more straight forward approach is to simply wait 1 frame before carrying on with your measurement.  I recently had a project where I needed to wait 1 frame in quite a few places and so the <i>FrameBuffer</i> was born.<br />
<br />
Create a new Flex 4 project and type in the following code :<br />
<br />
<div class="actionscript"><span style="color: #66cc66;">&lt;</span>mx:Application <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; creationComplete=<span style="color: #ff0000;">&quot;setUp()&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayList</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _years:ArrayList = <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _years.<span style="color: #006600;">source</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;2010&quot;</span> , <span style="color: #ff0000;">&quot;2009&quot;</span> , <span style="color: #ff0000;">&quot;2008&quot;</span> <span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span style="color: #0066CC;">text</span> = &nbsp; <span style="color: #ff0000;">&quot; &nbsp; &nbsp; &nbsp; yearTabBar.width = &quot;</span> + yearTabBar.<span style="color: #0066CC;">width</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TabBar<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id=<span style="color: #ff0000;">&quot;yearTabBar&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataProvider=<span style="color: #ff0000;">&quot;{_years}&quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">/&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Text</span> id=<span style="color: #ff0000;">&quot;output&quot;</span><span style="color: #66cc66;">&gt;&lt;/</span>mx:Text<span style="color: #66cc66;">&gt;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></div><br />
When you publish you will see the Flex 4 Spark TabBar.<br />
<br />
<div style="text-align: center" class='img_box'><br />
<a href="http://www.garethshapiro.com/media/1/20110202-view-buffer-screen1.png">Spark Component TabBar</a></div><br />
<br />
Frustratingly the output text will tell you that : <br />
<br />
	yearTabBar.width = 0<br />
<br />
The reason is of course that we need to wait 1 frame for the Flash Player to get through the render part of it's cycle.  During this part the component is be measured and its width recorded.  <br />
<br />
There are many situations where this crops up and many ways of dealing with it.  The best approach is to architect your application differently so it does not fall victim to this.  Your <i>Views</i> should go through separate <i>Draw</i> and <i>Layout </i> phases and this problem will be avoided.  Like using <i>Chunker</i>, which I linked to above, this is not always possible or desirable.  It's not going to help your preloader for example. <br />
<br />
The easiest way is to set up an Event Handler to listen for <i>Event.ENTER_FRAME</i> and then to retrieve the width.  This is of course quite easy to do but on a recent project it was cropping up a bit and I was looking for an straight forward way achieve this and so I create the <i>FrameBuffer</i> utility.<br />
<br />
If you haven't done so already make the FrameBuffer code available to your project.<br />
<br />
	Step 1.  Create a folder called <i>com</i> inside your <i>src</i> folder.<br />
	Step 2.  Create a <i>garethshapiro</i> folder inside your <i>com</i> folder.<br />
	Step 3.  Add the <i>utilities</i> folder from the download and everything in it to the <i>garethshapiro</i> folder.<br />
<br />
Change the code you typed above to include the lines that have //2 at the end below <br />
<br />
<div class="actionscript"><span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayList</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">garethshapiro</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">framebuffer</span>.<span style="color: #006600;">FrameBuffer</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// 2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _years:ArrayList = <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create the TabBar</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _years.<span style="color: #006600;">source</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;2010&quot;</span> , <span style="color: #ff0000;">&quot;2009&quot;</span> , <span style="color: #ff0000;">&quot;2008&quot;</span> <span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span style="color: #0066CC;">text</span> = &nbsp; <span style="color: #ff0000;">&quot; &nbsp; &nbsp; &nbsp; yearTabBar.width = &quot;</span> + yearTabBar.<span style="color: #0066CC;">width</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> __frameBuffer : FrameBuffer = <span style="color: #000000; font-weight: bold;">new</span> FrameBuffer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// 2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; __frameBuffer.<span style="color: #006600;">buffer</span><span style="color: #66cc66;">&#40;</span> &nbsp; measureTabBar &nbsp; <span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// 2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> measureTabBar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// 2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span style="color: #0066CC;">text</span> = &nbsp; <span style="color: #ff0000;">&quot; &nbsp; &nbsp; &nbsp; yearTabBar.width = &quot;</span> + yearTabBar.<span style="color: #0066CC;">width</span>; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// 2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// 2</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span></div><br />
This time the output text will tell you :<br />
<br />
	yearTabBar.width = 211<br />
<br />
A result.  Happy face.<br />
<br />
By default the <i>FrameBuffer</i> will wait 1 frame.  If you want it to wait longer then you can supply a second argument a <i>Number</i> which is the number of frames to wait.<br />
<br />
<div class="actionscript">__frameBuffer.<span style="color: #006600;">buffer</span><span style="color: #66cc66;">&#40;</span> &nbsp; measureTabBar &nbsp; , <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span>;</div><br />
<br />
It is also very likely that you would need to supply arguments to the method that is to be called and this is possible through another optional parameter.  The arguments to be supplied are wrapped up in an <i>Array</i>.<br />
<br />
<div class="actionscript">__frameBuffer.<span style="color: #006600;">buffer</span><span style="color: #66cc66;">&#40;</span> &nbsp; measureTabBar &nbsp; , <span style="color: #cc66cc;">5</span> , <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Trace Message&quot;</span> , <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</div> <br />
<b>Preloading</b><br />
<br />
To get this to help you in preloading simply divide your preloading tasks into pieces and at the end of each piece use the <i>FrameBuffer</i> to wait one frame before moving on to the next piece.  If you have a large amount of data then instead of having one for loop handle it all use some variables to keep track of how far you are in the data and only process a small amount each time, wait 1 frame, and carry on.<br />
<br />
<b>Context</b><br />
<br />
This code is still dependant on the frame rate of the Flash Player.  If you give the player too much to do in one frame everything in your application, including the <i>FrameBuffer</i> is going to wait until that code is finished.<br />
<br />
The <i>FrameBuffer</i> is the easiest way but not the most efficient way of solving this problem.  If you are writing code that is sensitive to performance then there are better ways of achieving results, two of which I have mentioned in this article.  We are adding a type of pause into our program.  Expecting better performance this way is the same as expecting more flavour from food by adding water.<br />
<br />
That aside quite often user feedback is more important than performance, especially when the difference is milliseconds.  This is not an article aimed at C++ programmers writing financial trading software after all.<br />
<br />
Hope this helps.]]></descriptionnnn>
 <category>Developer</category>
<comments>http://www.garethshapiro.com/index.php?itemid=44</comments>
 <pubDate>Thu, 3 Feb 2011 10:05:08 +0000</pubDate>
</item><item>
 <title>Flash Actionscript 3 : ViewBuffer</title>
 <link>http://www.garethshapiro.com/index.php?itemid=21</link>
<descriptionnnn><![CDATA[<div class='item_list_rightbox'><a href="http://www.garethshapiro.com/media/1/adobe_flash.png"></a></div>At the end of 2008 I worked on a Flash project for The Economist called 'The World in 2009'.    There was a graphic designer who was responsible for producing a world map vector and I wired it all up.  <br />
<br />
As you can imagine this artwork was intricate.  Each country had a border and a background colour that were separate objects, some text fields for labels, and as you would expect also grouped into continents.  The designer was using Adobe Illustrator to create the vector shapes and importing these into Flash and sending me the .fla<br />
<br />
The process was not very smooth.  There were changes to the artwork of course, Illustrator does not create MovieClips in the same way that you would manually and also when dealing with such an complex piece, old fashioned user error creeps in.<b>The Solution, ViewBuffer</b><br />
<br />
<a href="http://www.garethshapiro.com/media/downloads/ViewBuffer.as.zip">Download</a><br />
<br />
This made life a little difficult for me while developing the Actionscript 3 code.  The artwork was divided into regions so the files were easier to work with for the designer.  I would load each one using a Loader() class and attach it to the Display List.  I could reference the various objects, outlines / text fields / background colour clips,  inside them like so : <br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_1.png">Get a reference to a MovieClip inside a loaded SWF (The hard way)!!</a><br />
<br />
It is easy to see why this is not a good situation to be in.  One change to the structure and my paths would stop working.  There were also further complications with instance names which caused the same problem.  This is similar to how paths are constructed in Actionscript 2, with dot notation, so what is the best way of doing the same thing in Actionscript 3?<br />
<br />
The bottom line is I do not want to be hamstrung by changes either by the Art Director or the Graphic Designer on the project.  Changes are always going to happen and I looked to find a solution that simply accommodated them.  One of the greatest things about AS3 is the Display List structure.  The way that Display Objects are children of DisplayObjectContainers means that  we can automatically examine this structure, or part of it, and record each of the items in an Array.<br />
<br />
The ViewBuffer takes care of the path and presents the items to us in a straight forward list.  <br />
<br />
I will assume you know how to import packages into your AS3 projects so won't go into that in detail.  Obviously you need this line at the top of the code : <br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_2.png">Make sure you have access to the Class</a><br />
<br />
Once you have access to the ViewBuffer you need to make an instance of one : <br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_3.png">Create a new ViewBuffer</a><br />
<br />
Let's say that once again you have a Loader called europe_clip_loader and you have added to the the display list, your next step would be to to inspect it : <br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_4.png">&lt;br /&gt;
Inspect the top element of the Display List that we are interested in</a><br />
				<br />
In the above line of code the parameter is compulsory and it has to be a DisplayObjectContainer.  The reason I have called the DisplayObjectContainer you are inspecting a ViewComponent is that I am a massive fan of <a href="/tag/puremvc">PureMVC</a> and this is what they are called in that framework.  It seems to make sense because in Flex you would divide Views up into separate MXML files and they may not be on the Display List when you inspect them for the ViewBuffer.  Once you have inspected your ViewComponent you then use the instance name of the items in the ViewBuffer to get reference to them. <br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_5.png">Get a reference to a MovieClip inside a loaded SWF (The easy way)!!</a><br />
<br />
If this MovieClip gets moved around then no problem your code will still work.  If the instance name gets removed or changed then some more work is needed.  Perhaps the person creating the .fla file names the MovieClip incorrectly and calls it 'country_russia' (without the _mc) on the end.   <br />
<br />
<b>Taking a Look</b><br />
<br />
What you would do is first look at the buffer list to see the instance names of the items on there.  This is done like so : <br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_6.png">Output the ViewBuffer to the Output panel</a><br />
<br />
The first parameter of the showBufferList method is the function you want to use to display.  Here we are using the built in trace() method.  Do not put the brackets on, just the name of the function, just like an event handler.  The second parameter is optional and is a String.  This is the property of the item that you would like displayed.  The most useful is “name” but you may want to use “alpha” , “x” or “y” to tell you more details.  If you use one of the other properties then the name is also outputted to give you better results.<br />
<br />
I use a great debugging tool for Flash and Flex developing called <a href="http://code.google.com/p/flash-thunderbolt/" target='_blank'>Thunderbolt</a>.  This bit of code will output to Firebug, the web developer plug in for Firefox.  If you are using this technique you would show the details of the buffer list like so :<br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_7.png">&lt;br /&gt;
Output the ViewBuffer to Firebug</a><br />
<br />
Great but you may run into problems if after you have made up your ViewBuffer you remove or add an item and then try to reference it using getBufferListItemByName().  <br />
<br />
<b>Adding and Removing Items</b><br />
<br />
You can keep the ViewBuffer in synch by using addViewBufferItem() and removeViewBufferItem().<br />
<br />
These both work in exactly the same way  :<br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_8.png">Add a new item</a><br />
<br />
This will add item as a child of item_parent to both the Display List and the View Buffer.  Similarly with removing items : <br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_9.png">Remove an item</a><br />
<br />
This will remove item from both the Display List and the View Buffer.<br />
<br />
In both these examples item_parent needs to be a DisplayObjectContainer and item a DisplayObject.<br />
<br />
<b>Advanced Techniques</b><br />
<br />
This is quite a straight forward piece of code so there is only one Advanced Technique.  If you would like to exclude certain data types from the ViewBuffer you can specify these when you inspect the ViewComponent.  The second parameter of the ViewBuffer is an Array of Data Types to be excluded.<br />
<br />
<a href="http://www.garethshapiro.com/media/viewbuffer/as3_viewbuffer_10.png">Exclude StaticText and Shape Data Types from the ViewBuffer</a><br />
<br />
The reason for this is perhaps you are not interested in administering static items and you are trying make sure your swf performs as quickly as possible.  You may also be using a framework such as PureMVC where you have a different class for each View and you do not want global access to the items in other Views across all of the ViewBuffers in your application.<br />
<br />
I am sure this code can be improved, I have deliberately kept it from being too complicated.  If you do use it, or better yet, improve it please let me know and I'll incorporate the improvements for everyone.<br />
<br />
<a href="http://www.garethshapiro.com/media/downloads/ViewBuffer.as.zip">Download</a>]]></descriptionnnn>
 <category>Developer</category>
<comments>http://www.garethshapiro.com/index.php?itemid=21</comments>
 <pubDate>Tue, 28 Apr 2009 11:56:42 +0000</pubDate>
</item><item>
 <title>Search Engine Optimisation (SEO) Blog Plug In</title>
 <link>http://www.garethshapiro.com/index.php?itemid=20</link>
<descriptionnnn><![CDATA[<div class='item_list_rightbox'><a href="http://www.garethshapiro.com/media/1/20090401-nucleus.gif"></a></div>I have been using Google's excellent free <a href="http://www.google.com/webmasters/tools" target='blank'>Webmaster Tools</a> to make sure that this blog is in good shape as far as Search Engine Optimisation (SEO) is concerned.  One of the things I needed to improve were the description meta tags on each page but I could not find a plug in that would help me achieve this.  So I wrote one myself and it is free for anyone who uses the Nucleus blogging system to use.<b>Install</b><br />
<br />
1. Download the plug in from <a href="http://www.garethshapiro.com/media/downloads/NP_SimpleSEO.zip">here</a>.<br />
<br />
2. Unzip and you should end up with a file called NP_SimpleSEO.php<br />
<br />
3. Upload this file into your plug in folder using an FTP program.  Your plug in folder can be found at : yoursite/nucleus/plugins/<br />
<br />
4. Download the head.inc file that your template is using.  This can be found at : yoursite/skins/~skin name~/head.inc<br />
<br />
5. Open this file up using an editor.  If you don't have one don't use Word, rather use Notepad on a PC or TextEdit on a Mac.<br />
<br />
Remove this line :<br />
<br />
 &lt;meta name="description" content=" &lt;%blogsetting(desc)%&gt;" /&gt;<br />
<br />
Insert this line in it's place :<br />
<br />
 &lt;%SimpleSEO()%&gt; <br />
<br />
6.  Upload head.inc back into the same place.<br />
<br />
7.  Log in to the admin area of your Nucleus blog and click on Plugins which is under the Management section.  At the bottom of the page you should now be able to choose SimpleSEO from the drop down menu at the bottom.  Do this and click the 'Install Plugin' button.<br />
<br />
Done!<br />
<br />
<b>Use</b><br />
<br />
When you add or edit an item you will now have three new fields to fill in on the page under the heading <i>Simple SEO</i>.  Simply fill these in as you wish.  If you are using a robots.txt file then simply leave this field blank and no meta tags for robots will appear.  If you do not supply a description then the default one for the blog, which is found on the left hand menu under Settings will be used.]]></descriptionnnn>
 <category>Developer</category>
<comments>http://www.garethshapiro.com/index.php?itemid=20</comments>
 <pubDate>Wed, 1 Apr 2009 16:44:48 +0000</pubDate>
</item>
  </channel>
</rss>