<?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; misc</title>
	<atom:link href="http://guyinthechair.com/category/misc/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>The FTE Part 4: Advanced Layout Techniques</title>
		<link>http://guyinthechair.com/2010/10/the-fte-part-4-advanced-layout-techniques/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-fte-part-4-advanced-layout-techniques</link>
		<comments>http://guyinthechair.com/2010/10/the-fte-part-4-advanced-layout-techniques/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 11:07:51 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[misc]]></category>
		<category><![CDATA[Flash Text Engine]]></category>
		<category><![CDATA[FTE]]></category>
		<category><![CDATA[text layout]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=583</guid>
		<description><![CDATA[This is part four in an ongoing series about the Flash Text Engine. You can see the previous entries here. You should know, this series isn&#8217;t about Adobe&#8217;s Text Layout Framework, which is an advanced typography and text layout framework. The Flash Text Engine is the low-level API that TLF is built on. In Flash [...]]]></description>
			<content:encoded><![CDATA[<p>This is part four in an ongoing series about the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/engine/package-detail.html" title="FTE" target="_blank">Flash Text Engine</a>. You can see the previous entries <a href="http://guyinthechair.com/tag/fte/" target="_blank">here</a>.</p>
<p style="padding-left: 15px; padding-right: 15px; color: #999999;">You should know, this series isn&#8217;t about <a href="http://labs.adobe.com/technologies/textlayout/">Adobe&#8217;s Text Layout Framework</a>, which is an advanced typography and text layout framework. The Flash Text Engine is the low-level API that TLF is built on. In Flash Player 10, the FTE resides in the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/engine/package-detail.html" target="_blank">flash.text.engine</a> package.</p>
<h2>Advanced Text Rendering</h2>
<p>The FTE may be low level, but that affords developers like you and me serious control over the presentation of our text fields. The FTE renders glyphs into a series of TextLines, but forces us to handle the sizing and layout of the lines. Today, I&#8217;ll cover how to efficiently create and position lines. For simplicity&#8217;s sake, I&#8217;ll assume the TextLines&#8217; widths extend to the edges of the Container they are rendered into.</p>
<p>In this post I&#8217;ll cover:</p>
<ul>
<li>text flow across containers</li>
<li>container resizing</li>
<li>TextLine positioning, invalidation, and reuse</li>
</ul>
<h3>Caveats</h3>
<p>In order to keep this post relatively short, I&#8217;ve simplified the algorithms here down to the basic principles. This is a general description of the layout algorithms in tinytlf, though they are getting more complex by the day.</p>
<h2>Example</h2>
<p>Here&#8217;s the final product of what I&#8217;m going to walk through. <strong>Click on the text to resize the columns</strong>:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="600" height="600" align="center">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/10/FTE_Resizing.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/10/FTE_Resizing.swf" width="600" height="600" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h3>Defining the Problem</h3>
<p>From a layout perspective, we have a number of paragraphs that need to be rendered into a list of DisplayObjectContainers. When we run out of DisplayObjectContainers, we&#8217;re going to call it quits. What if we run out of lines before we&#8217;re done rendering containers? Good! It&#8217;s easy to quit when you don&#8217;t have any content left to render.</p>
<p>So what we need is a layout algorithm that will break TextLines from a Vector of TextBlocks across a list of DisplayObjectContainers (DOCs).</p>
<h3>Text Layout</h3>
<p>In order to coordinate the layout between paragraphs and containers, I&#8217;ve defined a controller I call <a href="http://guyinthechair.com/wp-content/uploads/2010/10/srcview/source/org/tinytlf/layout/TextLayout.as.html" title="Simplified TextLayout">TextLayout</a>. TextLayout&#8217;s job is to run through the list of TextBlocks, rendering as many lines as possible into the available DOCs. When the DOC is full, TextLayout moves to the next container. If there is no next container, TextLayout breaks out of the rendering algorithm. Similarly with TextBlocks, if we run out paragraphs to render, TextLayout breaks out of the layout algorithm.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/**
 * Renders as many lines from the list of TextBlocks into the specified
 * conatiners as possible.
 */</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">render</span><span style="color: #000000;">&#40;</span>blocks<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>TextBlock<span style="color: #000066; font-weight: bold;">&gt;</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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>containers <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000066; font-weight: bold;">!</span>containers<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000066; font-weight: bold;">!</span>blocks <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000066; font-weight: bold;">!</span>blocks<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	containers<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">forEach</span><span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">:</span>TextContainer<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">...</span>args<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: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span>preLayout<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</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> block<span style="color: #000066; font-weight: bold;">:</span>TextBlock = blocks<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> i<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>
	<span style="color: #6699cc; font-weight: bold;">var</span> container<span style="color: #000066; font-weight: bold;">:</span>TextContainer = containers<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>block <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> container<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		container = renderBlockAcrossContainers<span style="color: #000000;">&#40;</span>block<span style="color: #000066; font-weight: bold;">,</span> container<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		block = <span style="color: #000066; font-weight: bold;">++</span>i <span style="color: #000066; font-weight: bold;">&lt;</span> blocks<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">?</span> blocks<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h3>TextContainer</h3>
<p><a href="http://guyinthechair.com/wp-content/uploads/2010/10/srcview/source/org/tinytlf/layout/TextContainer.as.html">TextContainer</a> is a single DOC that renders TextLines. It is a layout controller that determines the positions and sizes of the TextLines inside himself.</p>
<p>TextContainer maintains a very important relationship with TextLayout&#8217;s rendering algorithm. TextLayout repeatedly calls the <strong>TextContainer.layout()</strong> method, passing in a TextBlock to render lines from, and optionally, the previous line that was rendered from the block. It is TextContainer&#8217;s responsibility to render as many lines from the TextBlock into itself until either, 1. the TextBlock has no lines left to render, or 2. the TextContainer is full and has no more room for additional TextLines.</p>
<p><strong>TextContainer.layout()</strong> should return the last line rendered from the TextBlock. Null is a valid value to return. If a (non-null) TextLine was returned, TextLayout assumes the TextContainer is full, finished rendering lines, and moves to the next TextContainer, keeping the same TextBlock. If TextContainer returns <strong>null</strong>, TextLayout assumes there&#8217;s still room in the TextContainer for lines, and TextLayout passes the next TextBlock to the TextContainer.</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> layout<span style="color: #000000;">&#40;</span>block<span style="color: #000066; font-weight: bold;">:</span>TextBlock<span style="color: #000066; font-weight: bold;">,</span> previousLine<span style="color: #000066; font-weight: bold;">:</span>TextLine<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>TextLine
<span style="color: #000000;">&#123;</span>
	_y = measuredHeight<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> line<span style="color: #000066; font-weight: bold;">:</span>TextLine = createTextLine<span style="color: #000000;">&#40;</span>block<span style="color: #000066; font-weight: bold;">,</span> previousLine<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		lines<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #004993;">position</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">//If there's no room, return the last line broken.</span>
		<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>checkConstraints<span style="color: #000000;">&#40;</span>line<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;">return</span> line<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		line = createTextLine<span style="color: #000000;">&#40;</span>block<span style="color: #000066; font-weight: bold;">,</span> line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//This will be null here.</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> line<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Line layout is straightforward. I&#8217;m sure you know what the <strong>position()</strong> and <strong>checkConstraints()</strong> methods do, and if not, the source is available <a href="http://guyinthechair.com/wp-content/uploads/2010/10/srcview/source/org/tinytlf/layout/TextContainer.as.html">here</a>.</p>
<p>This is good enough to work for the first layout pass, but resizing introduces a bit more complexity.</p>
<h2>TextLineValidity</h2>
<p>We can take advantage of an FTE TextBlock and TextLine feature to get resizing.</p>
<p>When the ContentElement &#8220;model&#8221; is updated, the TextLine &#8220;views&#8221; should updated to reflect the changes. But we as FTE users have no concept of the data behind each individual TextLines, so if we updated the screen, we&#8217;d have to start from the first line and re-create each one. This is extremely inefficient, especially if the change only reflected in one actual line update.</p>
<p>Luckily, the TextBlock can track and resolve such changes for you. Whenever anything in the TextBlock&#8217;s <strong>content</strong> member changes, the TextBlock marks relevant lines &#8220;invalid&#8221; (<a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/engine/TextLineValidity.html#INVALID">TextLineValidity.INVALID</a>). The TextBlock exposes a pretty handy property called <strong>firstInvalidLine</strong>, which points to the first line in the TextBlock that needs updating. Look mom, no searching!</p>
<p>You can check the status of individual lines simply by reading the <strong>TextLine.validity</strong> property. Luckily, validity is also writeable, and the TextBlock respects our decision if we choose to mark certain lines &#8220;invalid&#8221; ourselves. I guess we know best!</p>
<h2>Resizing</h2>
<p>When a TextContainer is resized, we need to know about it and invalidate our TextLine children.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explicitWidth<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">NaN</span><span style="color: #000066; font-weight: bold;">;</span>
override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">width</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> explicitWidth<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">width</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</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: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span> == explicitWidth<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
	explicitWidth = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
	invalidateLines<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> invalidateLines<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>
	lines<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">forEach</span><span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>l<span style="color: #000066; font-weight: bold;">:</span>TextLine<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">...</span>args<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>
		l<span style="color: #000066; font-weight: bold;">.</span>validity = TextLineValidity<span style="color: #000066; font-weight: bold;">.</span>INVALID<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h3>Line Reuse</h3>
<p>During the first layout pass, we use the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/engine/TextBlock.html#createTextLine()">TextBlock.createTextLine</a> method exclusively. But TextLines are expensive to create, so Flash Player 10.1 introduced the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/engine/TextBlock.html#recreateTextLine()">TextBlock.recreateTextLine</a> method. Allowing us to recreate TextLines means that the Flash Player can re-jigger the TextLine&#8217;s contents internally, without the overhead of creating a new TextLine instance.</p>
<p>During a resize operation, lines will be either created or destroyed. If you set the width smaller, the TextField will be forced to render new TextLines. If you set the width wider, the TextField can remove TextLines at the end. In the first case, we&#8217;ll have to make extra calls to <strong>TextBlock.createTextLine</strong>. In the second case, we can remove the TextLines from the display list and remove all references. In this case, the lines have been <strong>orphaned</strong>.</p>
<p>But with the introduction of <strong>recreateTextLine</strong>, it&#8217;s optimal to cache orphaned lines, at least for a little while. It&#8217;s possible that we will resize the TextField smaller again, which will require the creation of new lines. But if we&#8217;ve previously created lines, why not reuse them instead of creating new ones? Good thinking you.</p>
<p>However, this changes the meaning of the <strong>line</strong> argument in the <strong>TextContainer.layout</strong> method. Now, the line can either be:</p>
<ul>
<li>A valid and successfully broken TextLine, which should be used as the <strong>previousLine</strong> argument to create or re-create a TextLine.</li>
<li>An invalid TextLine that needs to be re-created. This should only happen in the case that the line is the <strong>TextBlock.firstLine</strong> value, because there is no previously broken valid TextLine. Since we don&#8217;t want to wipe out our orphan cache looking for a line, we can detect this case and recreate the line.</li>
<ul>
<p>This introduces just a bit more complexity, but luckily we can encapsulate it in the <strong>TextContainer.createTextLine</strong> method.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/**
 * Creates or recreates a given TextLine.
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createTextLine<span style="color: #000000;">&#40;</span>block<span style="color: #000066; font-weight: bold;">:</span>TextBlock<span style="color: #000066; font-weight: bold;">,</span> line<span style="color: #000066; font-weight: bold;">:</span>TextLine<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>TextLine
<span style="color: #000000;">&#123;</span>
	removeOrphanedLines<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>line<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>line<span style="color: #000066; font-weight: bold;">.</span>validity === TextLineValidity<span style="color: #000066; font-weight: bold;">.</span>INVALID<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> block<span style="color: #000066; font-weight: bold;">.</span>recreateTextLine<span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</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>orphans<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> orphan<span style="color: #000066; font-weight: bold;">:</span>TextLine = getFirstOrphan<span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>orphan<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> block<span style="color: #000066; font-weight: bold;">.</span>recreateTextLine<span style="color: #000000;">&#40;</span>orphan<span style="color: #000066; font-weight: bold;">,</span> line<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">return</span> block<span style="color: #000066; font-weight: bold;">.</span>createTextLine<span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeOrphanedLines<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: #6699cc; font-weight: bold;">var</span> line<span style="color: #000066; font-weight: bold;">:</span>TextLine<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> n<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = lines<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<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> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		line = lines<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">.</span>validity === TextLineValidity<span style="color: #000066; font-weight: bold;">.</span>VALID<span style="color: #000000;">&#41;</span>
			<span style="color: #0033ff; font-weight: bold;">continue</span><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: #004993;">contains</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		lines<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		orphans<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		n = lines<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</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: #009900; font-style: italic;">//Static so it's shared between instances of TextContainer</span>
<span style="color: #0033ff; font-weight: bold;">private</span> static const orphans<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>TextLine<span style="color: #000066; font-weight: bold;">&gt;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">&lt;</span>TextLine<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #3f5fbf;">/**
 * Returns the first invalid orphan that also isn't the input line.
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #339966; font-weight: bold;">function</span> getFirstOrphan<span style="color: #000000;">&#40;</span>exceptForMe<span style="color: #000066; font-weight: bold;">:</span>TextLine<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>TextLine
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>orphans<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> orphan<span style="color: #000066; font-weight: bold;">:</span>TextLine = orphans<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>orphan == exceptForMe<span style="color: #000000;">&#41;</span>
		orphan = orphans<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>orphan <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> orphan<span style="color: #000066; font-weight: bold;">.</span>validity == TextLineValidity<span style="color: #000066; font-weight: bold;">.</span>VALID<span style="color: #000000;">&#41;</span>
		orphan = orphans<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pop</span><span style="color: #000000;">&#40;</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> orphan<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Because we can possibly recreate TextLines without calling <strong>getFirstOrphan</strong>, sometimes a TextLine in the orphan list is recreated but not removed from the list of possible orphans. The two checks in this method ensure that we don&#8217;t hit this case.</p>
<p>And there you have it! That&#8217;s the basic gist of TextLine rendering, resizing, and reuse across multiple DisplayObjectContainers. You can see all the source for the demo <a href="http://guyinthechair.com/wp-content/uploads/2010/10/srcview/index.html">here</a>, and be sure to check out <a href="http://github.com/guyinthechair/tinytlf">tinytlf</a>, the small text layout framework I&#8217;m writing. I described the basic line rendering algorithm in tinytlf (with enhancements of course). Though I&#8217;m currently working on a more iterative version. If I&#8217;m successful, it&#8217;ll be the topic of a future blog post. Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2010/10/the-fte-part-4-advanced-layout-techniques/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>360 Flex/RIAdventure Cruise</title>
		<link>http://guyinthechair.com/2009/12/360-flexriadventure-cruise/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=360-flexriadventure-cruise</link>
		<comments>http://guyinthechair.com/2009/12/360-flexriadventure-cruise/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 18:45:54 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[community]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=72</guid>
		<description><![CDATA[I just got back from the RIAdventure cruise and WOW, what an awesome time! This was the only conference I&#8217;ve been to where both the speakers and attendees were all top-notch. Being locked on a cruise ship in the Caribbean for 7 days with these guys was an incredible experience. And I never heard the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://riadventure.com/images/200x180_RIAdv_09_Go.gif" alt="RIAdventure Cruise" /></p>
<p>I just got back from the RIAdventure cruise and WOW, what an awesome time! This was the only conference I&#8217;ve been to where both the speakers and attendees were all top-notch. Being locked on a cruise ship in the Caribbean for 7 days with these guys was an incredible experience. And I never heard the words, &#8220;no, I don&#8217;t want to discuss <em>work topics</em>, we&#8217;re on vacation!&#8221;</p>
<p>On the last day, I filled in for <a href="http://www.blog.rivello.org/" target="_blank" title="Sam Rivello">Sam Rivello</a>, who was recovering from a drunken leap off the ship&#8217;s main staircase. I threw together a demo of the <a href="http://guyinthechair.com/?p=61" title="Particle Emitter Publisher" target="_blank">Particle Emitter Publishing Tool</a> I blogged about a few weeks ago, and showed how easy it is to implement a <a href="http://www.lostinactionscript.com/blog/index.php/2009/01/05/tweensy-goes-public/" title="Tweensy: Efficient Actionscript Tweening Engine" target="_blank">TweensyFX</a> particle emitter in your app (either through MXML or Actionscript, your choice). A few of the Tweensy classes use constructor injection (they require parameters in the constructor), which isn&#8217;t compatible with MXML, so I extended and used the subclasses for MXML instead. Hopefully when Tweensy gets to 1.0, all the constructor injection will be stripped out, as setter injection is usually more efficient anyway.</p>
<p>When I presented this, I got some really great feedback about ways to make it better. I know that I&#8217;ve got to work on the interface, as it&#8217;s not very intuitive and is difficult to navigate. A great idea that <a href="http://www.usefulconcept.com/" title="Joshua Cyr" target="_blank">Josh Cyr</a> suggested is a publishing community, where people can submit, rate, and comment on different FX. I envision something similar to <a href="http://kuler.adobe.com/" title="Adobe Kuler Community" target="_blank">Adobe Kuler</a>, or the <a href="http://ryanswanson.com/regexp/" title="Regexp Explorer" target="_blank">Flex 3 Regexp Explorer</a>.</p>
<p><a href="http://guyinthechair.com/wp-content/flex/emitterfx_demo/index.html" title="EmitterFX demo" target="_blank">Here&#8217;s the demo</a>, and <a href="http://guyinthechair.com/wp-content/flex/emitterfx_demo/srcview/index.html" title="EmitterFX Source View" target="_blank">here&#8217;s the source</a>. The SWF Profiler in the demo overrides the right-click &#8220;View Source&#8221; option, so sorry about that. <a href="http://guyinthechair.com/wp-content/flex/emitterfx_demo/srcview/source/com/ptaylor/effects/EmitterCanvas.as.html" title="EmitterCanvas.as" target="_blank">Here&#8217;s the EmitterCanvas</a> I used to render Emitters and IEffects to one BitmapLayer.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2009/12/360-flexriadventure-cruise/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Particle Emitter Publishing Tool</title>
		<link>http://guyinthechair.com/2009/11/particle-emitter-publishing-tool/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=particle-emitter-publishing-tool</link>
		<comments>http://guyinthechair.com/2009/11/particle-emitter-publishing-tool/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 07:19:34 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[misc]]></category>
		<category><![CDATA[BitmapFilter]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tweensy]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=61</guid>
		<description><![CDATA[I&#8217;m tired, so I&#8217;m going to keep this quick. The Emitter class by Tweensy is fantastic and fun to use, but it&#8217;s not easy to imagine what an effect will look like without coding up an example. That&#8217;s why I&#8217;ve put together a publishing tool for Tweensy&#8217;s particle Emitter. I&#8217;m using 15 sample particles embedded [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m tired, so I&#8217;m going to keep this quick. The <a href="http://docs.flashdynamix.com/tweensy/fx/index.html?com/flashdynamix/motion/extras/Emitter.html&amp;com/flashdynamix/motion/extras/class-list.html" target="_blank">Emitter</a> class by <a href="http://www.lostinactionscript.com/blog/index.php/2009/01/05/tweensy-goes-public/" target="_blank">Tweensy</a> is fantastic and fun to use, but it&#8217;s not easy to imagine what an effect will look like without coding up an example.</p>
<p>That&#8217;s why I&#8217;ve put together a publishing tool for Tweensy&#8217;s particle Emitter. I&#8217;m using 15 sample particles embedded in a SWF, <a href="http://guyinthechair.com/wp-content/flex/emitterfx/assets/particles/particles.swf" target="_blank">which you can download here</a>. <a href="http://guyinthechair.com/wp-content/flex/emitterfx/index.html" target="_blank">Launch the editor here</a>.</p>
<p>Some features of this editor include:</p>
<ul>
<li>The ability to save configurations to a file to be loaded again later (serializing the data to AMF and reading it in to restore state). This means your designers can fiddle with the animations and then email you the configuration.</li>
<li>A code generater for each Emitter and each BitmapFilter applied, which means you can load up the configuration the designers sent you and pretty much copy/paste the code into your project.</li>
</ul>
<p>I will update to add more effects, like the <a href="http://docs.flashdynamix.com/tweensy/fx/index.html?com/flashdynamix/motion/effects/PerlinDisplacementEffect.html&amp;com/flashdynamix/motion/effects/class-list.html" target="_blank">PerlinDisplacementEffect</a> that helps with the <a href="http://www.tweensy.org/examples/fireSmokeFX.html" target="_blank">really cool fire effects</a> Tweensy is capable of, but for now this is what I&#8217;ve got.</p>
<p>Once you add an emitter, you&#8217;ll need to set at least the emission frequency, emission randomness, and particle life to see anything happen. After that I suggest moving the X/Y coords and turning on either the Blur filter or the ColorTransform filter. Changing the start and end colors does some dramatic things, as well as fiddling with the blendMode (I suggest either Normal or Add). If you&#8217;ve got any questions or feature requests, leave them in the comments. Good luck!</p>
<p><span style="color: #339966;">Update</span>: Here&#8217;s two sample emitters to start off with: <a href="http://guyinthechair.com/wp-content/flex/emitterfx/configurations/particleEffect1.amf">Effect 1</a> and <a href="http://guyinthechair.com/wp-content/flex/emitterfx/configurations/fireworks.amf">Fireworks</a> (right click and &#8220;Save as&#8230;&#8221;, keeping the .amf extension).</p>
<p><span style="color: #339966;">Update 2</span>: Added the PerlinDisplacementEffect. Try it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2009/11/particle-emitter-publishing-tool/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>sweet rainbow pic&#8230;</title>
		<link>http://guyinthechair.com/2008/10/sweetrainbowpicwlightninghtshootingfromhands/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sweetrainbowpicwlightninghtshootingfromhands</link>
		<comments>http://guyinthechair.com/2008/10/sweetrainbowpicwlightninghtshootingfromhands/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 16:13:50 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=8</guid>
		<description><![CDATA[    sweetrainbowpicwlightninghtshootingfromhands Originally uploaded by guyinthechair Dusty did this at 3 this morning because he needed to wake up and continue working on the project we&#8217;re doing. I love it.          ]]></description>
			<content:encoded><![CDATA[<div style="float: right; margin-left: 10px; margin-bottom: 10px;"><a title="photo sharing" href="http://www.flickr.com/photos/22725654@N02/2983717047/"><img style="border: solid 2px #000000;" src="http://farm4.static.flickr.com/3208/2983717047_be0fc716b8_m.jpg" alt="" /></a>   </p>
<p><span style="font-size: 0.9em; margin-top: 0px;"><br />
<a href="http://www.flickr.com/photos/22725654@N02/2983717047/">sweetrainbowpicwlightninghtshootingfromhands</a></span></p>
<p>Originally uploaded by <a href="http://www.flickr.com/people/22725654@N02/">guyinthechair</a></p>
</div>
<p>Dusty did this at 3 this morning because he needed to wake up and continue working on the project we&#8217;re doing.</p>
<p>I <strong>love</strong> it.</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2008/10/sweetrainbowpicwlightninghtshootingfromhands/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

