<?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</title>
	<atom:link href="http://guyinthechair.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://guyinthechair.com</link>
	<description>//the blog of Paul Taylor</description>
	<lastBuildDate>Mon, 26 Jul 2010 20:24:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The Flash Text Engine, Part 2: Interaction</title>
		<link>http://guyinthechair.com/?p=312</link>
		<comments>http://guyinthechair.com/?p=312#comments</comments>
		<pubDate>Mon, 28 Jun 2010 06:16:57 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[Flash Text Engine]]></category>
		<category><![CDATA[FTE]]></category>
		<category><![CDATA[fte interaction]]></category>
		<category><![CDATA[tiny tlf]]></category>
		<category><![CDATA[tinytlf]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=312</guid>
		<description><![CDATA[This is part 2 in an ongoing series about the Flash Text Engine. You can read part 1 here. To clarify, 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 Player 10, [...]]]></description>
			<content:encoded><![CDATA[<p>This is part 2 in an ongoing series about the Flash Text Engine. <a href="http://guyinthechair.com/?p=250" target="_blank" title="The Flash Text Engine, Part 1">You can read part 1 here</a>. </p>
<p style="padding-left:15px;padding-right:15px;color:#999999">To clarify, 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/AS3LCR/Flash_10.0/flash/text/engine/package-detail.html">flash.text.engine</a> package.</p>
<h2>Interaction in the Flash Text Engine</h2>
<p>In my previous post on the Flash Text Engine, I ran through the basics of what you need to get the FTE to render TextLines. While rendering lines on the screen is nice, this post is about how to add interaction to the TextLines that are produced. </p>
<p>TextLines are <a href="http://livedocs.adobe.com/flex/3/langref/flash/display/InteractiveObject.html" title="InteractiveObject" target="_blank">InteractiveObjects</a>. You can add event listeners directly to them and listen for interaction events. The FTE also gives you the option to associate an individual EventDispatcher instance with a single ContentElement, so that when the user interacts with the data of the ContentElement, the events are cloned to the EventDispatcher instance you specified. As I discuss the details, you&#8217;ll see that each approach has its own strengths and weaknesses.</p>
<h3>Approach 1: TextLines as InteractiveObjects</h3>
<p>Since TextLine is an InteractiveObject, you can simply listen for Mouse and Keyboard events on each TextLine instance. With this approach, you know the TextLine that was interacted with. The main drawback here is that TextLine knows almost nothing about the ContentElement which it is rendering. Multiple ContentElements can be rendered into the same TextLine, and multiple TextLines can render the same (really long) ContentElement.</p>
<p>Interact with the lines in this demo:<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="235" height="100">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo2.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo2.swf" width="235" height="100">
      <!--<![endif]-->
        TextLine InteractiveObject event listeners.
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<a href="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo2.as">Source</a></p>
<p>The fact that you don&#8217;t know about the content of the TextLines is ok though, for some problems that isn&#8217;t necessary. For example, you don&#8217;t really need to know about the contents of the TextLines to draw decorations, such as underline, strikethrough, or selection.</p>
<p>Select this text:<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="400" height="125">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo7.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo7.swf" width="400" height="125">
      <!--<![endif]-->
        Selection with the Flash Text Engine
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<a href="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo7.as">Source</a></p>
<h3>Approach 2: Working with TextLineMirrorRegions (TLMRs)</h3>
<p>The preferred method of managing interaction in the Flash Text Engine is with <a title="TextLineMIrrorRegion" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLineMirrorRegion.html" target="_blank">TextLineMirrorRegions</a>.</p>
<p>If you read my <a href="http://guyinthechair.com/?p=250" target="_blank" title="The Flash Text Engine, Part 1">previous post</a>, you&#8217;ll remember that to render any text, you have to create instances of any of the Flash Text Engine&#8217;s model classes: <a title="TextElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextElement.html" target="_blank">TextElement</a>, <a title="GraphicElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/GraphicElement.html" target="_blank">GraphicElement</a>, or <a title="GroupElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/GroupElement.html" target="_blank">GroupElement</a>. When you create an instance of these classes, you can specify an EventDispatcher as the <code>eventMirror</code> for the ContentElement. When the user interacts with the visual representation of this ContentElement via TextLines, the events are re-dispatched to the <code>eventMirror</code> you specified. This allows you to know when a user interacts only with a particular ContentElement.</p>
<p>In this code sample, I create an EventDispatcher to pass in as the <code>eventMirror</code> for the TextElement. Then I add a listener for mouseMove on the <code>eventMirror</code> instance. This will trace out every time you mouse over the TextElement.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> dispatcher<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">EventDispatcher</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0033ff; font-weight: bold;">new</span> TextElement<span style="color: #000000;">&#40;</span><span style="color: #990000;">'Inspiring quote here.'</span>, <span style="color: #0033ff; font-weight: bold;">new</span> ElementFormat<span style="color: #000000;">&#40;</span>
                                         <span style="color: #0033ff; font-weight: bold;">new</span> FontDescription<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, 
                                         dispatcher<span style="color: #000000;">&#41;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> onMouseMove<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Function</span> = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
    <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'Mouse move on '</span> <span style="color: #000000; font-weight: bold;">+</span> e.<span style="color: #004993;">target</span>.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
dispatcher.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, onMouseMove<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>These two lines are part of the same TextElement:<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="190" height="40">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo3.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo3.swf" width="190" height="40">
      <!--<![endif]-->
        Quick demo of using the eventMirror with a TextElement.
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<a href="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo3.as">Source</a></p>
<p>How is this different from the previous demo? TextLine has a property called <code>mirrorRegions</code>, a Vector of TextLineMirrorRegion instances. Since multiple ContentElements can be rendered by a single TextLine, TextLine creates TLMR instances for each ContentElement with an <code>eventMirror</code>, then associates the TLMRs with the <code>eventMirror</code>s respectively.</p>
<p>TextLine listens on itself for interaction events. When the events overlap with any of the TLMRs, TextLine notifies the appropriate TLMR of the event. <strong>After all normal event processing for the TextLine is done</strong>, each TLMR  re-dispatches the events it was notified of to its <code>eventMirror</code> instance.</p>
<p>In this example, I added a listener for the &#8220;mouseDown&#8221; event on both the TextLine and the ContentElement&#8217;s <code>eventMirror</code>. Notice that the event dispatched on the <code>eventMirror</code> happens second.<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_3" width="285" height="55">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo4.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo4.swf" width="285" height="55">
      <!--<![endif]-->
        The difference between adding an event listener on the line, and one via an eventMirror in FTE.
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<a href="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo4.as">Source</a></p>
<p>Here&#8217;s what the TLMRs look like (I&#8217;ve drawn boxes for each boundary of a TextLineMirrorRegion).<br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_4" width="250" height="110">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo5.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo5.swf" width="250" height="110">
      <!--<![endif]-->
        Example of the bounds of TextLineMirrorRegions.
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<a href="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo5.as">Source</a></p>
<h3>Caveats</h3>
<p>Of course, this wouldn&#8217;t be a Flash Player feature if it didn&#8217;t come with caveats ;). </p>
<p>TextLineMirrorRegion <em>simulates</em> the events, it doesn&#8217;t re-dispatch the exact instance it received from the TextLine. This is because TLMR isn&#8217;t an InteractiveObject itself. If you utilize the <code>eventMirror</code> to listen for MouseEvents, just realize they&#8217;re all faked &#8212; even though TextLine is the target, they didn&#8217;t originate from TextLine, and they don&#8217;t have feelings like real player-native events do.</p>
<h3>rollOver/rollOut events</h3>
<p>This event simulation means that we&#8217;re at the mercy of what Adobe chooses to simulate. They didn&#8217;t feel the need to simulate the roll events (rollOver/rollOut), so if you try to listen for them on the <code>eventMirror</code>, you won&#8217;t get them. Presumably this is because the roll events aren&#8217;t needed; since ContentElements don&#8217;t have display-list children, the roll events would be exactly the same as mouseOver/mouseOut.</p>
<p><strong>Except the roll events are still very relevent.</strong></p>
<p>It&#8217;s true, we&#8217;ve shifted from a display-list hierarchical structure (DisplayObjectContainers, etc.) to a ContentElement hierarchical structure. And it&#8217;s true, ContentElements don&#8217;t have display-list children. But they can have other ContentElement children, which means the roll events are still very relevant.</p>
<p>For example, if you had this XML model to render:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  Outside the group. 
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#44AA00&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      First group child.
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#AA0044&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Second group child.
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  Outside the group.
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You might want to know only when the entire <code>group</code> node is interacted with (just like when you have a DisplayObjectContainer with children).</p>
<p>Here&#8217;s the demo of this model. Mouse between the boundary of the first child and the second child, and notice how you get a &#8220;mouseOut&#8221; and then another &#8220;mouseOver&#8221; <strong>from the group</strong>. If this were the roll events, you would only get the &#8220;mouseOut&#8221; and &#8220;mouseOver&#8221; from the children, but <strong>hear nothing from the group</strong>. FYI, &#8220;mouseDown&#8221; clears the debug lines. 
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_5" width="400" height="110">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo6.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo6.swf" width="400" height="110">
      <!--<![endif]-->
        Why the rollOver/rollOut events aren&#039;t obsolete in the FTE.
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<a href="http://guyinthechair.com/wp-content/uploads/2010/06/FTEDemo6.as">Source</a></p>
<h3>Comparison</h3>
<p>So, how do the two techniques match up? The short answer is that each one accomplishes a different task. If you need the very base of interaction capabilities without the context of what you&#8217;re messing with (e.g. text selection), adding listeners straight on your TextLines is the way to go. However, if you need the context of which ContentElement the user interacts with (e.g. to mimic an HTML anchor tag), there&#8217;s no way around it, you have to use the event mirroring approach.</p>
<p><strong>P.S.</strong> Isn&#8217;t it freaky interacting with text that you can&#8217;t select? Maybe I&#8217;m just OCD, but I feel a strong desire to see an I-Beam mouse cursor every time I hover over FTE text. My favorite demo to write was the second one, because not only did I get to come up with a quick selection-drawing method, I added the freakin&#8217; I-Beam cursor. Anyway, hope you enjoyed this and good luck :).</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/?feed=rss2&amp;p=312</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Flash Text Engine, Part 1: Overview</title>
		<link>http://guyinthechair.com/?p=250</link>
		<comments>http://guyinthechair.com/?p=250#comments</comments>
		<pubDate>Thu, 03 Jun 2010 10:18:20 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[advanced text rendering]]></category>
		<category><![CDATA[cff]]></category>
		<category><![CDATA[compact font format]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash player 10]]></category>
		<category><![CDATA[Flash Text Engine]]></category>
		<category><![CDATA[FTE]]></category>
		<category><![CDATA[text layout]]></category>
		<category><![CDATA[Text Layout Framework]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[tiny tlf]]></category>
		<category><![CDATA[tinytlf]]></category>
		<category><![CDATA[TLF]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=250</guid>
		<description><![CDATA[This is the first post in what will be a multi-part series about the Flash Text Engine, a new low level text API in Flash Player 10. To clarify, 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 [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first post in what will be a multi-part series about the Flash Text Engine, a new low level text API in Flash Player 10.</p>
<p style="padding-left:15px;padding-right:15px;color:#999999">To clarify, 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/AS3LCR/Flash_10.0/flash/text/engine/package-detail.html">flash.text.engine</a> package.</p>
<p>The FTE is designed to render text &#8220;document style&#8221;. It&#8217;s primarily meant to replace the TextField for advanced uses, not provide a whole framework for text layout on the scale of an HTML rendering engine.</p>
<p>The FTE handles what I call <strong>flow</strong>: formatting that causes text to be pushed to the next line in a paragraph. I don&#8217;t know if that&#8217;s the official term, but it seems to fit. It does not do <strong>layout</strong>, which is things like bullet points, indentation, wrapping around images, padding, etc., nor does it handle <strong>decoration</strong>, things like underline, strikethrough, background color, selection, etc. I believe the FTE leaves these out because 1.) layout is a much more complicated and nuanced problem than flow, one that you wouldn&#8217;t necessarily want in the FP core, and 2.) decorations don&#8217;t cause <strong>reflow</strong>, or affect whether and how text is wrapped to the next line.</p>
<p>The FTE conforms to a small MVC architecture, there are about 10 core classes that provide most of the functionality, with the rest of them encapsulating constants. Something to note, every class in the FTE is final :( more on that later.</p>
<h2>The FTE Model</h2>
<p>The basis of the Flash Text Engine model is something called <a title="flash.text.engine.ContentElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/ContentElement.html" target="_blank">ContentElement</a>. ContentElement is an abstract base class. You never call <code>new ContentElement()</code> (it&#8217;s similar to DisplayObject in this regard), instead you instantiate one of its 3 subclasses: <a title="flash.text.engine.TextElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextElement.html" target="_blank">TextElement</a>, <a title="flash.text.engine.GraphicElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/GraphicElement.html" target="_blank">GraphicElement</a>, or <a title="flash.text.engine.GroupElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/GroupElement.html" target="_blank">GroupElement</a>. Collectively these classes describe a Tree hierarchy for text, but I want to talk a bit more about ContentElement before we get too deep into that.</p>
<h3>ContentElement</h3>
<p>Take a look at the constructor of ContentElement:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">ContentElement<span style="color: #000000;">&#40;</span>elementFormat<span style="color: #000000; font-weight: bold;">:</span>ElementFormat = <span style="color: #0033ff; font-weight: bold;">null</span>, eventMirror<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span>, textRotation<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;rotate0&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>It has two important arguments, <strong>elementFormat</strong> and <strong>eventMirror</strong> (as well as a third less important argument, unless you&#8217;re one of the crazy types who likes to rotate text). I will come back to the eventMirror later, but for now lets just talk about <a title="flash.text.engine.ElementFormat" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/ElementFormat.html" target="_blank">ElementFormat</a>.</p>
<p>The ElementFormat class describes most of the properties that handle text flow. It has a fontDescription member, which is exactly what it sounds like. In <a title="flash.text.engine.FontDescription" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/FontDescription.html" target="_blank">FontDescription</a> you&#8217;ve got your standard <code>fontFamily</code>, <code>fontWeight</code>, <code>fontPosture</code> (which is traditionally the fontStyle in Flash), along with how the font is supposed to be retrieved from the depths of the Flash Player (as Compact Font Format or a device font).</p>
<p>ElementFormat has properties like <code>alpha</code>, <code>color</code>, <code>baselineShift</code>, <code>kerning</code>, etc. Basically anything that can affect <strong>reflow</strong>.</p>
<p>Ok, so that describes all you need to know for now about the ElementFormat and FontDescription objects. Now onto the implementation class you&#8217;ll use.</p>
<h3>TextElement</h3>
<p>Out of the three, TextElement is the most straightforward. It simply accepts a string of text to take care of:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">TextElement<span style="color: #000000;">&#40;</span><span style="color: #004993;">text</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">null</span>, elementFormat<span style="color: #000000; font-weight: bold;">:</span>ElementFormat = <span style="color: #0033ff; font-weight: bold;">null</span>, eventMirror<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span>, textRotation<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;rotate0&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>The ElementFormat you pass in is applied to the entire string of text that this TextElement owns. So if you specify an ElementFormat with a color of <span style="color: #ff0000;">red</span>, the entire string of text will render <span style="color: #ff0000;">red</span>.</p>
<h3>GraphicElement</h3>
<p>The next one to worry about is GraphicElement. He accepts <strong>any DisplayObject instance</strong> (<strong>instance!</strong>), as well as the width and height that you wish to allocate for the Graphic in the text:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">GraphicElement<span style="color: #000000;">&#40;</span>graphic<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span> = <span style="color: #0033ff; font-weight: bold;">null</span>, elementWidth<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">15.0</span>, elementHeight<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">15.0</span>, elementFormat<span style="color: #000000; font-weight: bold;">:</span>ElementFormat = <span style="color: #0033ff; font-weight: bold;">null</span>, eventMirror<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span>, textRotation<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;rotate0&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Some of the properties of the ElementFormat will apply to the GraphicElement, such as <code>alpha</code>, <code>baselineShift</code>, etc. Obviously the GraphicElement doesn&#8217;t respect font-specific settings from the ElementFormat and FontDescription objects.</p>
<h3>GroupElement</h3>
<p>Lastly there&#8217;s the GroupElement:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">GroupElement<span style="color: #000000;">&#40;</span><span style="color: #004993;">elements</span><span style="color: #000000; font-weight: bold;">:</span>Vector.<span style="color: #000000; font-weight: bold;">&lt;</span>ContentElement<span style="color: #000000; font-weight: bold;">&gt;</span> = <span style="color: #0033ff; font-weight: bold;">null</span>, elementFormat<span style="color: #000000; font-weight: bold;">:</span>ElementFormat = <span style="color: #0033ff; font-weight: bold;">null</span>, eventMirror<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span>, textRotation<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;rotate0&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>GroupElement is <strong>critical</strong>. GroupElement is a collection of any combination of TextElements, GraphicElements, or other GroupElements. GroupElement is the Tree functionality of FTE&#8217;s model. TextElement can&#8217;t have children, it controls a single String. Likewise, GraphicElement only describes a single DisplayObject instance. GroupElements tie it all together.</p>
<p>GroupElements provide an API for doing standard Tree functions; you can retrieve, split, merge, and group children using various methods. I speak from experience when I say you won&#8217;t often mess with this unless you&#8217;re writing an editable text field. And if you are writing an editable text field, God help you (just kidding, it is hella fun).</p>
<p>OK, enough Model talk. Onwards to&#8230;</p>
<h2>The FTE View</h2>
<p>There are two (<strong>2!</strong>) classes that make up the entirety of the Flash Text Engine&#8217;s <strong><em>View</em></strong> division: <a target="_blank" title="flash.text.engine.TextLine" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLine.html">TextLine</a> and <a target="_blank" title="flash.text.engine.TextLineMirrorRegion" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLineMirrorRegion.html">TextLineMirrorRegion</a>. Right now you can forget about TextLineMirrorRegion, as that has to do with interaction, which is a complicated topic and one which I will cover in detail later. So for now, only focus on TextLine.</p>
<h3>TextLine</h3>
<p>TextLine is a DisplayObjectContainer. Yes, that means it has the <code>get/add/removeChild</code> methods (<strong>they still work!</strong>), and is also an InteractiveObject. You can listen for all the normal interaction events. However, even though it inherits from InteractiveObject, there are a few properties that you can only read, not write. Those are detailed in the <a href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLine.html">documentation for TextLine</a>.</p>
<p>TextLine adds the concept of <em>atoms</em>, which are indivisible characters in a TextLine. Individual characters are atoms, as well as any graphics you have. The important thing to know here is that atoms can never be split between lines. The FTE will measure only to the atom level, no lower. </p>
<p>Atom information can be expensive to keep around&#8230; At first the TextLine only renders its text, it doesn&#8217;t know anything about the atoms it contains. However calling various methods will cause the TextLine to create its atom data. For example, if you call <code>getAtomIndexAtPoint()</code>, the TextLine must create the info about each atom so it can then calculate which atom occurs at the point you specify. This is all well and good, but be sure to call <code>flushAtomData()</code> once you&#8217;re done so the atom data will be GC&#8217;d.</p>
<p>TextLine has a reference to the previous and next lines, because TextLine is also a <a href="http://en.wikipedia.org/wiki/Doubly-linked_list">doubly-linked list</a>! How convenient! Of course, if there is no previous or next, you know you&#8217;re the first or last lines, respectively.</p>
<p>TextLine also has a <code>validity</code> status, which is whether the ContentElement that the line represents has changed since the line was rendered. Values are described in the <a href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLineValidity.html">TextLineValidity</a> class.</p>
<p>One thing that TextLine definitely <strong>is not</strong>: a Sprite. No, TextLine is a DisplayObjectContainer. The most important implication from this is that TextLine has no <strong>graphics context</strong>. This means you can&#8217;t call textLine.graphics.draw. :( Oh well.</p>
<p>TextLine is a concrete class, you use it directly, but you cannot instantiate one by calling its constructor. To do that you need&#8230;</p>
<h2>The FTE Controller</h2>
<p>There is arguably <strong>one class</strong> in the FTE&#8217;s <strong><em>Controller</em></strong> division: <a target="_blank" title="flash.text.engine.TextBlock" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextBlock.html">TextBlock</a>. I say <em>arguably</em> because yeah, <a target="_blank" title="flash.text.engine.TextJustifier" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextJustifier.html">TextJustifier</a> and <a target="_blank" title="flash.text.engine.TabStop" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TabStop.html">TabStop</a> exist, but they just affect how TextBlock does its rendering, not&#8230; hm. Ok, I&#8217;ve convinced myself that they count as Controller classes too, but only <em>barely</em>.</p>
<p>But believe me, you will come to think of TextBlock as the only Controller class too.</p>
<p>The TextBlock is a fairly standard Factory pattern implementation: TextBlock&#8217;s primary job is to accept a ContentElement as input and output as many TextLines as you want, given a width. <strong>ContentElement</strong> -> <strong>TextBlock</strong> -> <strong>TextLines</strong>. Got it? Me neither.</p>
<p>Ok, so TextBlock has this method called <code>createTextLine()</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">createTextLine<span style="color: #000000;">&#40;</span>previousLine<span style="color: #000000; font-weight: bold;">:</span>TextLine = <span style="color: #0033ff; font-weight: bold;">null</span>, <span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">1000000</span>, lineOffset<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0.0</span>, fitSomething<span style="color: #000000; 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: #000000; font-weight: bold;">:</span>TextLine</pre></div></div>

<p>Ok so what you do is you pass in the <strong><em>previous</em></strong> line that you created, plus the width that you want the <strong><em>current</em></strong> line to be, and TextBlock will measure out a TextLine for you. Are you seeing the doubly-linked list yet?</p>
<p>If you want to create the first line from a TextBlock, you should just pass in <code>null</code> to the <code>createTextLine()</code> method; assuming the TextBlock has content in his <code>content</code> property, and that content has at least one atom (characters or graphics), passing in <code>null</code> will <em>always</em> return a TextLine. If there are no more lines to be created, TextBlock will return <code>null</code> from the call to <code>createTextLine()</code>.</p>
<p>So from this it is simple to render the lines for a TextBlock with width 200:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> line<span style="color: #000000; font-weight: bold;">:</span>TextLine = block.createTextLine<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span>, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span>;
<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: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span>= line.<span style="color: #004993;">height</span>;
    line.<span style="color: #004993;">height</span> = <span style="color: #004993;">y</span>;
    line = block.createTextLine<span style="color: #000000;">&#40;</span>line, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<h3>Ok, I&#8217;ve detailed a lot so far, now it&#8217;s time to get to at an example.</h3>
<h3>Flash:</h3>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_6" width="450" height="32">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo1.swf" width="450" height="32">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>Here&#8217;s the code for the above simple line rendering:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.ContentElement;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.ElementFormat;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.FontDescription;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.FontPosture;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.FontWeight;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.GroupElement;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.TextBlock;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.TextElement;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.engine.TextLine;
&nbsp;
  <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;450&quot;</span>, <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;32&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SimpleDemo1 extends <span style="color: #004993;">Sprite</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SimpleDemo1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> e1<span style="color: #000000; font-weight: bold;">:</span>TextElement = <span style="color: #0033ff; font-weight: bold;">new</span> TextElement<span style="color: #000000;">&#40;</span><span style="color: #990000;">'Consider, what makes a text line a '</span>, <span style="color: #0033ff; font-weight: bold;">new</span> ElementFormat<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FontDescription<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> e2<span style="color: #000000; font-weight: bold;">:</span>TextElement = <span style="color: #0033ff; font-weight: bold;">new</span> TextElement<span style="color: #000000;">&#40;</span><span style="color: #990000;">'text line'</span>, <span style="color: #0033ff; font-weight: bold;">new</span> ElementFormat<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FontDescription<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_serif&quot;</span>, FontWeight.<span style="color: #004993;">NORMAL</span>, FontPosture.<span style="color: #004993;">ITALIC</span><span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> e3<span style="color: #000000; font-weight: bold;">:</span>TextElement = <span style="color: #0033ff; font-weight: bold;">new</span> TextElement<span style="color: #000000;">&#40;</span><span style="color: #990000;">'?'</span>, <span style="color: #0033ff; font-weight: bold;">new</span> ElementFormat<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FontDescription<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> e<span style="color: #000000; font-weight: bold;">:</span>Vector. = <span style="color: #0033ff; font-weight: bold;">new</span> Vector.<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      e.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>e1, e2, e3<span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> block<span style="color: #000000; font-weight: bold;">:</span>TextBlock = <span style="color: #0033ff; font-weight: bold;">new</span> TextBlock<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> GroupElement<span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> line<span style="color: #000000; font-weight: bold;">:</span>TextLine = block.createTextLine<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span>, <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> _y<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
      <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>;
        _y <span style="color: #000000; font-weight: bold;">+</span>= line.<span style="color: #004993;">height</span>;
        line.<span style="color: #004993;">y</span> = _y;
        line = block.createTextLine<span style="color: #000000;">&#40;</span>line, <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p style="font-size: 14px;"><strong>Holy crap Batman!</strong><br />
As you can see, it required <em>3 different TextElements <strong>and</strong> a GroupElement</em> to render some freakin&#8217; italic text in the middle of a sentence. Yeah. Par for the frickin&#8217; course.</p>
<p>In part 2 I&#8217;ll get into more details about interaction, TextBlock manipulation, all of it.<br />
Till then watch this project on github: <a target="_blank" title="tinytlf on github" href="http://github.com/guyinthechair/tinytlf">tinytlf</a>. It&#8217;s due for some major updates but it&#8217;s what I&#8217;m going to start talking about soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/?feed=rss2&amp;p=250</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex 3 Smooth Scrolling, Variable Row Height List</title>
		<link>http://guyinthechair.com/?p=232</link>
		<comments>http://guyinthechair.com/?p=232#comments</comments>
		<pubDate>Mon, 19 Apr 2010 05:54:24 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=232</guid>
		<description><![CDATA[Today I&#8217;m releasing another component, a smooth scrolling List that supports variable row height. I&#8217;ve got three demos of it, the first compares the standard Flex 3 List with my List, the second is another comparison but with a larger data set, and the third is a demo using the eBay API to pull down [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m releasing another component, a smooth scrolling List that supports variable row height. I&#8217;ve got three demos of it, <a href="http://guyinthechair.com/wp-content/flex/ptlib_demo/ListDemo.html" title="List Demo" target="_blank">the first compares the standard Flex 3 List with my List</a>, <a href="http://guyinthechair.com/wp-content/flex/ptlib_demo/LargeListDemo.html" title="Large List Demo" target="_blank">the second is another comparison but with a larger data set</a>, and the third is <a href="http://guyinthechair.com/wp-content/flex/ebay_demo/EBayDemo.html" title="eBay List Demo" target="_blank">a demo using the eBay API to pull down and display search results</a>.</p>
<p>Ok, it&#8217;s not a Flex 3 List and it doesn&#8217;t extend ListBase or even ScrollControlBase. It uses the virtualization feature of the Scroller component I demoed previously to manage scrollPosition.</p>
<p>There are a few reasons I didn&#8217;t use ListBase or ScrollControlBase. I&#8217;ve never felt comfortable with ListBase controlling the backgrounds and interactivity of its itemRenderers. It always seems like a violation of encapsulation, and it bloats the List classes. ScrollControlBase seemed like a place to start, until I realized I was writing tons of code in my List class just to handle scrollbars, so I pulled that out into the Scroller.</p>
<p>The class that really made it possible was <a href="http://github.com/guyinthechair/PTLib/blob/master/com/pt/components/controls/dataClasses/RepeaterData.as" title="RepeaterData" target="_blank">RepeaterData</a>. He&#8217;s the model class behind the list and the reason I know what item renderers to create, but he deserves a blog post of his own.</p>
<p>Right now it&#8217;s still very incomplete. It&#8217;s not very optimized, I can already think of places that speed could be improved. It doesn&#8217;t watch the data provider for refresh events. It doesn&#8217;t manage selection or selected items (yet). It&#8217;s up to the itemRenderer to handle all interaction, and it definitely doesn&#8217;t support any kind of drag and drop gestures. It&#8217;s really just a weekend experiment, but if you want to see it expounded on, leave a message in the comments. If you want to mess with it, it&#8217;s available at the <a href="http://github.com/guyinthechair/PTLib" title="PTLib" target="_blank">PTLib github repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/?feed=rss2&amp;p=232</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex 3 Scroller Component</title>
		<link>http://guyinthechair.com/?p=226</link>
		<comments>http://guyinthechair.com/?p=226#comments</comments>
		<pubDate>Sun, 18 Apr 2010 21:50:03 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=226</guid>
		<description><![CDATA[Here&#8217;s a Scroller component similar to Flex 4&#8242;s Scroller. It takes a single DisplayObject child and creates scrollbars at the edges. Scroller has an inset property, which controls whether the scrollbars overlap the content area or not. You can set the inset property to false, which will move the scrollbars outside the content area. Scroller [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a Scroller component similar to Flex 4&#8242;s Scroller. It takes a single DisplayObject child and creates scrollbars at the edges.</p>
<p>Scroller has an <strong>inset</strong> property, which controls whether the scrollbars overlap the content area or not. You can set the <strong>inset</strong> property to false, which will move the scrollbars outside the content area.</p>
<p>Scroller supports scroll &#8220;ramping&#8221;. When you hold one of the arrow buttons, instead of scrolling by 1 each time, it supports the ability to &#8220;ramp up&#8221; the scroll delta, which increments the position up to a certain threshold and scrolls that amount until the button is released.</p>
<p>Scroller also supports manual or virtualized scrolling. If you want to use Scroller, but don&#8217;t want Scroller to manually reposition the content area, you can specify which properties on the target to measure width and height, and which to set when the scrollPosition changes.</p>
<p><a href="http://guyinthechair.com/wp-content/flex/ptlib_demo/ScrollerDemo.html" title="Scroller Demo" target="_blank"><u>Here&#8217;s a demo</u></a>, and you can find it in a common component library I&#8217;m releasing on github called <a href="http://github.com/guyinthechair/PTLib" title="PTLib" target="_blank">PTLib</a>. I&#8217;ve tried to test it in creative ways, but I&#8217;m sure there are still bugs. So if you find some, just fork it, fix it, pull request it!</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/?feed=rss2&amp;p=226</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Flex Framework and Modularity: A Manifesto</title>
		<link>http://guyinthechair.com/?p=164</link>
		<comments>http://guyinthechair.com/?p=164#comments</comments>
		<pubDate>Wed, 20 Jan 2010 08:33:46 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[bitching]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flashworks]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[greg burch]]></category>
		<category><![CDATA[LayoutManager]]></category>
		<category><![CDATA[modularity]]></category>
		<category><![CDATA[RIAdventure]]></category>
		<category><![CDATA[UIComponent]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=164</guid>
		<description><![CDATA[If you haven&#8217;t watched Greg Burch&#8217;s excellent presentation on Slider at RIAdventure, you freakin should. Seriously, stop right now and watch it. But don&#8217;t forget about this blog post. Make sure to come back here after you&#8217;re done. The Soul of Flex Ok, from this point on I am going to assume you&#8217;ve done exactly as I [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: normal; font-size: 13px;">If you haven&#8217;t watched Greg Burch&#8217;s <a title="Greg Burch's RIAdventure Slider Presentation" href="http://www.screencast.com/users/jwilker/folders/RIAdventure%202009/media/03101638-66d9-4792-97de-77a8fc7c053f" target="_blank">excellent presentation on Slider</a> at RIAdventure, you freakin should. Seriously, stop right now and watch it. But don&#8217;t forget about this blog post. Make sure to come back here after you&#8217;re done.</span></p>
<h2>The Soul of Flex<br />
<span style="font-weight: normal; font-size: 13px;">Ok, from this point on I am going to assume you&#8217;ve done exactly as I told you and watched Greg Burch&#8217;s <a title="Greg Burch's RIAdventure Slider Presentation" href="http://www.screencast.com/users/jwilker/folders/RIAdventure%202009/media/03101638-66d9-4792-97de-77a8fc7c053f" target="_blank">excellent presentation on Slider</a> at RIAdventure. Around 6 minutes in, Greg starts talking about the Soul of Flex. I didn&#8217;t have much time to consider it, but two things immediately came to mind: invalidation and styles. In the video you&#8217;ll hear me mention CSS but later agree with Greg that CSS or not, styles is the true feature.</span></h2>
<p>Of course, I agree with all the others he said were also part of the Soul: MXML, databinding, states, skinning, item renderers, containers, and components. But as I watched him remove items that weren&#8217;t part of the Soul of Flex, I thought to myself:</p>
<p style="padding-left: 30px;">&#8220;Self, this list is completely subjective and based entirely on my opinion. It is extremely likely that someone else&#8217;s definition of the Soul of Flex is different than mine, and who&#8217;s to say which one is right? Is it Adobe&#8217;s job? Now that they&#8217;ve packed a framework full of features that real people use, they&#8217;re going to remove a good many features simply because the they do not fall into Adobe&#8217;s definition of what the Soul is? That&#8217;s not right. The community is too diverse for that. Flex is the Soul of Flex.&#8221;</p>
<div id="attachment_170" class="wp-caption alignleft" style="width: 160px"><a href="http://guyinthechair.com/wp-content/uploads/2010/01/soul-of-flex.png" target="_blank"><img class="size-thumbnail wp-image-170" title="Soul of Flex" src="http://guyinthechair.com/wp-content/uploads/2010/01/soul-of-flex-150x150.png" alt="The real Soul of Flex" width="150" height="150" /></a><p class="wp-caption-text">I say Flex is the Soul of Flex.</p></div>
<p>This got me thinking about Flex with regards to mobile development. At the time of this writing, every Flex 4 component has a base class that is <a title="UIComponent" href="http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UIComponent.as" target="_blank">13,246 lines of code</a> (<a title="CLOC parser in JS" href="http://dnalot.com/SparkDataGrids/clocFx.html" target="_blank"><strong>1412</strong> blank lines, <strong>6423</strong> comment lines, and <strong>5411</strong> actual code lines.</a>) If you&#8217;re using Flex 4 and skinning, you have two components, so multiply potentially everything the UIComponent does by 2:</p>
<ul style="list-style-position: inside;">
<li>2x the UIComponents to initialize</li>
<li>2x the UIComponents added to the inheriting style chain</li>
<li>2x the UIComponents to make validation passes on</li>
<li>2x the event listeners that are registered</li>
<li>2x the number of objects for the DragProxy (in the DragManager) to find in its getObjectsUnderPoint() implementation</li>
<li>and on and on&#8230;</li>
</ul>
<p>This means one of two things. Either the decision to abstract skins into another UIComponent was monumentally retarded, or the UIComponent is too large and tries to do to many things. Since I believe the new skins are wonderful from an architectural/modularity standpoint, I have to pick the second choice: <strong>the UIComponent is too damn big</strong>. It tries to do too damn much. Let me reiterate: <strong>I love the new Spark skins. I hate the size of the UIComponent.</strong></p>
<h2>The Question of Responsibility<br />
<span style="font-weight: normal; font-size: 13px;">Why is the UIComponent (at the time of this writing) 13,246 lines long? The answer is features. The UIComponent violates the <a title="Single Responsibility Principle" href="http://en.wikipedia.org/wiki/Single_responsibility_principle" target="_blank">Single Responsibility Principle</a>. Here&#8217;s a list of most of the features the UIComponent encapsulates:</span></h2>
<ul>
<li>Invalidation &#8211; Implements IInvalidating.
<ul>
<li>Defines invalidate properties/size/displayList functions.</li>
<li>Defines validateNow function.</li>
</ul>
</li>
<li>Validation &#8211; Implements ILayoutManagerClient.
<ul>
<li>Defines the initialized, nestLevel, processedDescriptors, and updateCompletePendingFlag properties.</li>
<li>Defines validate properties/size/displayList functions.</li>
</ul>
</li>
<li>Styles &#8211; Implements IAdvancedStyleClient, the only visual class that does.</li>
<li>States &#8211; Implements IStateClient and IStateClient2 to support the new Fx4 states syntax.</li>
<li>Tooltips &#8211; Implements IToolTipManagerClient, the only component class that does.</li>
<li>Constraint-based layout.</li>
<li>IRepeaterClient &#8211; UIComponents (and subclasses) can be created by Repeaters.</li>
<li>Databinding.</li>
<li>Related to Databinding, implements IPropertyChangeNotifier.</li>
<li>Embedded fonts.</li>
<li>Focus &#8211; Doesn&#8217;t implement IFocusManagerComponent by name, but does implement the functions. Has a reference to the FocusManager and a focusPane property.</li>
<li>Validators &#8211; Implements IValidatorListener, which allows the UIComponent to respond to ValidationResultEvents dispatched by the Validator classes.</li>
<li>Modules &#8211; Implements IFlexModule, so if created by an IFlexModuleFactory, the factory stores a reference of itself on the UIComponent.</li>
<li>Explicit/measured- max/min &#8211; widths/heights.</li>
<li>Percent widths/heights.</li>
<li>Enabled/disabled.</li>
<li>Effects.</li>
<li>Special logic for adding/removing children.</li>
<li>All the events it creates and dispatches, including
<ol>
<li>Initialization events, like preInit and creationComplete.</li>
<li>FlexEvents like show, hide, move, resize</li>
<li>StateChangeEvents.</li>
<li>DragEvents for the List classes. Not part of the public API.</li>
<li>ToolTipEvents</li>
<li>FlexMouseEvents</li>
</ol>
</li>
</ul>
<p>Man, the UIComponent does a ton of stuff. We haven&#8217;t even gotten into the measurement, layout, containment, children handling, skinning, item renderers, or graphics functionality of Flex yet!</p>
<h2>The UIComponent is the base class for&#8230; everything<br />
<span style="font-weight: normal; font-size: 13px;">At least, everything visual. Not including Flex 3 skins. It&#8217;s the base class for all non-Fx3-skin-related visual elements.</span></h2>
<p>The UIComponent has so many responsibilities because it is the base class for so many controls. You want a Label or TextArea? They&#8217;re UIComponents. You want a Button? It&#8217;s a UIComponent. You want a container of Buttons? It&#8217;s a UIComponent.</p>
<p><span style="font-weight: normal; font-size: 13px;">But there are a few things I can&#8217;t figure out about this configuration:</span></p>
<ol>
<li>Why does a container need logic in its base class that accesses embedded fonts, or creates UITextFields from embedded font contexts (I checked, UITextField is the only class passed into createInFontContext()).</li>
<li>Similarly, why does a Label require any knowledge about processedDescriptors, states, or validators? Labels can&#8217;t have children, states, or validators. In fact, Labels can&#8217;t do much except display text. Why do they need to be IFlexModule objects? I could go on, but I think you get the point.</li>
</ol>
<p>There is a trend of WTFs like this about the UIComponent that can only be explained by, &#8220;it&#8217;s <strong>the</strong> base class and we&#8217;re trying to keep our API super clean.&#8221;</p>
<h2>There is a better way: Composited Modularity<br />
<span style="font-weight: normal; font-size: 13px;">Most of the functionality is already segregated by the liberal use of interfaces&#8230; now lets actually implement it that way.</span></h2>
<p>Almost all the functionality that the UIComponent (and subclasses of UIComponent for that matter) contains can be grouped into smaller, more discreet classes. Lets call them modules. Once this is done, the UIComponent simply exists to provide a unified API to the developer and glue with which to assemble the modules. More complex controls and components are simply composed of more complex modules.</p>
<p>For example, the functionality for embedded fonts should be isolated into its own module. Then, only the Label, Text, TextArea, and maybe some other controls that require direct access to embedded fonts need to include the &#8220;EmbeddedFontsModule.&#8221; This way, the VBox doesn&#8217;t have to include functionality for accessing embedded fonts.</p>
<p>Similarly, a VBox would include special modules for adding children, measurement, and layout. See, this is easy.</p>
<p><span style="font-weight: normal; font-size: 13px;">And while we&#8217;re at it, let&#8217;s rewrite the LayoutManager.</span></p>
<h2>You heard me. The LayoutManager. It&#8217;s in my sights.<br />
<span style="font-weight: normal; font-size: 13px;">What&#8217;s so special about 3-phased validation that it has to be hard-coded into the Flex framework? Is it phase ordering? Nest-level ordering? That&#8217;s not special. That&#8217;s algorithms.</span></h2>
<p>First, for those who don&#8217;t know, the LayoutManager is what enables Flex components to do the awesome 3-phase component lifecycle that we&#8217;ve all come to know and love. When a component is invalidated for a phase (say, invalidateProperties()), he registers with the LayoutManager. The LayoutManager adds the component to the proper invalidation queue. There are 3 invalidation queues, one for each validation phase. The invalidation queues are a special PriorityQueue implementation. This is important, because there is an order to the validation process.</p>
<p>Components have a nestLevel, which is really just their position in the display list. The Application&#8217;s nestLevel is 3. The nestLevel increases from there, so the lowest component in the display tree has the highest number.</p>
<p>When a component is added to the invalidatePropertiesQueue, it is added at its nestLevel priority. When the invalidatePropertiesQueue is processed, components with the lowest nestLevel, the ones closest to 0, are processed first. This is called &#8220;top-down&#8221; processing, because it starts at the top of the display list and processes to the bottom.</p>
<p>The commit phase does top-down processing, because generally parents can commit properties on themselves and change properties on their children, which will then get committed. The measure phase is from the bottom-up (can you guess what that means? If not, put it in the comments.), because a parent will often make a decision on his size based on the sizes of his children. The update phase is another top-down queue, because now that the sizes and positions are calculated, it&#8217;s time to lay them out. This is what makes percent widths/heights, scrollbars, etc. possible.</p>
<h3>Rethinking validation<br />
<span style="font-weight: normal; font-size: 13px;">Does validation have to be hardcoded? Are the 3 phases all that are needed? How hard would it be to switch to just 2? 4? 100?</span></h3>
<p>The fact is, the developer should be able to hook into the power of phased updates for himself. Why have a manager that only validates 3 hard-coded phases, when you could have a manager that validates an unlimited number of dynamic phases?<br />
<span style="font-weight: normal; font-size: 13px;">Well sure Paul, that sounds great and all, but it&#8217;s kind of a tough problem.</span> &lt;&#8211; Shut up alternate text, I&#8217;ve got a solution.</p>
<p>Keep the idea of nestLevel. It&#8217;s clear, clean, and definite. Change the idea of 3 hard-coded phases into an unlimited number of injected phases, based on priorities. Similar to nestLevel for components, priorities are arbitrarily defined by the developer. A priority is an Array of ints. It can be as simple as &#8220;1&#8243; or as complex as &#8220;1.2.3.4.&#8221; It is only used as a basis for comparison between other priorities. For example, priority 1.2 is greater than priority 1.2.1, since it is assumed 1.2.1 is a subset of 1.2. However, 1.200 is much greater than 1.2, because 200 &gt; 2. Do priorities make sense? If the answer is no, put it in the comments.</p>
<p>The idea is that a developer can invalidate a component for a certain phase. The phase has a priority (like 1.3), and a direction (UP or DOWN). The ValidationManager keeps a Heap of Heaps, sorted by priority. If it doesn&#8217;t find a Heap at the priority specified, it creates a new Heap, adds the IValidationClient to it, sets the proper sort direction (UP or DOWN) on it, then adds the new Heap to the Heap of Heaps. If it does find a Heap, it adds the IValidationClient to the Heap that it found.</p>
<p>When it comes time to Validate (on the next enter_frame event), the ValidationManager dequeues each Heap from the Heap of Heaps. Then it dequeues each item from each individual Heap, validating it as it goes.</p>
<p>The beauty of this is that the Flex component lifecycle can be perfectly mimicked. Set the three phases to happen one after another, and you can get the same results. For APIs sake, lets add a gap between them, so a third party developer can come by later and inject his own phases between the 3 usual phases. If we set commit at 1.3, measure at 1.5, and update at 1.7, this should give us enough of a gap for developers to use.</p>
<p>Say Developer X wants to add some extra <strong>umph</strong> to his custom component, but needs this processing needs to happen in-phase and inbetween the measure and update phases. He simply needs to inject his own validation phase anywhere between measure at 1.5 and update at 1.7, lets keep it simple and say 1.6, and BAM. ValidationManager will validate his phase right after measure and right before update.</p>
<p>This allows the developers a whole new avenue of development, something that they would have had to tack onto one of Flex&#8217;s 3 hard-coded phases before.</p>
<p><span style="font-weight: normal; font-size: 13px;"> This is all words. Where are the actions. You fail.</span></p>
<h2>This is where I introduce FlashWorks<br />
<span style="font-weight: normal; font-size: 13px;">FlashWorks is a component set for Flash and FlashBuilder, designed around the concepts of a tiny core API and modularity.</span></h2>
<p>It includes the ValidationManager and validation scheme I&#8217;ve outlined here, as well as a few other things:</p>
<ul>
<li>MXML development</li>
<li>Skinning similar to Flex 4</li>
<li>Graphics primitives (extend EventDispatcher)</li>
<li>Measurement and Layout controllers with support for percent widths/heights</li>
<li>Injectable Validation phases</li>
<li>States, including support for FB4&#8242;s new States syntax</li>
<li>Styles, through a controller that interfaces with <a title="F*CSS Flash CSS parsing" href="http://fcss.flashartofwar.com/" target="_blank">Jesse Freeman&#8217;s F*CSS</a></li>
<li>Databinding</li>
<li>SystemManager that works with FB4&#8242;s code generation, so the FlashWorks movie is 2 frames, just like Flex.</li>
<li>A modular, pay-as-you-go system, so functionality is only included when it&#8217;s used. For instance, the States controller isn&#8217;t included unless States are defined on the component.</li>
</ul>
<h2>Alright, here&#8217;s the code and demos</h2>
<p><font color="#000099">[Edit]</font> I&#8217;ve since moved from this project onto <a href="http://github.com/guyinthechair/reflex">Reflex</a>. I feel it has more of a chance for success than a solo framework by me would.<br />
I&#8217;m keeping the demo and demo code here as a proof of concept:<br />
Demo: <a title="FlashWorks demo" href="http://guyinthechair.com/misc/flashworks/FlashWorks.html" target="_blank">http://guyinthechair.com/misc/flashworks/FlashWorks.html</a><br />
Source code for demo: <a title="FlashWorks Demo Source" href="http://guyinthechair.com/misc/flashworks/srcview/index.html" target="_blank">http://guyinthechair.com/misc/flashworks/srcview/index.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/?feed=rss2&amp;p=164</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Understanding the Flex SystemManager</title>
		<link>http://guyinthechair.com/?p=113</link>
		<comments>http://guyinthechair.com/?p=113#comments</comments>
		<pubDate>Sun, 17 Jan 2010 22:06:50 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[SystemManager]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=113</guid>
		<description><![CDATA[Before I start, let me say that there has been a lot of discussion about the SystemManager on various blogs. Deepa posted a fantastic write-up on the SystemManager back in October 07, which really got me interested in learning about it more. Working on Flex-less MXML is what finally pushed me to understand exactly why [...]]]></description>
			<content:encoded><![CDATA[<p>Before I start, let me say that there has been a lot of discussion about the SystemManager on various blogs. <a title="Deepa's fantastic blog on Flex" href="http://iamdeepa.com/blog/" target="_blank">Deepa</a> posted a fantastic <a title="SystemManager: Every Flex application's best friend" href="http://iamdeepa.com/blog/?p=11" target="_blank">write-up</a> on the SystemManager back in October 07, which really got me interested in learning about it more. Working on Flex-less MXML is what finally pushed me to understand exactly why it&#8217;s such a critical class. There&#8217;s a lot to cover about the SystemManager, from the behavior of the Flash Player to the behavior of the Flex compiler, so buckle up, cause this is a long one.</p>
<p><strong>Note 1: A recurring theme in this post is the fundamental behavior of the Flash Player. Flex would be nowhere without Flash, so if we desire true understanding of Flex, we must also understand the Flash Player.<br />
Note 2: For some of this, it is helpful to turn on the -keep-generated-actionscript flag in the FlashBuilder compiler options. To do this, go to Project &#8211;&gt; Properties &#8211;&gt; Flex Compiler. In the &#8220;Additional compiler arguments&#8221; field, type &#8220;-keep&#8221; at the end of the arguments list. FlashBuilder generates ActionScript from all your MXML, including a dynamic subclass of SystemManager. This will instruct FlashBuilder to place that code in the bin-debug/generated folder.</strong></p>
<p><span style="font-weight: normal; font-size: 14px;">To understand the SystemManager, you must first understand that&#8230;</span></p>
<h2>Every Flex Application is a 2-Frame Flash Movie</h2>
<p><img class="alignleft size-full wp-image-114" title="2 Frame Flash Movie" src="http://guyinthechair.com/wp-content/uploads/2010/01/loader_content_flash.png" alt="2 Frame Flash Movie" width="302" height="63" /> Yes, every one of them. The Flash Player is capable of downloading just the data for the first frame and streaming the rest of the movie. Therefore a trend started in the earlier days of Flash-only developing; you typically put a very small loader object on your first frame that displays the loading progress of the rest of the SWF to the user. That way the user has a visual indication that something is happening, and the movie gets preloaded to a point where the user won&#8217;t experience any playback hiccups.</p>
<h2>That is awesome&#8230; why do I care?<br />
<span style="font-weight: normal; font-size: 14px;">Good question. First, lets examine the implications of Flash&#8217;s load-and-stream feature:</span></h2>
<p>From a movie perspective if frames aren&#8217;t loaded, the movie stops until they are loaded. If the movie is constantly experiencing this, the movie&#8217;s framerate essentially becomes a function of the speed of the user&#8217;s internet connection.<br />
From a code perspective, <strong>if frames aren&#8217;t fully loaded, classes can&#8217;t be accessed</strong>. Calling <code>new MyObject()</code> will throw a runtime error, &#8220;1065: Variable MyObject is not defined.&#8221; This is because the frame that contains the definition for that class hasn&#8217;t been fully loaded.</p>
<h2>Oh I see now, so we need a small preloader on the first frame?<br />
<span style="font-weight: normal; font-size: 14px;">Exactly. All that silly Flash that we thought we left behind when we became &#8220;Enterprise Flex Developers&#8221; has come back to bite us in the ass. But never fear, the SystemManager is here.</span></h2>
<p><strong>The SystemManager is a fancy MovieClip</strong>. The SystemManager has a few duties, including:</p>
<ul>
<li>Create and initialize the pre-loader to show to the user during app load and startup.</li>
<li>Manage loading in RSLs.</li>
<li>Manage module logic. If the SystemManager is the root of the SWF, he knows he is a Flex Application. If he is not the root of the SWF, he knows he is a module, and must communicate with whichever SystemManager is the root of the SWF (see if you can spot the logical flaw of the assumption made in that sentence, there will be a quiz later). SystemManager must communicate events both ways between modules/app, such as mouse and keyboard events.</li>
<li>Manage Event.RESIZE events dispatched from the Stage.</li>
<li>Manages the embedded fonts list</li>
<li>Initializes the various manager singletons, such as ResourceManager and StylesManager.</li>
<li>Manages top-level application windows. The SystemManager maintains a <code>cursorChildren</code> list and a <code>popUpChildren</code> list, for tooltips and pop-up windows respectively.</li>
<li>Once all the code for the movie is loaded, SystemManager creates your actual Application instance and calls <code>initialize()</code>.</li>
<li>Adds the Application to the stage once the Application dispatches its FlexEvent.CREATION_COMPLETE event. This is why the Application doesn&#8217;t have a reference to the stage when its FlexEvent.CREATION_COMPLETE is dispatched, when all the other components do.</li>
</ul>
<h2>How it works<br />
<span style="font-weight: normal; font-size: 14px;">How the SystemManager does its thing. Matching colors are event listening/dispatching pairs.</span></h2>
<table border="0">
<tbody>
<tr>
<td>
<h3>Frame 1</h3>
</td>
<td>
<h3>Frame 2</h3>
</td>
</tr>
<tr>
<td width="50%">
<ul>
<li>stop()</li>
<li>listen for player <span style="color: #ff0000;">init</span> event</li>
<li><span style="color: #ff0000;">init</span> dispatched:
<ol>
<li>get root SystemManager (if we&#8217;re not the top level)</li>
<li> listen for <span style="color: #ff6600;">enterFrame event</span></li>
<li>create preloader</li>
<li>listen for <span style="color: #66FF00;">preloaderDocFrameReady</span> from preloader</li>
<li>listen for <span style="color: #999900;">complete</span> from preloader</li>
<li>load RSLs and wait</li>
<li>RSLs loaded. <span style="color: #66FF00;">preloaderDocFrameReady</span> dispatched by preloader
<ul>
<li><span style="color: #3366ff;">Timer created</span> to go run nextFrame() after 100 milliseconds</li>
</ul>
</li>
<li>Exactly 10 milliseconds after preloaderDocFrameReady dispatched, <span style="color: #999900;">complete</span> dispatched by preloader</li>
<li><span style="color: #3366ff;">Timer event</span> dispatched, nextFrame() called/<span style="color: #ff6600;">enterFrame handler</span> triggered</li>
</ol>
</li>
</ul>
</td>
<td width="50%">
<ul>
<li>Managers initialized.</li>
<li>Stage Resize listener added.</li>
<li>Application instance created.</li>
<li>listener for Application <span style="color: #ff00ff;">creationComplete</span> added</li>
<li>nextFrame()</li>
<li>Application <span style="color: #ff00ff;"> creationComplete</span> dispatched
<ol>
<li>Preloader removed</li>
<li>Application added to the stage</li>
<li>applicationComplete event dispatched</li>
</ol>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<h2>Hold on, I&#8217;m a Flex developer. I don&#8217;t work with frames.<br />
<span style="font-weight: normal; font-size: 14px;">I don&#8217;t have access to the timeline of my SWF. Actually, you do.</span></h2>
<p>It&#8217;s through an undocumented meta tag, [Frame], which is really just a shortcut for the -frames compiler option. You can <a title="[Frame] meta tag explanation" href="http://blogs.adobe.com/rgonzalez/2006/06/modular_applications_part_2.html" target="_blank">read all about the frame meta tag</a> at Roger Gonzalez&#8217;s blog, but here&#8217;s the gist of it: If you add the [Frame] meta tag to the top of the Application class of your project, the Flex compiler will insert a frame before the frame that your Application is on. If you specify the factoryClass property on the meta tag, the Flex compiler will generate a subclass of whichever class you specify as the factory, and put that on the frame it creates. If you open up the mx.core.Application class, you&#8217;ll see the line [Frame(factoryClass="mx.managers.SystemManager")] near the top. This tells the Flex compiler to create a frame before the mx.core.Application, and attach a generated subclass of mx.managers.SystemManager.</p>
<p>The Flex compiler will generate a subclass of your factory class that implements <code>IFlexModuleFactory</code>. As long as your SystemManager implements IFlexModuleFactory, your code will compile. The Flex compiler overrides the info() method and returns information specific to your Application, such as a list of embedded fonts and the name of your Application.</p>
<p>And with this meta tag, you can override the default SystemManager implementation. As Roger says, &#8220;if the [Frame] metadata exists on the base class of your application, a subclass of the factory will be generated. If the metadata is directly on your application class, it will be honored, but no subclass will be generated; its assumed that you&#8217;ve already written the appropriate factory.&#8221;</p>
<h2>Why this is cool</h2>
<p>Most Flex developers will never even know the SystemManager exists, and they shouldn&#8217;t have to. Adobe has done a good job of masking Flash behind a more professional, Java-like framework with Flex. If you want to write an app with zero dependence on the Flex framework, but still use the fantastic FlashBuilder IDE, debugger/profiler, MXML, and binding, this is really good to know. You can write an Application based on Sprite, write your own stripped down version of the SystemManager, and then write MXML and take advantage of Flex&#8217;s bindings and generated code. Rock on.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/?feed=rss2&amp;p=113</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>360 Flex/RIAdventure Cruise</title>
		<link>http://guyinthechair.com/?p=72</link>
		<comments>http://guyinthechair.com/?p=72#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>
		<category><![CDATA[doug mccune]]></category>
		<category><![CDATA[Flex 360]]></category>
		<category><![CDATA[greg burch]]></category>
		<category><![CDATA[john wilker]]></category>
		<category><![CDATA[josh cyr]]></category>
		<category><![CDATA[nate beck]]></category>
		<category><![CDATA[RIAdventure]]></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/?feed=rss2&amp;p=72</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Particle Emitter Publishing Tool</title>
		<link>http://guyinthechair.com/?p=61</link>
		<comments>http://guyinthechair.com/?p=61#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[Code Generation]]></category>
		<category><![CDATA[Emitter]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Particle]]></category>
		<category><![CDATA[Particle Emitter]]></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/?feed=rss2&amp;p=61</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Specify any property, style any object (not just UIComponent!)</title>
		<link>http://guyinthechair.com/?p=46</link>
		<comments>http://guyinthechair.com/?p=46#comments</comments>
		<pubDate>Sun, 08 Nov 2009 22:29:01 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=46</guid>
		<description><![CDATA[The styles in Flex are a wonderful thing. They allow a degree of control over the views in your app without the need to modify source code and recompile. However, the styles are (mostly) predefined and quite rigid. There are reasons for this, but the application of styles are not always consistent with the spirit [...]]]></description>
			<content:encoded><![CDATA[<p>The styles in Flex are a wonderful thing. They allow a degree of control over the views in your app without the need to modify source code and recompile. However, the styles are (mostly) predefined and quite rigid. There are reasons for this, but the application of styles are not always consistent with the spirit of the idea.</p>
<p>For instance, you cannot set the <code>x</code>, <code>y</code>, <code>width</code>, or <code>height</code> properties on a component through styles, presumably because it would negatively affect layout algorithms. However, you can set the <code>horizontalCenter</code> style, which affects the placement of components inside <code>Container</code> subclasses that use <code>CanvasLayout</code> (<code>Canvas</code> and any containers with <code>layout="absolute"</code>). If <code>horizontalCenter</code> is defined, these containers obey the law of the style instead of the developer who manually sets the <code>x</code> or <code>y</code>. So if you have a production application, with your layouts working well and code running smoothly, all it takes to completely screw over your Canvases and Panels is for <code>Canvas{horizontalCenter: 0;}</code> to appear somewhere in your external stylesheet.</p>
<p>Another problem with styles is that there is <strong>no way</strong> to retrieve the styles contained in a <code>CSSStyleDeclaration</code> object. This means that you can&#8217;t style an object that doesn&#8217;t extend <code>UIComponent</code>. One can argue that this is by design: the inheriting nature of certain styles means that it is very costly to maintain the chain throughout all the components, and <code>UIComponent</code> has a very nice caching scheme. But this is a pain when you work with <code>Sprite</code>s and <code>Shape</code>s instead of <code>UIComponent</code>s and <code>ProgrammaticSkin</code>s.</p>
<p>So if you want a-la-carte styling without the <code>UIComponent</code>, you are out of luck.</p>
<p>The solution? <a href="http://en.wikipedia.org/wiki/Monkey_patch" title="Monkey-Patch">Monkey-patch</a> (or underride, <a href="http://dougmccune.com/blog/2007/08/17/my-360flex-slides-and-code/" title="Underride">as Doug McCune called it</a>) the <code>CSSStyleDeclaration</code> object to expose a getter called <code>styles</code>. Ideally, this function returns all the styles in the order that they are overridden. So a style set through MXML overrides a style set through a stylesheet, and a style set using <code>setStyle()</code> overrides a style set through MXML.</p>
<p>Luckily, I have written the monkey-patch for you. All you need to do is put it inside a package called mx.styles in your project, and your app will be using the new <code>CSSStyleDeclaration</code> class.</p>
<p><a href="http://guyinthechair.com/wp-content/flex/styles/StylesTest.zip">Get it here</a>, and view a <a href="http://guyinthechair.com/wp-content/flex/styles/StylesTest.html" title="Styles Demo" target="_blank">demo here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/?feed=rss2&amp;p=46</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Physics and Flex: Box2DFlashAS3 meets Flex</title>
		<link>http://guyinthechair.com/?p=26</link>
		<comments>http://guyinthechair.com/?p=26#comments</comments>
		<pubDate>Thu, 15 Oct 2009 09:17:51 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Box2D Flex]]></category>
		<category><![CDATA[Box2DFlashAS3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash physics]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[flex library]]></category>
		<category><![CDATA[Flex physics]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[MXML Physics]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=26</guid>
		<description><![CDATA[Update: I have since abandoned this project in favor of the PushButton Engine, which wraps Box2D and provides a better graphics and component set than I could hope to achieve on my own. So far this has served as a useful academic exercise, and I will keep the code here for future reference. The Setup [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ffcc00;">Update</span><span style="color: #ffcc00;">:</span> I have since abandoned this project in favor of the <a title="PushButton Engine" href="http://pushbuttonengine.com/" target="_blank">PushButton Engine</a>, which wraps Box2D and provides a better graphics and component set than I could hope to achieve on my own. So far this has served as a useful academic exercise, and I will keep the code here for future reference.</p>
<h3>The Setup</h3>
<p>For those not in the know, <a title="Box2D" href="http://www.box2d.org/" target="_blank">Box2D</a> is an open source 2D physics engine for C++. There are many ports of it, and luckily there&#8217;s one for <a title="Box2D Flash AS3" href="http://box2dflash.sourceforge.net/" target="_blank">AS3 (Box2DFlashAS3)</a>. The current version (2.0.2) looks very similar to the C++ version, and might be a straight port (I&#8217;m not entirely sure). It follows the C++ syntax of class prefixes and allows public access to (what should be) internal member variables. 2.1 promises cleaned up syntax and fixed accessor types, but until then, the library can seem daunting to the uninitiated.</p>
<h3>The Problem</h3>
<p>The main problem is that Box2D doesn&#8217;t define a (reusable) way to graphically represent objects on the screen. It only simulates the interactions between the objects mathematically. This is very efficient, but not very convenient if you need to rapidly prototype a physics based application. There are <a title="Box2d Flash World Construction Kit" href="http://www.sideroller.com/wck/" target="_blank">tools</a> to <a title="b2ide Flash components" href="http://code.google.com/p/b2ide/" target="_blank">build</a> Box2D worlds for the Flash environment, but they emphasize working within the Flash IDE. I hate and loathe the Flash IDE (not AS3 projects themselves, mind you). I want something tailored for Flex. I want something that fits into the rapid application development cycle of most Flex apps, which means I want to use MXML. I want to stay up to date with the Box2D project, so when 2.1 does roll around, I won&#8217;t have to rewrite application code.</p>
<h3>The Solution</h3>
<p>Enter FlexWorld. FlexWorld is a framework for graphical representation of Box2D bodies. It is most similar to the <a title="Box2D Flash World Construction Kit" href="http://www.sideroller.com/wck/" target="_blank">World Construction Kit</a>, but is meant exclusively for Flex. You get all the benefits of Flex, including the <a href="http://livedocs.adobe.com/flex/3/langref/mx/managers/LayoutManager.html" target="_blank">LayoutManager</a>, styles, events, data binding, and MXML.</p>
<h3>The Demo</h3>
<p><a href="http://guyinthechair.com/wp-content/flex/flexWorld/demo/index.html" target="_blank">FlexWorld Demo (launches in a new window)</a></p>
<h3>How it Works</h3>
<p>FlexWorld starts with a PhysicalWorld, which is a subclass of <a title="The Container class" href="http://livedocs.adobe.com/flex/3/langref/mx/core/Container.html" target="_blank">Container</a>. PhysicalWorld has boundaries determined by its width and height. Children of the PhysicalWorld are typically subclasses of the abstract class PhysicalBody (which extends <a title="The UIComponent class" href="http://livedocs.adobe.com/flex/3/langref/mx/core/UIComponent.html" target="_blank">UIComponent</a>). Right now, only the PhysicalBox and PhysicalCircle classes are available. World initialization happens only when you say it does, and clean up is as efficient as can be. To get going, initialize the world: PhysicalWorld#createWorld. Then, you can register each PhysicalBody with the world by calling PhysicalWorld#registerBody. This is to ensure proper instantiation and update. When the world is ready to go, just call PhysicalWorld#activate, and it will start rendering.</p>
<h3>In-Phase updates</h3>
<p>PhysicalWorld renders by calling PhysicalBody#update on each PhysicalBody registered with it. This render cycle falls into the commitProperties phase of the component lifecycle (more on that <a title="About the component instantiation life cycle" href="https://www.adobe.com/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=ascomponents_advanced_148_05.html" target="_blank">here</a> and <a title="About the steps for creating a component" href="https://www.adobe.com/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=ascomponents_advanced_148_06.html#219779" target="_blank">here</a>). This ensures that properties are changed at the beginning of the lifecycle, just before commits will happen. If the render is meant to continue, updateDisplayList (which is at the end of the update cycle) will call UIComponent#invalidateProperties on the PhysicalWorld.</p>
<h3>Where is this going</h3>
<p>This is a very alpha release. Everything that you see works, and not much else. The shapes aren&#8217;t interactive yet, and they don&#8217;t do much drawing beyond what you see. Nothing is documented (and I&#8217;m horrible at keeping up with it), I don&#8217;t even have an SVN repository set up yet. Right now it&#8217;s primarily an interesting proof-of-concept rather than a useful tool. I&#8217;ll be developing it more for a project I&#8217;m currently on, and hopefully I&#8217;ll roll those changes in.</p>
<h3>The Source</h3>
<p>The source for the demo is <a title="FlexWorld demo source" href="http://guyinthechair.com/wp-content/flex/flexWorld/demo/srcview/index.html" target="_blank">here</a>.<br />
The source for the library (including Box2DFlashAS3 2.0.2) is <a title="FlexWorld library source" href="http://guyinthechair.com/wp-content/flex/flexWorld/source/FlexWorld.zip" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/?feed=rss2&amp;p=26</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
