<?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>guy in the chair . com &#187; community</title>
	<atom:link href="http://guyinthechair.com/category/community/feed/" rel="self" type="application/rss+xml" />
	<link>http://guyinthechair.com</link>
	<description>//the blog of Paul Taylor</description>
	<lastBuildDate>Fri, 18 Nov 2011 01:22:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>tinytlf Explorer App</title>
		<link>http://guyinthechair.com/2011/10/tinytlf-explorer-app/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tinytlf-explorer-app</link>
		<comments>http://guyinthechair.com/2011/10/tinytlf-explorer-app/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 07:33:18 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[tinytlf]]></category>
		<category><![CDATA[tinytlf demo app]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=781</guid>
		<description><![CDATA[I&#8217;ve written a little feature explorer app to showcase some of tinytlf&#8217;s latest features. You can play around with it below, or you can launch the demo app into a new window. You can manipulate the renderer by editing CSS or switching which HTML document is rendered. I threw in a circular paragraph renderer just [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a little feature explorer app to showcase some of tinytlf&#8217;s latest features. You can play around with it below, or you can <a href="http://guyinthechair.com/flash/tinytlf/2.0/explorer/TinyTLFDemo.html" target="_blank">launch the demo app into a new window.</a></p>
<p>You can manipulate the renderer by editing CSS or switching which HTML document is rendered. I threw in a circular paragraph renderer just for fun. I also included a time indicator to show how long Flash takes to parse each HTML source. Even though Flash takes forever to serialize Strings to XML, this shows that tinytlf renders it almost instantaneously every time. I&#8217;ll talk about this more in my next post.</p>
<p>This is now the official tinytlf demo, so I&#8217;ll be updating it as I add features in the future. To demonstrate tinytlf&#8217;s capabilities beyond sanitized HTML input, I&#8217;ve included examples from <a href="http://idlewords.com/" target="_blank">Idle Words</a> and the HTML version of <a href="https://plus.google.com/u/0/113556260101951952093/about" target="_blank">Christian Cantrell&#8217;s</a> eBook, <a href="http://www.livingdigitally.net/books/farmer_one/farmer_one.html" target="_blank">Farmer One</a>.</p>
<p><a href="https://github.com/guyinthechair/tinytlf" target="_blank">Watch or fork the project on Github.</a></p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="600" height="500">
      <param name="movie" value="http://guyinthechair.com/flash/tinytlf/2.0/explorer/TinyTLFDemo.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/flash/tinytlf/2.0/explorer/TinyTLFDemo.swf" width="600" height="500">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2011/10/tinytlf-explorer-app/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Design-by-Contract in RobotLegs 1.4</title>
		<link>http://guyinthechair.com/2011/07/design-by-contract-in-robotlegs-1-4/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=design-by-contract-in-robotlegs-1-4</link>
		<comments>http://guyinthechair.com/2011/07/design-by-contract-in-robotlegs-1-4/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 20:12:08 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[bitching]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[covariance]]></category>
		<category><![CDATA[invariance]]></category>
		<category><![CDATA[robotlegs]]></category>
		<category><![CDATA[robotlegs-variance-utility]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=754</guid>
		<description><![CDATA[If you talked to me at a conference sometime in the last nine months, chances are I ranted loudly about type-variant auto-mediation. At the time, I meant an implementation I wrote in PureMVC because I assumed robotlegs already supported covariant auto-mediation. It doesn&#8217;t. Explanation to follow. Flash and the City Before I begin, this was [...]]]></description>
			<content:encoded><![CDATA[<p>If you talked to me at a conference sometime in the last nine months, chances are I ranted loudly about <a href="https://github.com/dnalot/robotlegs-utilities-variance">type-variant auto-mediation</a>. At the time, I meant an implementation I wrote in PureMVC because I assumed <a href="http://www.robotlegs.org/" title="robotlegs-as3" target="_blank">robotlegs</a> already supported covariant auto-mediation. It doesn&#8217;t. Explanation to follow.</p>
<h2>Flash and the City</h2>
<p>Before I begin, this was the topic of my <a href="http://fatc.co/" title="Flash and the City" target="_blank">Flash and the City</a> talk this year. You can find the slides <a href="http://www.slideshare.net/pauletaylor/design-by-contract-in-robotlegs-as3" title="Design by Contract in robotlegs AS3" target="_blank">here</a> if you want.</p>
<h2>Auto Mediation</h2>
<p>Robotlegs has an interface called <a href="http://api.robotlegs.org/org/robotlegs/core/IMediatorMap.html" title="IMediatorMap interface" target="_blank">IMediatorMap</a>, which maps UIComponent types to Mediator types. Robotlegs watches the display list, and when instances of any mapped components are added to (or removed from) the stage, it will create (or destroy) an instance of the mapped Mediator for it.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">mediatorMap<span style="color: #000066; font-weight: bold;">.</span>mapView<span style="color: #000000;">&#40;</span>MyViewType<span style="color: #000066; font-weight: bold;">,</span> MyViewMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Each time you create and add a new instance of MyViewType to the stage, a corresponding MyViewMediator instance will be created.</p>
<h2>Problems</h2>
<p>The problem with MediatorMap is two-fold:</p>
<ol>
<li>It enforces an arbitrary restriction that each View instance can only have one Mediator instance. This is dangerous, because it blurs the line between view logic and business logic. Does this functionality belong in the UIComponent or the Mediator? Developers end up writing Views and Mediators with poor separation of concerns, and inevitably overflow View logic into their Mediators. Mediators aren&#8217;t seen as reusable bits of business logic, they&#8217;re seen as an extension to the UI component.
</li>
<li>MediatorMap is a <a href="http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)" title="Covariance and Contravariance" target="_blank">type invariant</a> mapping. The map creates a Mediator only if the view component is an exact instance of a mapped type.
<p>For example, if you register the <code>MyViewComponentMediator</code> type for <code>MyViewComponent</code>, subclasses of <code>MyViewComponent</code> (say, <code>MyViewComponentSubclass</code>) don&#8217;t get an instance of <code>MyViewComponentMediator</code> automatically created for them.</p>
<p>If <code>MyViewComponent</code> encapsulates enough useful functionality to supplement it with its own Mediator, doesn&#8217;t <code>MyViewComponentSubclass</code> still implement (through inheritance) and require the same functionality from the MediatorMap? Sure, the subclass may override certain functions, but that&#8217;s just polymorphism at work.
</li>
</ol>
<h2>Covariant Auto Mediation</h2>
<p>The idea behind <a href="http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)" title="Covariance and Contravariance" target="_blank">covariant</a> mediation is that a Mediator is created if a component <em>extends</em> or <em>implements</em> a mapped view component type.</p>
<p>Here&#8217;s the practical difference between an invariant check and a covariant check:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//Invariant check:</span>
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>myViewComponent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">constructor</span> == MyViewComponent<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
    <span style="color: #009900; font-style: italic;">//Do something</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//Covariant check:</span>
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>myViewComponent <span style="color: #0033ff; font-weight: bold;">is</span> MyViewComponent<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
    <span style="color: #009900; font-style: italic;">//Do something else</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If the instance of <code>myViewComponent</code> is actually a subclass of the MyViewComponent type, the first check will fail, but the second check will pass.</p>
<h2>Extends or Implements</h2>
<p>Extending classes for functionality is all well and good, but it&#8217;s not as flexible or as clean as implementing an interface. For starters, AS3 allows you only one parent class, so you can&#8217;t compose much functionality through inheritance before running into the <a href="http://en.wikipedia.org/wiki/Diamond_problem" title="The Diamond Problem -- why multiple inheritance is problematic" target="_blank">diamond problem</a>.</p>
<p>Before I go any further, yes, this means you can map a Mediator for all instances or subclasses of <code>Sprite</code> or <code>UIComponent</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// An instance of SpriteMediator will be created each time an instance</span>
<span style="color: #009900; font-style: italic;">// or subclass of Sprite is added to the display list. Crazy, huh?</span>
<span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>mapMediator<span style="color: #000000;">&#40;</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">,</span> SpriteMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Naturally this introduces performance problems, so everything from the &#8220;flash.*&#8221; and &#8220;mx.*&#8221; packages are filtered out by default.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>registerPackageFilter<span style="color: #000000;">&#40;</span><span style="color: #990000;">'flash.*'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>registerPackageFilter<span style="color: #000000;">&#40;</span><span style="color: #990000;">'mx.*'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>And you can add your own package filter definitions (like if you&#8217;ve got a particle emitter and want to skip inspection of each particle):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>registerPackageFilter<span style="color: #000000;">&#40;</span><span style="color: #990000;">'com.myApp.particles.*'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Anyway, covariantly auto-mediating base classes is alright I guess, but who wants to maintain a complex inheritance tree? Not me. <strong>The real sexy magic happens when you start mapping Interfaces for auto-mediation.</strong></p>
<p>Interfaces are covariantly checked:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>myComponent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">constructor</span> == IMyInterface<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//will always be false</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>myComponent <span style="color: #0033ff; font-weight: bold;">is</span> IMyInterface<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//can evaluate to true</span></pre></div></div>

<h2>Demo Time</h2>
<p>This post has been highly theoretical so far, and if you let me continue extolling the virtues of designing interfaces to apply behaviors to components via covariant mediation it will only devolve into something more abstract and academic.</p>
<p>So instead, I&#8217;ll show off some code to do it for me. Here&#8217;s the demo app I created for my FATC talk.</p>
<p>This demo has three progressively more impressive examples of common problems solved in very few LOC using covariant mediation:</p>
<ol>
<li>An example of handling system-wide error events.</li>
<li>An example of managing selected screen state.</li>
<li>An example DataGrid where each cell is representative of a unique and open streaming channel from the server.</li>
</ol>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="595" height="400">
      <param name="movie" value="http://guyinthechair.com/wp-content/flex/covariant_mediation/FATC.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/flex/covariant_mediation/FATC.swf" width="595" height="400">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h2>Rundown</h2>
<p>I&#8217;ll run through just the meaty parts of this demo. The source for the whole thing is <a href="http://guyinthechair.com/wp-content/flex/covariant_mediation/srcview/index.html" target="_blank">here</a>.</p>
<h3>App.mxml and IoC Mappings</h3>
<p>Here&#8217;s the important part of the Application MXML file:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> createChildren<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// Normally these IoC mappings are done inside the Context.</span>
	<span style="color: #009900; font-style: italic;">// Do them here because we have access to our children.</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> context<span style="color: #000066; font-weight: bold;">:</span>FATC_Context = <span style="color: #0033ff; font-weight: bold;">new</span> FATC_Context<span style="color: #000000;">&#40;</span>systemManager <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">:</span>IVariantMediatorMap = context<span style="color: #000066; font-weight: bold;">.</span>variantMap<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Map implementations of ISystemErrorUI to have</span>
	<span style="color: #009900; font-style: italic;">// SystemErrorUIMediators registered for them automatically</span>
	<span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>mapMediator<span style="color: #000000;">&#40;</span>ISystemErrorUI<span style="color: #000066; font-weight: bold;">,</span> SystemErrorUIMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">// Map implementations of IScreen to have ScreenMediators</span>
	<span style="color: #009900; font-style: italic;">// registered for them automatically</span>
	<span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>mapMediator<span style="color: #000000;">&#40;</span>IScreen<span style="color: #000066; font-weight: bold;">,</span> ScreenMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">// Map implementations of IStreamingServiceUI to have</span>
	<span style="color: #009900; font-style: italic;">// StreamingServiceUIMediator registered for them automatically</span>
	<span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>mapMediator<span style="color: #000000;">&#40;</span>IStreamingServiceUI<span style="color: #000066; font-weight: bold;">,</span> StreamingServiceUIMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> injector<span style="color: #000066; font-weight: bold;">:</span>IInjector = context<span style="color: #000066; font-weight: bold;">.</span>theInjector<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">// Tell the injector to create and inject a new instance of</span>
	<span style="color: #009900; font-style: italic;">// StreamingService each time it sees a dependency on IStreamingService</span>
	injector<span style="color: #000066; font-weight: bold;">.</span>mapClass<span style="color: #000000;">&#40;</span>IStreamingService<span style="color: #000066; font-weight: bold;">,</span> StreamingService<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000066; font-weight: bold;">.</span>createChildren<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Register the mediators for the Screens class immediately.</span>
	<span style="color: #009900; font-style: italic;">// (normally the registration is deferred to the next frame).</span>
	<span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>registerMediators<span style="color: #000000;">&#40;</span>screens<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h3>ISystemErrorUI and the <a href="http://guyinthechair.com/wp-content/flex/covariant_mediation/srcview/source/ptaylor/bdd/errors/SystemErrorUIMediator.as.html" target="_blank">SystemErrorUIMediator</a></h3>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> interface ISystemErrorUI
<span style="color: #000000;">&#123;</span>
	<span style="color: #339966; font-weight: bold;">function</span> handleError<span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span>SystemErrorEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> errorAcknowledged<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>ISignal<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Components that are interested in being notified when errors occur can implement the <code>ISystemErrorUI</code> interface. Whenever an error happens in the Application, it&#8217;s the responsibility of the errored operation to dispatch a SystemErrorEvent, either bubbling on the display list, or on robotlegs&#8217; shared <code>eventBus</code>. Each instance of SystemErrorUIMediator will notify its ISystemErrorUI instance.</p>
<h3>IScreen and the <a href="http://guyinthechair.com/wp-content/flex/covariant_mediation/srcview/source/ptaylor/bdd/screens/ScreenMediator.as.html" target="_blank">ScreenMediator</a></h3>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> interface IScreen
<span style="color: #000000;">&#123;</span>
	<span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> selectedScreen<span style="color: #000000;">&#40;</span>screen<span style="color: #000066; font-weight: bold;">:</span>IScreen<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> screenChangedSignal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>ScreenChangedSignal<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Implementations of IScreen will be notified when the <code>selectedScreen</code> changes. Implementations of IScreen can cause the screen to change by dispatching their <code>screenChangedSignal</code> member.</p>
<p>Whether the implementor of IScreen truly wishes to change the <code>selectedScreen</code>, or whether it&#8217;s simply interested when the <code>selectedScreen</code> is changed, the ScreenMediator doesn&#8217;t care. In the demo, three of the four implementations of <code>IScreen</code> respond uniquely when their <code>selectedScreen</code> setter is called:</p>
<ol>
<li>The <code><a href="http://guyinthechair.com/wp-content/flex/covariant_mediation/srcview/source/ptaylor/bdd/screens/components/Screens.mxml.html" target="_blank">Screens</a></code> class is a ViewStack. When its <code>selectedScreen</code> setter is called, it checks first whether the <code>IScreen</code> instance is a child of itself. If not, <code>Screens</code> adds it as a child. <code>Screens</code> ultimately changes its <code>selectedChild</code> property to the new <code>IScreen</code>.</li>
<li>The <code><a href="http://guyinthechair.com/wp-content/flex/covariant_mediation/srcview/source/ptaylor/bdd/errors/components/ErrorNotificationView.mxml.html" target="_blank">ErrorNotificationView</a></code> class is the bar at the top that drops down when an error occurs. If the bar is showing and the <code>selectedScreen</code> setter is called, the bar hides itself.</li>
<li>The <code><a href="http://guyinthechair.com/wp-content/flex/covariant_mediation/srcview/source/ptaylor/bdd/grid/components/StreamingServiceItemRenderer.as.html" target="_blank">StreamingServiceItemRenderer</a></code> class is the item renderer for the DataGrid. When the <code>selectedScreen</code> changes to and from the <code>GridScreen</code> instance, <code>StreamingServiceItemRenderer</code> starts or stops the incoming data stream. In this way, we can shut down any data sources for screens that aren&#8217;t currently visible.</li>
</ol>
<h3>IStreamingServiceUI and the <a href="http://guyinthechair.com/wp-content/flex/covariant_mediation/srcview/source/ptaylor/bdd/grid/StreamingServiceUIMediator.as.html" target="_blank">StreamingServiceUIMediator</a></h3>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> interface IStreamingServiceUI
<span style="color: #000000;">&#123;</span>
	<span style="color: #339966; font-weight: bold;">function</span> setStreamData<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span>StreamData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> updateStreamInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>ChangeStreamInfoSignal<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>There&#8217;s only one implementation of <code>IStreamingServiceUI</code>: <code><a href="http://guyinthechair.com/wp-content/flex/covariant_mediation/srcview/source/ptaylor/bdd/grid/components/StreamingServiceItemRenderer.as.html" target="_blank">StreamingServiceItemRenderer</a></code>. <code>StreamingServiceItemRenderer</code> is the item renderer for each cell in the DataGrid.</p>
<p><code>StreamingServiceItemRenderer</code> takes advantage of the fact that the DataGrid reuses its itemRenderers. When the user scrolls, the DataGrid sets in a new value for <code>data</code>. When that happens, the itemRenderer dispatches its <code>updateStreamInfo</code> member Signal.</p>
<p>When the UI dispatches its <code>updateStreamInfo</code> Signal, <code>StreamingServiceUIMediator</code> tells the service instance the new channel name. Then, the service closes its current channel, and opens a stream with the new channel name.</p>
<p>Because the DataGrid reuses its itemRenderers, and the itemRenderers dispatch changes in its data values to its Mediator, the Mediator can reuse its service instance, which manages opening and closing streams. </p>
<p><strong>This means we only keep open connections for visible cells.</strong></p>
<p>Pretty cool, huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2011/07/design-by-contract-in-robotlegs-1-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Better Describe Type Cache</title>
		<link>http://guyinthechair.com/2011/02/a-better-describetypecache/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-better-describetypecache</link>
		<comments>http://guyinthechair.com/2011/02/a-better-describetypecache/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 01:01:01 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[describeType]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=672</guid>
		<description><![CDATA[I don&#8217;t always work with the Flex Framework, so over and over I&#8217;ve written the following: package my.project.package.utils &#123; public class Type &#123; private static const cache:Dictionary = new Dictionary&#40;false&#41;; public static function describe&#40;value:Object&#41;:XML&#123;&#125;; &#125; &#125; The describe function caches the results of a call to describeType() based on the type of Class passed in [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t always work with the Flex Framework, so over and over I&#8217;ve written the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> my<span style="color: #000066; font-weight: bold;">.</span>project<span style="color: #000066; font-weight: bold;">.</span><span style="color: #9900cc; font-weight: bold;">package</span><span style="color: #000066; font-weight: bold;">.</span>utils
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Type
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> static const cache<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> describe<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The describe function caches the results of a call to describeType() based on the type of Class passed in as the Value. But it&#8217;s super ugly! All over the place I&#8217;ve had to reference a static class: &#8220;Type.describe(myObject);&#8221; <strong>lame</strong>.</p>
<p>Why can&#8217;t the results of describeType() just be cached in the player? Maybe it is now and I just don&#8217;t know it? If so, please tell me!</p>
<p>So <a href="https://github.com/guyinthechair/as3-gestures/blob/master/src/org/tinytlf/utils/reflect.as">here&#8217;s the solution</a> if you&#8217;d rather have a global function than a static method call:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> org<span style="color: #000066; font-weight: bold;">.</span>tinytlf<span style="color: #000066; font-weight: bold;">.</span>utils
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.*;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> reflect<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">,</span> refreshCache<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span>
	<span style="color: #000000;">&#123;</span>
		const typeCache<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = ReflectionCache<span style="color: #000066; font-weight: bold;">.</span>cache<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span> <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">Class</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span> <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">Proxy</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">type</span> = <span style="color: #004993;">getDefinitionByName</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">getQualifiedClassName</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span> <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">type</span> = <span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span>
				<span style="color: #004993;">type</span> = <span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">constructor</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>refreshCache <span style="color: #000066; font-weight: bold;">||</span> typeCache<span style="color: #000000;">&#91;</span><span style="color: #004993;">type</span><span style="color: #000000;">&#93;</span> == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
			typeCache<span style="color: #000000;">&#91;</span><span style="color: #004993;">type</span><span style="color: #000000;">&#93;</span> = <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">describeType</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">return</span> typeCache<span style="color: #000000;">&#91;</span><span style="color: #004993;">type</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Dictionary</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> ReflectionCache
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> static const cache<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>An internal class! Yipee! Static, but internalized. Until now I didn&#8217;t think you could store a static stateful reference for global functions to use. </p>
<p>Now you can go around all over the place calling &#8220;reflect(myObject);&#8221;, enjoying the convenience of describeType() and the benefits of using a static method.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2011/02/a-better-describetypecache/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>From Flash to Objective-C Part 1: Syntax</title>
		<link>http://guyinthechair.com/2011/02/flash-to-objective-c-syntax-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=flash-to-objective-c-syntax-part-1</link>
		<comments>http://guyinthechair.com/2011/02/flash-to-objective-c-syntax-part-1/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 17:49:52 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[community]]></category>
		<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Syntax]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=630</guid>
		<description><![CDATA[Face it: Apple&#8217;s done a great job with the iOS UI. Consider this an axiom for the rest of the post. I&#8217;m not going to try and convince you if you disagree, and I&#8217;m not going to rehash what boils down to a religious debate. Their HIG is clutch. But programming for it is crazy! [...]]]></description>
			<content:encoded><![CDATA[<p>Face it: Apple&#8217;s done a great job with the iOS UI. Consider this an axiom for the rest of the post. I&#8217;m not going to try and convince you if you disagree, and I&#8217;m not going to rehash what boils down to a religious debate. Their <a href="http://www.google.com/url?sa=t&#038;source=web&#038;cd=1&#038;ved=0CBMQFjAA&#038;url=http%3A%2F%2Fdeveloper.apple.com%2Flibrary%2Fmac%2Fdocumentation%2FUserExperience%2FConceptual%2FAppleHIGuidelines%2FXHIGIntro%2FXHIGIntro.html&#038;ei=4SBDTem-AoWcgQeit8XuAQ&#038;usg=AFQjCNEcUV4xiwK2PW9wgW1N_o63IiGNow" title="Apple Human Interface Guidelines">HIG</a> is clutch.</p>
<p>But programming for it is crazy! Have you seen this language? What is this shit?<br />
<img src="http://guyinthechair.com/wp-content/uploads/2011/01/obj-c_code_snippet.png" alt="Are the designers of Objective-C insane??" title="obj-c_code_snippet" width="600" height="202" class="aligncenter wp-image-631" /></p>
<h1>Relax</h1>
<p>This post is Objective-C syntax for the average Flash developer. It isn&#8217;t that scary. The colors are just different than you&#8217;re used to. And you&#8217;ll have to know or learn C, but don&#8217;t worry if you&#8217;re unfamiliar, I have faith you&#8217;ll pick it up quick enough. Because you&#8217;re creative and curious and you like learning new things dammit.</p>
<h1>Syntax</h1>
<p>So why haven&#8217;t you jumped into iOS? For me, it was the syntax. So now I&#8217;m going to compare the syntax of the languages from an <a href="http://jessewarden.com/">AS3 dev&#8217;s</a> point of view. In the end, I hope you won&#8217;t feel as intimidated as I did by this weirdly beautiful language.</p>
<h1>Disclaimer</h1>
<p>I&#8217;m still learning this stuff too. If I&#8217;m wrong on anything, please post it in the comments. I&#8217;m trying to disseminate useful information, things that took me a bit of studying to figure out, in the hopes that it won&#8217;t take you as long.</p>
<h2>Primitives</h2>
<p>There are a few keyword differences:</p>
<h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">AS3		Objective<span style="color: #000066; font-weight: bold;">-</span>C
<span style="color: #0033ff; font-weight: bold;">true</span>		YES
<span style="color: #0033ff; font-weight: bold;">false</span>		NO
<span style="color: #0033ff; font-weight: bold;">null</span>		nil
<span style="color: #0033ff; font-weight: bold;">this</span>		self</pre></div></div>

</h4>
<h2>Variables</h2>
<p>Variable declaration and assignment:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// AS3</span>
<span style="color: #6699cc; font-weight: bold;">var</span> myInteger<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Objective-C</span>
<span style="color: #a61390;">int</span> myInteger <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>;</pre></div></div>

<p>You can see, this isn&#8217;t any different from C++, Java, C#, etc. The difference from AS3 is the lack of the required <strong>var</strong> or <strong>const</strong> keyword, and the type is specified <strong>before</strong> the variable.</p>
<h3>Memory Allocation</h3>
<p>Something we don&#8217;t typically think about in AS3: stack vs. heap allocation. </p>
<p>The Stack is a LIFO (last in, first out) pool of memory blocks that are allocated/deallocated very quickly. Each time you call a function, a block of memory is allocated for the function&#8217;s scope. When you return from the function, the block of memory is released back to the stack. This means stack-managed memory blocks are reused very frequently, therefore is mostly allocated from RAM or even the CPU&#8217;s cache, making it extremely fast.</p>
<p>The Heap is more complex, and allocates and deallocates memory based on usage patterns. I am not remotely familiar with how Objective-C allocates memory from The Heap, but in general, allocating/deallocating memory from the heap takes longer than from the stack.</p>
<p><a href="http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap">Here&#8217;s a better explanation of the difference between the stack and the heap.</a> This stuff is just generally good to know.</p>
<h3>Values</h3>
<p>Values are primitive types, allocated on the stack, and passed by value, or copied. That is, if you pass the variable as an argument to a function, the variable&#8217;s <strong>value</strong> is copied then passed in.</p>
<h4>Structs</h4>
<p>A struct (short for <strong>&#8220;structure&#8221;</strong>), is a type that stores multiple values. AS3 doesn&#8217;t have structs, but we typically mimic the behavior of structs with <strong>Value Objects</strong> (VOs). But when structs are passed, they are passed by value, not reference. When you pass a struct (such as CGRect in Objective-C), the struct is essentially copied and fed into the target method.</p>
<h3>Pointers</h3>
<p>Pointers are a special data type that points to a location in memory allocated from The Heap. When a variable is typed to a pointer, accessing that variable will redirect you to the value stored at the pointer&#8217;s memory address. Pointers typically point to object instances, partly because objects have state and it won&#8217;t do to pass objects by value.</p>
<p>More about pointers at Wikipedia <a href="http://en.wikipedia.org/wiki/Pointer_(computing)">here</a>.</p>
<p>The Objective-C syntax to designate pointers is to add a star (<strong>*</strong>) between the type and the variable name:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIButton <span style="color: #002200;">*</span>myButton <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIButton alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>This means var <code>myButton</code> is a pointer that points to a <code>UIButton</code> instance somewhere in memory.</p>
<h2>Methods</h2>
<p>Objective-C has no concept of <span style="text-decoration:line-through;">access modifiers or</span> namespaces. For the purpose of this writeup, I&#8217;ll only use public methods. For familiarity&#8217;s sake, I&#8217;m using the <strong>addChild</strong> method signature of the <strong>DisplayObjectContainer</strong> class in my examples. Also, this post isn&#8217;t meant to introduce any Objective-C paradigms, obviously Cocoa doesn&#8217;t do DisplayObjects and event listeners like Flash does.</p>
<h3>Anatomy</h3>
<p>In AS3, functions are declared in this pattern:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">namespace</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">parameters</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>Type<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>In Objective-C, you have the exact same options, just moved around a bit:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>Type<span style="color: #002200;">&#41;</span>name<span style="color: #002200;">:</span> parameters;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>DisplayObject <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>addChild<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>DisplayObject <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>child;</pre></div></div>

<p>So in comparison:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>DisplayObject <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>addChild<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>DisplayObject <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>child;</pre></div></div>

<p>Say you&#8217;re writing the addChild method signature of the DisplayObjectContainer class:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">public function addChild<span style="color: #002200;">&#40;</span>child<span style="color: #002200;">:</span>DisplayObject<span style="color: #002200;">&#41;</span><span style="color: #002200;">:</span>DisplayObject;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>DisplayObject <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>add<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>DisplayObject <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>child</pre></div></div>

<h4>Multiple Parameters</h4>
<p>In AS3, you want more parameters, you separate them by commas:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Function</span><span style="color: #000066; font-weight: bold;">,</span> useCapture<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> priority<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> useWeakReference<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span></pre></div></div>

<p>In Objective-C, you name them:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>addEventListener<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>type listener<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">SEL</span><span style="color: #002200;">&#41;</span>listener useCapture<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>useCapture priority<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>priority useWeakReference<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>useWeakReference</pre></div></div>

<p>This is just to show 1-1 parity with AS3. Because the order and name of the parameters is what makes up the method name, you could also write this method something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>addEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>type withListener<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">SEL</span><span style="color: #002200;">&#41;</span>callback usingCapture<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>phase withPriority<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>priority andWeakReference<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>weakReference</pre></div></div>

<p>This way, the method reads almost like a sentence: <strong>&#8220;add event type String, with listener SEL, using capture phase BOOL, with priority int, and weak reference BOOL.&#8221;</strong></p>
<h4>Static Functions</h4>
<p>In AS3, you declare a static function with the <strong>static</strong> keyword:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> instanceFunction<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> staticFunction<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>In Objective-C, you put a + in front of the method declaration:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>instanceFunction;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>staticFunction;</pre></div></div>

<h3>Calling Methods</h3>
<p>In AS3, if you&#8217;re calling a method, it&#8217;s straightforward like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">mySprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>myChild<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Here&#8217;s the same thing in Objective-C:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>mySprite addChild<span style="color: #002200;">:</span>myChild<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>And the two lines side-by-side:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">mySprite.addChild<span style="color: #002200;">&#40;</span>myChild<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#91;</span>mySprite addChild<span style="color: #002200;">:</span>myChild<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Here&#8217;s calling our pretend addEventListener function from before:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Calling our fictitious addEventListener method:</span>
<span style="color: #002200;">&#91;</span>dispatcher addEvent<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;mouseDown&quot;</span> withListener<span style="color: #002200;">:^</span><span style="color: #002200;">&#123;</span><span style="color: #11740a; font-style: italic;">/* do something */</span><span style="color: #002200;">&#125;</span> usingCapture<span style="color: #002200;">:</span>no withPriority<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> andWeakReference<span style="color: #002200;">:</span>no<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Classes</h2>
<p>In Objective-C, each class is composed of <strong>two</strong> files. One is called the <strong>header</strong> file (suffix <strong>.h</strong>), the other is the <strong>implementation</strong> file (suffix <strong>.m</strong>). This is a C convention, since C doesn&#8217;t have proper classes.</p>
<h3>Constructors</h3>
<p>ActionScript has one constructor, it&#8217;s a function named after the Class it&#8217;s constructing. There are language reasons for this, primarily because deep down, AS3 isn&#8217;t that different from JavaScript, and each class is really just one big closure. But that&#8217;s a topic for another time.</p>
<p>Objective-C has what are called &#8220;designated initializers.&#8221; A designated initializer is pretty much the same idea as a constructor. A designated initializer is just a function that returns <strong>self</strong>, the Object&#8217;s reference to itself (AS3&#8242;s equivalent of <strong>this</strong>). Since designated initializers don&#8217;t have to be named after the class, there can be many, each taking different initialization values. This is essentially constructor overloading.</p>
<p>So where in AS3, you&#8217;d write:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MyClass<span style="color: #000000;">&#40;</span>required<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">,</span> optional1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> optional2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>You could write the following in Objective-C:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init; <span style="color: #11740a; font-style: italic;">//no required options, can leave this out if you wish</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>required;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">:</span>required withOption<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>option1;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">:</span>required withOption<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>option1 andAnother<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>option2;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">:</span>required orJust<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>option2;</pre></div></div>

<p>By convention, initializers start with some variation of the word &#8220;init.&#8221;</p>
<h3>Headers</h3>
<p>A header file is loosely analogous to an <strong>Interface</strong> in ActionScript 3. The header file declares all the publicly available functions and getters/setters available on the object. The header also declares what our Class inherits from, and the interfaces our Class implements. For this reason, what ActionScript actually calls an Interface, Objective-C calls a Protocol.</p>
<p>In short, all the API is declared in header files.</p>
<h4>Implementation</h4>
<p>The second part of a Class is the implementation. The implementation is the actual method and property implementation of the header file for the Class.</p>
<h4>Examples</h4>
<p><strong>ExampleClass.as:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>ptaylor<span style="color: #000066; font-weight: bold;">.</span>blog <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ExampleClass <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Object</span> implements IMyInterface<span style="color: #000066; font-weight: bold;">,</span> IOtherInterface <span style="color: #000000;">&#123;</span>
        <span style="color: #009900; font-style: italic;">//Constructor</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ExampleClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #009900; font-style: italic;">//do stuff</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>ExampleClass.h:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #a61390;">@interface</span> ExampleClass <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> &lt;IMyInterface, IOtherInterface&gt;
<span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The <strong>@interface</strong> declaration tells Objective-C that this is a header file, followed by the header&#8217;s name, <strong>ExampleClass</strong>. The following colon (<strong>:</strong>) declares what type this Class will extend from. Protocol (AS3 Interfaces) implementation declaration happens after the superclass declaration, inside the <strong>&lt; &gt;</strong> block.</p>
<p><strong>ExampleClass.m:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;ExampleClass.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> ExampleClass
&nbsp;
<span style="color: #11740a; font-style: italic;">//constructor</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init<span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">//do stuff</span>
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The <strong>@implementation</strong> declaration tells Objective-C what header this file is implementing.</p>
<p>That&#8217;s it. That&#8217;s all I&#8217;ve got. I&#8217;ve skimmed over and given you the fifty-thousand foot overview of the Objective-C continent. As always, post some shit in the comments if I&#8217;m wrong or you liked this or whatever.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2011/02/flash-to-objective-c-syntax-part-1/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Fun With Comments</title>
		<link>http://guyinthechair.com/2011/01/fun-with-comments/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fun-with-comments</link>
		<comments>http://guyinthechair.com/2011/01/fun-with-comments/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 23:36:41 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=627</guid>
		<description><![CDATA[Found this comment from a commit in November 2010. Had to repost it here. In case anybody else does this too, know you&#8217;re not alone. At least the code this describes passes the unit tests. //// // Everything after this point is basically magic. It was written during // one coffee fueled weekend, and to [...]]]></description>
			<content:encoded><![CDATA[<p>Found this comment from a commit in <a href="https://github.com/guyinthechair/tinytlf/blob/880733788f62dbc2f09a6724ed883b7e40365b47/tinytlf-gestures/src/org/tinytlf/interaction/gestures/Gesture.as#L54">November 2010</a>. Had to repost it here. In case anybody else does this too, know you&#8217;re not alone. At least the code this describes passes the unit tests.</p>
<blockquote>
<p>		////<br />
		// Everything after this point is basically magic. It was written during<br />
		// one coffee fueled weekend, and to be honest, I don&#8217;t remember much of<br />
		// it. That night is just a blur in my memory. Modify at your own peril.<br />
		//<br />
		// Here be dragons.<br />
		// (I&#8217;ve always felt that any serious library needs this comment at<br />
		// least once).<br />
		////
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2011/01/fun-with-comments/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tinytlf Updates and new Experiments</title>
		<link>http://guyinthechair.com/2010/11/tinytlf-updates-and-new-experiments/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tinytlf-updates-and-new-experiments</link>
		<comments>http://guyinthechair.com/2010/11/tinytlf-updates-and-new-experiments/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 17:50:15 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[tinytlf]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=601</guid>
		<description><![CDATA[Sorry for the dearth of tinytlf posts lately, I&#8217;ve been head-down coding tons of new stuff. If you don&#8217;t believe me, check out the git repository history. I&#8217;m working on an official tinytlf demo explorer app, ala minimalcomps but it&#8217;s going to let you do lots of cool stuff. In the meantime, I&#8217;ll post a [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for the dearth of tinytlf posts lately, I&#8217;ve been head-down coding tons of new stuff. If you don&#8217;t believe me, check out the <a href="https://github.com/guyinthechair/tinytlf/commits/master">git repository history</a>.</p>
<p>I&#8217;m working on an official tinytlf demo explorer app, ala <a href="http://minimalcomps.com/">minimalcomps</a> but it&#8217;s going to let you do lots of cool stuff. In the meantime, I&#8217;ll post a few choice demos to this post, kind of show off what I&#8217;ve been working on.</p>
<h2>Mobile TextField</h2>
<p>First up, huge updates to gestures, behaviors, and decorations. So much that I&#8217;ve been able to come up with this demo, primarily meant for Android devices, but still usable on the desktop. Highlight in this TextField:<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="480`" height="854">
      <param name="movie" value="http://guyinthechair.com/flash/tinytlf/demos/Android.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/flash/tinytlf/demos/Android.swf" width="480`" height="854">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
 </p>
<h2>Better HTML support</h2>
<p>Here&#8217;s some awesome HTML demos that <a href="http://twitter.com/tanya">Tanya Gray</a> has put together&#8230;<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_3" width="600" height="600">
      <param name="movie" value="http://guyinthechair.com/flash/tinytlf/demos/KittehFlow.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/flash/tinytlf/demos/KittehFlow.swf" width="600" height="600">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_4" width="600" height="600">
      <param name="movie" value="http://guyinthechair.com/flash/tinytlf/demos/KittehHistoryFlow.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/flash/tinytlf/demos/KittehHistoryFlow.swf" width="600" height="600">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
 </p>
<p>and&#8230; maybe Divs and Tables?<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_5" width="600" height="600">
      <param name="movie" value="http://guyinthechair.com/flash/tinytlf/demos/TinyTLFDemo.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/flash/tinytlf/demos/TinyTLFDemo.swf" width="600" height="600">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
 </p>
<h2>Advanced Constraint Layouts</h2>
<p>Floats aren&#8217;t just for HTML. Floats take advantage of a more generalized layout algorithm, which flows text around <em>constraints</em>. Floats are just a simple (Rectangle) constraint. You can implement the <em>ITextConstraint</em> interface with your own constraint implementation.</p>
<p>Here&#8217;s a few demos that show off the layout algorithm. Special thanks to <a href="http://algorithmist.wordpress.com/" target="_blank" title="The Algorithmist">Jim Armstrong (the Algorithmist)</a> for the spline math.<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_6" width="600" height="600">
      <param name="movie" value="http://guyinthechair.com/flash/tinytlf/demos/Spline.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/flash/tinytlf/demos/Spline.swf" width="600" height="600">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_7" width="600" height="600">
      <param name="movie" value="http://guyinthechair.com/flash/tinytlf/demos/SplineScrollerDemo.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/flash/tinytlf/demos/SplineScrollerDemo.swf" width="600" height="600">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
 </p>
<h2>Experimental, Just for Fun</h2>
<p>A gmail-style link editing behavior!<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_8" width="600" height="400">
      <param name="movie" value="http://guyinthechair.com/flash/tinytlf/demos/Ticonderoga.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/flash/tinytlf/demos/Ticonderoga.swf" width="600" height="400">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
 </p>
<p>So you can see I haven&#8217;t been idle! It&#8217;s just a lot of work. All the code for these demos is <a href="http://guyinthechair.com/flash/tinytlf/demos/srcview/source/">here</a>. Fork the framework at <a href="https://github.com/guyinthechair/tinytlf">github</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2010/11/tinytlf-updates-and-new-experiments/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Tinytlf at 360&#124;Flex DC and 360&#124;MAX</title>
		<link>http://guyinthechair.com/2010/09/tinytlf-at-360flex-dc-and-360max/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tinytlf-at-360flex-dc-and-360max</link>
		<comments>http://guyinthechair.com/2010/09/tinytlf-at-360flex-dc-and-360max/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 03:54:57 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[community]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=574</guid>
		<description><![CDATA[I haven&#8217;t been blogging as often these last two weeks because I&#8217;m spending a lot of time preparing for my 360&#124;Flex and 360&#124;MAX presentations. I&#8217;ve been developing some kickass features and demos that I have yet to discuss publicly, so if you&#8217;re in the mood to be wowed, show up to my presentations. 360&#124;Flex DC [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.360flex.com/" target="_blank" title="360 Flex Conference"><img src="http://guyinthechair.com/wp-content/uploads/2010/09/speakerbadge.png" alt="360|Flex Speaker" title="speakerbadge" width="200" height="211" class="aligncenter size-full wp-image-575" /></a></p>
<p>I haven&#8217;t been blogging as often these last two weeks because I&#8217;m spending a lot of time preparing for my <a href="http://www.360flex.com/" target="_blank" title="360 Flex Conference">360|Flex</a> and <a href="http://www.360flex.com/about/360max/" target="_blank" title="360|MAX Unconference">360|MAX</a> presentations. I&#8217;ve been developing some kickass features and demos that I have yet to discuss publicly, so if you&#8217;re in the mood to be wowed, show up to my presentations.</p>
<h2><a href="http://www.360flex.com/" target="_blank" title="360 Flex Conference">360|Flex DC</a></h2>
<p>My presentation is the first morning, right after the keynote address (go ahead, ask me if I&#8217;m nervous about following <a href="http://dougmccune.com/blog/" target="_blank" title="badass">Doug McCune</a>?). The title is &#8220;<strong>Advanced Text Rendering with the Flash Text Engine and tinytlf</strong>.&#8221; I&#8217;ll present a general overview of the Flash Text Engine and introduce tinytlf. I&#8217;ll try and cover the low level FTE APIs as best I can in the time, but I need to move quickly into tinytlf. I only have about 70 minutes, and I hope to leave 5-10 minutes at the end for questions. I&#8217;ll be announcing tinytlf 1.0, as well as demoing some yet-to-be-announced features. It&#8217;ll be killer, I promise!</p>
<h2><a href="http://www.360flex.com/about/360max/" target="_blank" title="360|MAX Unconference">360|MAX</a></h2>
<p>The title for my 360|MAX presentation is &#8220;<strong>Tinytlf and Multi-Everything</strong>.&#8221; This presentation will begin with an overview of tinytlf, but will primarily focus on the features that enable and promote multi-screen, multi-platform, and multi-touch development. Topics covered will be the performance, interactivity, and configurability for different platforms. If you&#8217;re interested in a multi-platform text controls, this will be presentation to see.</p>
<p>These two conferences are <em>the</em> places to be for developers or companies who have invested in the Flash Platform. You&#8217;ve done your due diligence by choosing Flash, now keep up with the platform &#8217;cause the times, they are a-changin&#8217;. Register for 360|Flex <a href="http://www.eventbrite.com/event/680816340/360flexhelpsell/2222560777">here</a>, and for Adobe MAX <a href="https://max.adobe.com/register/">here</a>. </p>
<p>I&#8217;m very excited to present tinytlf to the world. If you see me at either event, hit me up! I&#8217;m more than happy to answer questions, etc. See you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2010/09/tinytlf-at-360flex-dc-and-360max/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dual Image Flow Example</title>
		<link>http://guyinthechair.com/2010/08/dual-image-flow-example/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dual-image-flow-example</link>
		<comments>http://guyinthechair.com/2010/08/dual-image-flow-example/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 12:30:29 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[Flash Text Engine]]></category>
		<category><![CDATA[text layout]]></category>
		<category><![CDATA[tinytlf]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=566</guid>
		<description><![CDATA[Expounding on last week&#8217;s image flow algorithm, I present to you a generalized algorithm for text flow around inline graphics. You can see it here: ImageFlowContainer, and fork the repo here: tinytlf. This algorithm only works for left-aligned paragraphs, if you try it with any other alignment I can&#8217;t guarantee it&#8217;ll look good. These images [...]]]></description>
			<content:encoded><![CDATA[<p>Expounding on last week&#8217;s image flow algorithm, I present to you a generalized algorithm for text flow around inline graphics. You can see it here: <a href="http://github.com/guyinthechair/tinytlf/blob/d1a02a87fd492a81a04edf10695a83df153ce63d/tinytlf-extensions/src/org/tinytlf/layout/ImageFlowContainer.as">ImageFlowContainer</a>, and fork the repo here: <a href="http://github.com/guyinthechair/tinytlf">tinytlf</a>.</p>
<p>This algorithm only works for left-aligned paragraphs, if you try it with any other alignment I can&#8217;t guarantee it&#8217;ll look good. These images don&#8217;t respect float, they&#8217;re just placed at fortuitous positions in the content. They respect box-model padding properties (padding-left, etc.). Also, I changed the default selection colors to be as close to Aqua Blue as possible.</p>
<p>Here&#8217;s the <a href="http://en.wikipedia.org/wiki/Crimson_Rose" target="_blank" title="Atrophaneura hector - Wikipedia, the free encyclopedia">original Wikipedia article</a> for comparison. As always, here&#8217;s the <a href="http://guyinthechair.com/flash/tinytlf/demos/srcview/source/DualImageFlow.as.html">source</a> for this demo. Just <a href="http://guyinthechair.com/flash/tinytlf/demos/srcview/source/assets/crimson_rose_dual_flow.xml.txt">XHTML</a> and <a href="http://guyinthechair.com/flash/tinytlf/demos/srcview/source/assets/wikipedia.css.html">CSS</a>.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_9" width="600" height="1000" align="center">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/08/DualImageFlow.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/08/DualImageFlow.swf" width="600" height="1000" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h2>Selection</h2>
<p>Tinytlf&#8217;s selection algorithms are character and line level algorithms, not block level algorithms like most web browsers. That means that even if you select an entire paragraph, tinytlf only knows you&#8217;re selecting from the paragraph begin index to the paragraph end index.</p>
<p>This leads to some interesting consequences, like an image on the first atomIndex in a line causing the entire line height to be as tall as him. You see some overlap, because tinytlf&#8217;s default <code>selectionAlpha</code> is 0.28.</p>
<p>In addition, all the decorations in tinytlf only draw <strong>underneath</strong> the TextLines. Therefore you don&#8217;t see selection over images, like you would in a web browser. Later I might allow the option for decorating on top of the Lines layer, but I&#8217;ve left it out for 1.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2010/08/dual-image-flow-example/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Advanced Text Layout in Tinytlf</title>
		<link>http://guyinthechair.com/2010/08/advanced-text-layout-in-tinytlf/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=advanced-text-layout-in-tinytlf</link>
		<comments>http://guyinthechair.com/2010/08/advanced-text-layout-in-tinytlf/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 16:54:58 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[Flash Text Engine]]></category>
		<category><![CDATA[text layout]]></category>
		<category><![CDATA[tinytlf]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=551</guid>
		<description><![CDATA[Since last week, pretty much the most requested feature has been text flow around inline graphics. Yes, even more than editability. I&#8217;ve had cleaning up and adding advanced features to the TextLayout and TextContainer on the tinytlf 1.0 roadmap for a while, but last night I finally got to work on it. These classes are [...]]]></description>
			<content:encoded><![CDATA[<p>Since last week, pretty much the most requested feature has been text flow around inline graphics. Yes, even more than editability. I&#8217;ve had <a href="https://gist.github.com/669e6c56f3a1a7e743c9" target="_blank" title="Happy Refactoring">cleaning up</a> and adding advanced features to the TextLayout and TextContainer on the tinytlf 1.0 roadmap for a while, but last night I finally got to work on it. These classes are only preliminary, but I hope they demo just how powerful tinytlf&#8217;s layout architecture can be.</p>
<p>As always, the source is available here: <a href="http://guyinthechair.com/flash/tinytlf/demos/srcview/source/" target="_blank">source for these demos</a>.</p>
<h2>Text Layout</h2>
<p>Ok, so say we have this <a href="http://en.wikipedia.org/wiki/Atrophaneura_hector" target="_blank">wikipedia entry</a> about the fascinating <strong><i>Atrophaneura hector</i> (Crimson Rose)</strong> butterfly. It&#8217;s a nice article, and tinytlf formats it well (except for the TLMR bug):</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_10" width="600" height="280" align="center">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/08/ImageFlowNoImage.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/08/ImageFlowNoImage.swf" width="600" height="280" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h2>Don&#8217;t encyclopedia entries come with an image?</h2>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_11" width="600" height="280" align="center">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/08/ImageFlowLeft.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/08/ImageFlowLeft.swf" width="600" height="280" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h3>Much better!</h3>
<h2>Put that image where you want it</h2>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_12" width="600" height="280" align="center">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/08/ImageFlowRight.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/08/ImageFlowRight.swf" width="600" height="280" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h3>Alright, now we&#8217;re rockin&#8217;</h3>
<p>Ok, I know this is ugly, but I thought I&#8217;d show off a little bit. You aren&#8217;t constricted to docking on the left or the right, the new layout algorithm will wrap text around images no matter where they are in the markup.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_13" width="600" height="280" align="center">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/08/ImageFlowCenter.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/08/ImageFlowCenter.swf" width="600" height="280" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p><br/></p>
<h2>Features</h2>
<p>This shows off some features I&#8217;ve never talked about before. Of course there&#8217;s flow around the image, but that&#8217;s really just some fancy layout math, it&#8217;s not too complicated. I&#8217;m probably most proud of the fact that <strong>tinytlf intelligently renders only the invalid TextLines</strong>.</p>
<h3>Invalidation</h3>
<p>This is a Flash Text Engine feature, but it&#8217;s one that I love: when members of the FTE ContentElement model change (text, ElementFormat, etc.), the TextBlock will tag the TextLines which render the content &#8220;invalid.&#8221; The FTE can&#8217;t automatically update the TextLines; whomever renders the TextLines (tinytlf, in this case), is responsible for surgically removing and re-rendering the invalid lines.</p>
<p>It&#8217;s a delicate procedure, but tinytlf handles it like a champ. You see the result of this in the examples whenever you roll over an anchor tag and it changes <em>fontPosture</em> or color.</p>
<h3>Layout</h3>
<p>The second part of this is the little bit of fancy math I did to break and layout the lines in the proper order. If you want to see the algorithm, check out the newest <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-extensions/src/org/tinytlf/layout/ImageFlowContainer.as#L9" target="_blank">ImageFlowContainer here</a>.</p>
<p>It&#8217;s not too difficult. Basically, as I lay out the lines, I calculate the (x, y) position for the next TextLine. Because I can change the <code>x</code> and <code>y</code> independently of each other, I can break TextLines across the plane of the graphic.</p>
<p>Where can it go from here? My next feature will be to respect padding set on the <code>&lt;img/&gt;</code> tag. After that will be allowing a way for the <code>&lt;img/&gt;</code> to specify whether it renders inline, causes line/paragraph breaking, etc. There&#8217;s a lot that can be done.</p>
<h3>Caveats</h3>
<p>I haven&#8217;t tested this with more than one image. In theory it should work, but I&#8217;ve been awake for longer than 24 hours, so I can&#8217;t trust I&#8217;m actually thinking as clearly as I think I am o.O.</p>
<p>And yes, there&#8217;s a bug with the links. It&#8217;s especially prominent here, but basically when you move the mouse very quickly, the FTE TextLineMirrorRegions dispatch a &#8220;mouseOver&#8221; but never its corresponding &#8220;mouseOut.&#8221; If anybody on Adobe&#8217;s TLF or FTE team can shed some light on this situation, I&#8217;d be very grateful.</p>
<p>That&#8217;s it, happy coding. <a href="http://github.com/guyinthechair/tinytlf/" target="_blank" title="tinytlf on github">Fork it on github!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2010/08/advanced-text-layout-in-tinytlf/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Tinytlf Overview</title>
		<link>http://guyinthechair.com/2010/08/tinytlf-overview/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tinytlf-overview</link>
		<comments>http://guyinthechair.com/2010/08/tinytlf-overview/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 07:53:41 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[Flash Text Engine]]></category>
		<category><![CDATA[tinytlf]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=537</guid>
		<description><![CDATA[Last week I formally introduced tinytlf to the world, just in time for FITC. I was blown away at its reception, the outpouring of feedback and support was amazing, way more than I thought there would be. Thanks a ton if you were a part of that! Part of that feedback was a request for [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I <a href="http://guyinthechair.com/?p=515" target="_blank">formally introduced</a> <a href="http://github.com/guyinthechair/tinytlf/" target="_blank">tinytlf</a> to the world, just in time for <a href="http://www.fitc.ca/">FITC</a>. I was blown away at its reception, the outpouring of feedback and support was amazing, way more than I thought there would be. Thanks a ton if you were a part of that!</p>
<p>Part of that feedback was a request for more information. What makes tinytlf different? What are the features/goals of the project? And (truly) my favorite inquiries, &#8220;does tinytlf have feature X?&#8221; So I thought I&#8217;d write a followup, explaining a bit about my motivations for writing it, my goals for the framework, and a high level overview of some of its key processes.</p>
<p><strong>Note: When I say TextField, I&#8217;m talking about Flash&#8217;s legacy TextField, flash.text.TextField.</strong></p>
<h2>Goals</h2>
<p>Tinytlf has ambitious goals. With tinytlf, I want to create a small, extensible library for developers to write advanced text controls. I want to give developers full control over every facet of the TextField; nothing is sacred, and every piece replaceable with a more suitable implementation. I want a TextField that finally parses real HTML, and applies real CSS stylesheets. I want a TextField that, while still visually consistent, finally provides interactive capabilities on par with the OS native text controls.</p>
<h3>Native</h3>
<p>Flash&#8217;s TextField has never been as good as the native OS offering. Like it or not, text is a place where [the dreaded] HTML5 has a clear advantage over Flash. I&#8217;d be willing to go as far as to say that it&#8217;s one of the main reasons many web developers, &#8220;technologists&#8221; (yes I&#8217;ve seen that job description), and web-savvy users hate on Flash content. They expect their text to be selectable across TextField instances. They expect the mouse and keyboard interactions to be the same as their OS of choice. They expect the text decorations to be just as eye-popping as the rest of Flash&#8217;s visuals. And it&#8217;s sad to say they aren&#8217;t.</p>
<h3>HTML and CSS</h3>
<p>It&#8217;s never been very easy for Flash developers either. The most common representation of rich text on the web is HTML. The TextField does support a subset of HTML tags; <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#htmlText" target="_blank">11 of them</a> to be exact. But you are stuck with those 11, and you have virtually no control over the styling or rendering of the content. Want stars for list items instead of bullets? Too bad. Don&#8217;t want your links underlined? Tough luck.</p>
<p>The CSS support is pitiful too. You can import CSS into a StyleSheet object, then apply the StyleSheet to the TextField, but it too only supports a subset of styles. On top of that, the TextField is no longer editable. So bon voyage to a Rich Text Editor that respects CSS! For that, you have to use the alternate and incompatible TextFormat class, but that requires management by developers and doesn&#8217;t offer any more styling options than StyleSheet!</p>
<h3>Modularity</h3>
<p>These days, modularity is a buzz word thrown around for good measure. Writing modular systems is the goal of every developer and framework, but it&#8217;s a promise that is seldom kept. Tinytlf ensures modularity by keeping strict separation of concern and delegating the bulk of the functionality to small, externally defined controller classes. Tinytlf has four actor maps, which allows for controllers to be defined or replaced from the outside.</p>
<p>For example, every text decoration in tinytlf is written externally and mapped into the framework at startup. There&#8217;s nothing inherently special about the word &#8220;underline&#8221;, or the class that draws underline decorations. It&#8217;s only what was defined and mapped in at runtime. So if you want to write your own class that draws underlines, you can, and externally map it in and replace tinytlf&#8217;s default implementation.</p>
<p>This same pattern is used over and over throughout the system, and gives you a new level of control over the TextField like you&#8217;ve never had before. If you want to support a new HTML tag, you can write a controller which parses that HTML tag. If you want a new decoration, write the implementation and map it in! If you need to fix a bug in one of tinytlf&#8217;s controllers, write the fix and replace the default controller. (Then contribute it back!)</p>
<h2>A Text Layout Framework</h2>
<p>Allow me to define the general problems a TLF has to solve:</p>
<ul>
<li>Model definition and resolution/parsing</li>
<li>Text decorations (<span style='text-decoration:underline;'>underline</span>, <span style='text-decoration:line-through;'>strikethrough</span>, etc).</li>
<li>Text interaction (both generic and <a href="#" title="Example of context-sensitive text interaction">context-sensitive</a>)
<li>Styles/formatting (notably inline and cascading styles)</li>
<li>Rendering algorithms for the font glyphs that respects styles and formatting</li>
<li>Layout algorithms that respect the model, decorations, and styles of the text</li>
</ul>
<p>Luckily, tinytlf doesn&#8217;t have to solve all these problems alone. Tinytlf gets a tremendous amount of help from the Flash Player, through the Flash Text Engine API.</p>
<table width="100%">
<tr>
<td width="50%"><strong>Flash Text Engine&#8217;s responsibilities</strong></td>
<td width="50%"><strong>Tinytlf&#8217;s  responsibilities</strong></td>
</tr>
<tr>
<td width="50%">
<ul>
<li>Model definition</li>
<li>Contextual text interactions</li>
<li>Inline styles</li>
<li>Glyph rendering algorithms</li>
</ul>
</td>
<td width="50%">
<ul>
<li>Model resolution and parsing</li>
<li>Generic text interactions</li>
<li>Cascading and inline style application</li>
<li>Layout algorithms, including text flow around images and flow between containers</li>
<li>Text decorations</li>
<li>The default definition of a TextField component</li>
</ul>
</td>
</tr>
</table>
<h2>Architecture Overview</h2>
<p>Tinytlf&#8217;s architecture allows all these pieces to come together, ensuring tinytlf is more than the sum of its parts.</p>
<p>Tinytlf is broken into five separate projects: <strong>utils</strong>, <strong>core</strong>, <strong>gestures</strong>, <strong>extensions</strong>, and <strong>components</strong>, respectively. Each project builds on the features of the previous project. You &#8220;pay as you go,&#8221; deciding for yourself what features you need and at what cost. For ease of use, you can use the components library, which is the default TextField, and depends on every project.</p>
<p>If you want, you can start over from <strong>core</strong>. Tinytlf is 100% interfaces, so, much like robotlegs, the default classes are just the reference implementation.</p>
<h3>A Text Engine</h3>
<p>The core of tinytlf is the <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-core/src/org/tinytlf/ITextEngine.as#L18" target="_blank"><code>TextEngine</code></a> actor, responsible for invalidation, selection, and tracking the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/engine/TextBlock.html" target="_blank">TextBlocks</a> in the TextField. <code>TextEngine</code> is also a <code>facade</code> pattern, which unifies tinytlf&#8217;s four unique subsystems: <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-core/src/org/tinytlf/layout/ITextLayout.as#L16" target="_blank"><code>TextLayout</code></a>, <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-core/src/org/tinytlf/decor/ITextDecor.as#L12" target="_blank"><code>TextDecor</code></a>, <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-core/src/org/tinytlf/styles/ITextStyler.as#L13" target="_blank"><code>TextStyler</code></a>, and <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-core/src/org/tinytlf/interaction/ITextInteractor.as#L14" target="_blank"><code>TextInteractor</code></a>.</p>
<p>Every tinytlf actor or controller class receives a reference to the central <code>TextEngine</code> actor. Because <code>TextEngine</code> is a <code>facade</code>, any subsystem can call into any other subsystem. For example, the interaction controllers can add or remove text decorations by accessing the <code>TextDecor</code> actor from the <code>TextEngine</code> (e.g. when you mouse over, the controller can add an underline, then when you mouse out, remove it).</p>
<h3>Engine Configuration</h3>
<p>In tinytlf, every actor and controller class is externally defined. So tinytlf&#8217;s <code>TextEngine</code> accepts an <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-core/src/org/tinytlf/ITextEngineConfiguration.as#L3" target="_blank"><code>ITextEngineConfiguration</code></a> implementation to set up the default actors and mappings. For example, see the tinytlf TextField&#8217;s <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-components/src/org/tinytlf/components/flash/TextFieldEngineConfiguration.as#L32" target="_blank"><code>TextFieldEngineConfiguration</code></a>.</p>
<h3>Model Agnosticism</h3>
<p>Tinytlf is model agnostic. It doesn&#8217;t care what format your data originally comes in, only if you can convert it into a tree of FTE <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/engine/ContentElement.html" target="_blank"><code>ContentElements</code></a>. The FTE already defined the model, it&#8217;s tinytlf&#8217;s job to resolve the differences between your model and FTE&#8217;s.</p>
<p>The default tinytlf TextField parses XHTML. There&#8217;s nothing inherently special about XHTML; XHTML is ubiquitous and easily converted into a tree of <code>ContentElements</code>. But if your model is not XHTML, you can write an implementation of <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-core/src/org/tinytlf/layout/model/factories/ILayoutFactoryMap.as#L13" target="_blank"><code>ILayoutFactoryMap</code></a>, then replace <code>ITextLayout's</code> <code>textBlockFactory</code> instance with your own.</p>
<h3>Maps Maps Maps</h3>
<p>Tinytlf exposes four maps, which allows for controllers to be externally defined. Tinytlf&#8217;s actors rely on definitions in their maps, then delegate functionality to the controllers. For example, tinytlf&#8217;s <code>TextDecor</code> exposes a map to define the classes which draw different text decorations. Then, when <code>TextDecor</code> receives instructions to decorate, it checks its map for the decoration definitions:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">decor<span style="color: #000066; font-weight: bold;">.</span>mapDecoration<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;bgColor&quot;</span><span style="color: #000066; font-weight: bold;">,</span> BackgroundColorDecoration<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
decor<span style="color: #000066; font-weight: bold;">.</span>mapDecoration<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;strike&quot;</span><span style="color: #000066; font-weight: bold;">,</span> StrikeThroughDecoration<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
decor<span style="color: #000066; font-weight: bold;">.</span>decorate<span style="color: #000000;">&#40;</span>someObj<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span>bgColor<span style="color: #000066; font-weight: bold;">:</span> 0xFF0000<span style="color: #000066; font-weight: bold;">,</span> bgAlpha<span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">0.7</span><span style="color: #000066; font-weight: bold;">,</span> strike<span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>In this example, <code>TextDecor</code> will instantiate two decorations, one for &#8220;bgColor&#8221; and one for &#8220;strike.&#8221; There&#8217;s nothing inherently special about those two strings, only that they exist in the map. Because of this, the <code>TextDecor</code> uses the mapped classes.</p>
<p>This is the pattern in three other areas as well: <code>ILayoutFactoryMap</code>, <code>ITextInteractor</code>, and <code>ITextStyler</code>.</p>
<h3>Gestures</h3>
<p>For <strong>context-insensitive</strong> text interaction, tinytlf includes a gestures library. A gesture is similar in spirit to iPhone and Android gestures; a sequence of events that occur in a certain order, so that when the last event occurs, the gesture is &#8220;unlocked,&#8221; and activates its behaviors. Behaviors are tiny command classes that are meant to control one facet of interaction. A great example is the <a href="http://github.com/guyinthechair/tinytlf/blob/master/tinytlf-gestures/src/org/tinytlf/interaction/behaviors/mouse/IBeamBehavior.as#L14" target="_blank">IBeamBehavior</a>, which controls whether the cursor is an IBeam or an arrow. Gestures can have multiple behaviors, and the same behavior can be mapped to multiple gestures.</p>
<p>The potential here is for interactivity on par with native text controls, but also allows for flexibility between platforms, like different gestures whether the user is on a PC or Mac. Moving from desktop to mobile? Just swap out mouse-based gestures for touch-based gestures, keeping all the same behaviors, allowing you to keep a consistent experience between devices.</p>
<h3>Layout</h3>
<p>Layout is a complicated problem, but tinytlf manages to cope. Tinytlf has a central <code>ITextLayout</code> actor for the <code>ITextEngine</code>, which renders lines from multiple <code>TextBlocks</code> between multiple <code>DisplayObjectContainers (DOC)</code>. Each DOC gets its own layout controller, called an <code>ITextContainer</code>. I have <a href="http://guyinthechair.com?p=412" title="TextBlocks, TextLines, and Text Layout" target="_blank">previously blogged about</a> various techniques for text layout, which are part of tinytlf&#8217;s default layout controllers. I&#8217;m still working on features for tinytlf v.1.0, but the current algorithm is pretty good.</p>
<p>During layout and re-render, tinytlf will only render the invalid <code>TextLines</code> from each <code>TextBlock</code>. This is one of many optimizations provided by the FTE of which tinytlf takes advantage.</p>
<h2>Still rough around the edges&#8230;</h2>
<p>Tinytlf isn&#8217;t finished. I&#8217;m working furiously to have 1.0 for my <a href="http://www.360flex.com/schedule/" target="_blank">360|Flex session</a>. It needs more gestures and behaviors. I&#8217;m working on the layout algorithm to get text flow around images. Of course, editability is a huge feature everybody requests. I have a general idea of where the bottle necks in the framework are, but I haven&#8217;t done much formal testing. And of course I&#8217;m committed to releasing it with full test coverage.</p>
<p>If you would like to help, you can <a href="mailto:guyinthechair@gmail.com">email me</a> and/or <a href="http://github.com/guyinthechair/tinytlf/" title="tinytlf github repository" target="_blank">jump in</a> any time. The simplest thing you can do is request features. I&#8217;ve built this for myself, so I&#8217;m curious about other people&#8217;s requirements. I&#8217;ve already received some awesome feature requests that have kept my brain churning. At the very least I can keep them in the back of my mind, and try to keep from short-circuiting the framework, making those features impossible.</p>
<p><span style="font-size:22px;">What are you waiting for? <a href="http://github.com/guyinthechair/tinytlf/" title="tinytlf github repository" target="_blank">Fork it on github!</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2010/08/tinytlf-overview/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

