<?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>alecmce.com &#187; as3</title>
	<atom:link href="http://alecmce.com/category/as3/feed" rel="self" type="application/rss+xml" />
	<link>http://alecmce.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 02:54:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>(Unfolding) Platonic Solids</title>
		<link>http://alecmce.com/uncategorized/unfolding-platonic-solids</link>
		<comments>http://alecmce.com/uncategorized/unfolding-platonic-solids#comments</comments>
		<pubDate>Sun, 11 Sep 2011 17:34:04 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1223</guid>
		<description><![CDATA[Before I was an ActionScript coder I was a mathematics teacher. It may have been a giveaway that coding was more my style than teaching when I made this, originally in AS2: (roll-over to activate) Later on I ported it to AS3 for a game that was never published. I made these: Then, I forgot [...]]]></description>
			<content:encoded><![CDATA[<p>Before I was an ActionScript coder I was a mathematics teacher. It may have been a giveaway that coding was more my style than teaching when I made this, originally in AS2: (roll-over to activate)</p>
<div style="text-align:center;">

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="400" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/09/UnfoldingDodecahedron4.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/09/UnfoldingDodecahedron4.swf" width="400" height="400">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

</div>
<p>Later on I ported it to AS3 for a game that was never published. I made these:</p>
<div style="text-align:center;">

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="400" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/09/AllJewels.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/09/AllJewels.swf" width="400" height="400">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

</div>
<p>Then, I forgot about it, for a long time, but I just came across it again! It&#8217;s actually my own 3D library, back in the days before I had heard of Papervision or Away3D, or any of the others. It draws the polygons using Graphics. That part is worthless.</p>
<p>However, I haven&#8217;t seen the dihedral angle structure that allows me to define the solid to open and close in other code. Perhaps this will be useful to someone. If you would like it, then you&#8217;re very welcome!</p>
<p>The code is here: <a href="http://bit.ly/reybnU">https://github.com/alecmce/ptolemy3D/tree/master/src</a>. The unfolding parts <a href="http://bit.ly/otraoa">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/uncategorized/unfolding-platonic-solids/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CommandFlow &#8211; Another Approach to (RobotLegs) Asynchronicity</title>
		<link>http://alecmce.com/as3/commandflow-another-approach-to-robotlegs-asynchronicity</link>
		<comments>http://alecmce.com/as3/commandflow-another-approach-to-robotlegs-asynchronicity#comments</comments>
		<pubDate>Sun, 11 Sep 2011 11:38:18 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[robotlegs]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1213</guid>
		<description><![CDATA[In this post I present another first draft of an extension for RobotLegs, my RobotLegs Flow Extension, which seeks to cope with problems surrounding asnychronicity in command-level code. In my last blog post, I argued that Robotlegs is poorly equipped to cope with asynchronous processes, and offered an extension to RobotLegs to seek to solve [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I present another first draft of an extension for RobotLegs, my <a href="http://bit.ly/qF9QqN">RobotLegs Flow Extension</a>, which seeks to cope with problems surrounding asnychronicity in command-level code.</p>
<p>In my last blog post, I argued that Robotlegs is poorly equipped to cope with asynchronous processes, and offered an extension to RobotLegs to seek to solve this problem, &quot;<a href="http://bit.ly/nEtgUZ">Async Processes Extension</a>&quot;. This extension follows in the footsteps of other interesting libraries, such as Shaun Smith&#8217;s <a href="https://github.com/darscan/robotlegs-extensions-Oil">Oil Extension</a> among many others.</p>
<h2>Reflecting about Processes</h2>
<p>Since I wrote that code and blog post, I have been reflecting on my approach. I have a few problems with it:</p>
<ul>
<li>RobotLegs is fundamentally lightweight. It is my framework of choice because it&#8217;s hardly a framework at all. The Processes extension adds a lot of conceptual overhead and does a lot of work under-the-hood.</li>
<li>It separates the concept of a process from the concept of a command, but it can often be the case that previously synchronous code can become asynchronous (for example: when moving from mocked data to live data), or the other way (for example: once data is  pre-loaded that was previously loaded just-in-time). Refactoring between commands and processes seems more trouble than it&#8217;s worth.</li>
<li>The under-the-hood part of the Process class means that it&#8217;s impossible to duck-type a Process. Duck-typing is good insofar as you know a framework that accepts duck-typable object has minimal dependencies.</li>
</ul>
<p>These criticisms of the library led me to think about a more lightweight approach.</p>
<h2>The Central Premise of Process</h2>
<p>The central premise of my critique of asynchronous code is that this sort of code is bad because the Command contains both its own logic and sequencing logic:</p>
<pre class="brush: as3; title: ; notranslate">
// pseudo-code!

class Context
{
	signalCommandMap.map(runSecond, SecondCommand);
	signalCommandMap.execute(FirstCommand);
}

class FirstCommand
{
	[Inject]
	public var runSecond:Signal;

	public function execute():void
	{
		process = new SomeProcess();
		process.run().addOnce(onComplete);
	}

	private function onComplete():void
	{
		runSecond.dispatch();
	}
}
</pre>
<p>It would be preferable to abstract the sequencing logic, so that the FirstCommand can just report that it has completed what it needs to do without having to know what&#8217;s next.</p>
<p>I have often found that you end up drawing diagrams for code written this way with each command in a box with arrows between them. I want a class that encapsulates that diagram, ensuring that the individual commands are truly agnostic with respect to their context in the application.</p>
<h2>A Different Approach</h2>
<p>If we abandon the notion of a Process, then how can we retain this separation? My second approach has been to abstract the sequencing logic into a class, called <a href="http://bit.ly/n46bVs">CommandFlow</a>. The intention is to use it like this:</p>
<pre class="brush: as3; title: ; notranslate">
// pseudo-code!

class Context
{
	injector.mapClass(ComamndFlow, CommandFlow);

	signalCommandMap.execute(InitCommand);
}

class InitCommand
{
	[Inject]
	public var flow:CommandFlow;

	public function execute():void
	{
		flow.push(FirstCommand);
		flow.push(SecondCommand);
		flow.next();
	}

}

class FirstCommand
{
	[Inject]
	public var flow:CommandFlow;

	public function execute():void
	{
		process = new SomeProcess();
		process.run().addOnce(onComplete);
	}

	private function onComplete():void
	{
		flow.next();
	}
}
</pre>
</p>
<p>The command sequencing is abstracted into InitCommand, so that FirstCommand doesn&#8217;t need to know anything more than that it is part of a sequence. CommandFlow is a helper that allows asnychronous command sequencing to take place with a minimum of impact on the classes&#8217; functionalities themselves.</p>
<p>Each CommandFlow injected into a command is a separate instantiation, so that if nested command logic is required, then it is possible. For example:</p>
<pre class="brush: as3; title: ; notranslate">
// pseudo-code!

class Context
{
	signalCommandMap.execute(InitCommand);
}

class InitCommand
{
	[Inject]
	public var flow:CommandFlow;

	public function execute():void
	{
		flow.push(FirstCommand);
		flow.push(LastCommand);
		flow.next();
	}
}

class FirstCommand
{
	[Inject]
	public var flow:CommandFlow;

	public function execute():void
	{
		flow.push(SecondCommand);
		flow.push(ThirdCommand);
	}
}
</pre>
<p>In this structure, FirstCommand will trigger SecondCommand and ThirdCommand before LastCommand is executed.</p>
<p>Payloads can be passed in explicitly through the push method, as CommandFlow exposes this method:</p>
<pre class="brush: as3; title: ; notranslate">
public function push(command:Class, ...args):Boolean;
</pre>
<p>A working demo of the code-in-action is provided in the github repository <a href="http://bit.ly/niwypL">here</a>.</p>
<h2>Notes</h2>
<p>At the moment it is not clear how to handle commands being pushed into a CommandFlow once the flow has been started with a next() call.</p>
<p>If the CommandFlow approach is to be useful, I will need to add branching into the CommandFlow class, and it could quickly become very difficult to maintain. Careful thought will be needed to cope with this.</p>
<p>After my previous post, <a href="http://www.creynders.be">Camille Reynders</a> made several good criticisms. One important one is how to handle failures. I think that this might be handled elegantly through branching, or possibly through some CommandFlow.error method that is a general &#8216;abandon-ship&#8217; method. I&#8217;m not sure yet how to implement this, since I&#8217;m not yet committed to using this sort of approach to solving asynchronicity problems.</p>
<p><a href="https://github.com/brianheylin">Brian Heylin</a> also pointed me towards some interesting resources that led me to adjust my Notices classes (my implementation of the Signals concept) to expose what I am calling a &#8216;<a href="http://bit.ly/r1z05O">Future</a>&#8216;; essentially a single-dispatch Signal/Notice, such that if you bind to it post-dispatch, the bound method is immediately called with the data that was originally dispatched.</p>
<h2>Last Thought</h2>
<p>I am keen to emphasise that these ideas are not complete; they need refining, tweaking and using. Perhaps I have gone down another blind-alley? Perhaps the Processes idea is better after-all? Or perhaps I&#8217;m misunderstanding something fundamental about how to wire-up applications with asynchronous functionality that you can enlighten me about?</p>
<p>A blog is for nothing if not shared learning. If you have any comments (positive or negative) then I would really appreciate hearing them!</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/commandflow-another-approach-to-robotlegs-asynchronicity/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>gaia-tween</title>
		<link>http://alecmce.com/animation/gaia-tween</link>
		<comments>http://alecmce.com/animation/gaia-tween#comments</comments>
		<pubDate>Sat, 23 Jul 2011 10:52:38 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[animation]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1141</guid>
		<description><![CDATA[Today I have pushed the first version of a new open-source tween library to github/alecmce/gaia-tween. I have been working on it for some time, to provide a robust, flexible, extensible alternative to the Greensock stable of tween libraries (TweenMax, TweenLite, etc.). I have several reasons for choosing not to use Greensock libraries for tweening: I [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have pushed the first version of a new open-source tween library to <a href="https://github.com/alecmce/gaia-tween">github/alecmce/gaia-tween</a>. I have been working on it for some time, to provide a robust, flexible, extensible alternative to the Greensock stable of tween libraries (TweenMax, TweenLite, etc.).</p>
<p>I have several reasons for choosing not to use Greensock libraries for tweening:</p>
<ul>
<li>I have great respect for TweenLite, but I have rarely used it in anger. Most of the time, the applications that I work on have some element of pay-to-play, and Greensock has <a href="http://www.greensock.com/licensing/">an unusual license</a> that has put-off at least two employers from using it. I do not want to learn a library that I can only use on some of my projects;</li>
<li>For all the clean code we try to write, Tweening libraries often jar with their funky APIs. I didn&#8217;t want my tweening library to be a statically-referenced black-box of almost unreadable code, I wanted it to have elements with well-defined responsibilities, objects that encapsulate concepts of time, tweens and eases. I wanted to be able to <acronym definition="Test Drive Development">TDD</acronym> these elements and offer my tests for public scrutiny. In short, I wanted my tweening library to feel more like the rest of my code and less like dark magic;</li>
<li>Probably most of all, I wanted to write it because I could, and because I hadn&#8217;t yet.</li>
</ul>
<h2>Speed and Memory</h2>
<div style="text-align: center; margin: auto;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="500" height="375">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/07/SpeedDemo1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/07/SpeedDemo1.swf" width="500" height="375">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="https://github.com/alecmce/gaia-tween/blob/master/demo/gaia/demo/tween/SpeedDemo.as">SpeedDemo.as source</a></div>
<p>In the tests that I have done so far, gaia-tween is fractionally behind TweenLite on speed. However, it is ahead in memory consumption! Currently the strategy for gaia-tween is to instantiate the elements that it needs and pool them indefinitely, so there is no garbage collection taking place, but I am looking to add that in as a future iteration. During tweening, no object is constructed nor destroyed by the tweening engine. Compare the memory profile of the two tween engines, from the SpeedDemo test below (<a href="https://github.com/alecmce/gaia-tween/blob/master/demo/gaia/demo/tween/SpeedDemo.as">SpeedDemo source here</a>):</p>
<h3>gaia-tween memory graph</h3>
<p><img src="http://alecmce.com/wp-content/uploads/2011/07/gaia-tween-memory.jpg" alt="" title="gaia-tween-memory" width="484" height="282" class="aligncenter size-full wp-image-1146" /></p>
<h3>TweenLite memory graph</h3>
<p><img src="http://alecmce.com/wp-content/uploads/2011/07/tweenlite-memory.jpg" alt="" title="tweenlite-memory" width="490" height="281" class="aligncenter size-full wp-image-1147" /></p>
<p>gaia-tween uses considerably less memory to run than TweenLite.</p>
<h2>Structure</h2>
<p>The API challenge was to find the right separation of responsibilities to keep the tween engine extensible without the extender having to do unnecessary work. The key features of this API are:</p>
<ul>
<li>Time is an independent concept from the tweening engine. A Time object is passed into the Tweening engine, which responds to changes in milliseconds-elapsed appropriately;</li>
<li>The ease functions have been simplified so that eases take one parameter &#8211; a proportion between 0 and 1, and return back a proportion between 0 and 1. This should make it easier for custom eases to be implemented;</li>
<li>The duration of a tween, the delay before starting it and any ease that may be applied to it are defined at the moment that a tween is added;</li>
<li>All other definition depends upon the context of the tween, and can be defined in a TweenForm. Currently three different kinds of TweenForms exist: a PropertyTweenForm for performing classic property tweens on objects; a ColorTweenForm for tweening the ColorTranform.color property of a DisplayObject; a MethodTweenForm for defining a method that will take the proportion between 0 and 1.</li>
</ul>
<p>This diagram may help explain the concepts more easily:</p>
<p><img src="http://alecmce.com/wp-content/uploads/2011/07/gaia-tween-explanation.jpg" alt="" title="gaia-tween-explanation" width="500" height="438" class="aligncenter size-full wp-image-1154" /></p>
<p>I have also added a convenience class that does the job of creating the TweenForms for you, <code><a href="https://github.com/alecmce/gaia-tween/blob/master/src/gaia/lib/tween/GaiaTweens.as">GaiaTweens.as</a></code>. This object-pools property tween forms and exposes a simplified API for those who want their tweening engine to keep everything under the hood.</p>
<h2>Examples</h2>
<p>The <code>ColorTweenForm</code> in action (roll-over to trigger):</p>
<div style="text-align: center; margin: auto;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_3" width="500" height="375">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/07/ColorDemo1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/07/ColorDemo1.swf" width="500" height="375">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="https://github.com/alecmce/gaia-tween/blob/master/demo/gaia/demo/tween/ColorDemo.as">ColorDemo.as source</a></div>
<p><br/></p>
<p>By passing in a different <code>Time</code> class, timeline animations are possible:</p>
<div style="text-align: center; margin: auto;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_4" width="500" height="375">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/07/TimelineDemo.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/07/TimelineDemo.swf" width="500" height="375">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="https://github.com/alecmce/gaia-tween/blob/master/demo/gaia/demo/tween/TimelineDemo.as">TimelineDemo.as source</a></div>
</p>
<p>Some issues with time-lining remain, and will be worked on for future improvements to the engine.</p>
<h2>Notices and Signals</h2>
<p>I am a huge proponent of the <a href="https://github.com/robertpenner/as3-signals/wiki">as3-signals</a> library. When <a href="http://robertpenner.com/">Robert Penner</a> originally introduced Signals, I was working on something similar with my friend <a href="http://blog.vizio360.co.uk/">Simone</a>. Since that time I have used Signals in almost every project I have worked on. However, One thing I really want to be able to do is to define a signal that only exposes an <code>addOnce</code> method. I have advocated this but there is clearly a disagreement about the direction that signals should take. So, I have created my own &#8211; simplified &#8211; implementation of signals. For want of a better name, I&#8217;ve called them <a href="https://github.com/alecmce/gaia-tween/tree/master/src/gaia/lib/notice"><code>Notices</code></a>. However, if you are interested in using or trying-out gaia-tween but are committed to using Signals, there is a <a href="https://github.com/alecmce/gaia-tween/tree/signals">signals branch</a> that replaces the Notices with Signals.</p>
<h2>Feedback</h2>
<p>I have produced this for my work at <a href="http://www.gaiaonline.com/">Gaia Interactive</a>, but Gaia have agreed to it being released because we would greatly appreciate feedback about it so that it can be improved. Please comment on API decisions, code implementations, feature requests, and so on. The more feedback I get, the more likely I can produce a robust, scalable alternative to the Greensock tweening stable. Or of course, you could fork the library and help improve it more directly!</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/animation/gaia-tween/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with Firefox</title>
		<link>http://alecmce.com/as3/working-with-firefox</link>
		<comments>http://alecmce.com/as3/working-with-firefox#comments</comments>
		<pubDate>Thu, 31 Mar 2011 23:31:04 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1108</guid>
		<description><![CDATA[Just a quickie, that you probably already know. I don&#8217;t think have I updated Firefox in a while, and suddenly when I did I was getting a lot of firefox Flash crashes when I was studying code on a breakpoint. It turns out that recent versions of Firefox run the Flash Player on a separate [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quickie, that you probably already know. I don&#8217;t think have I updated Firefox in a while, and suddenly when I did I was getting a lot of firefox Flash crashes when I was studying code on a breakpoint.</p>
<p>It turns out that recent versions of Firefox run the Flash Player on a separate process that has a timeout of 45 seconds. If the player hangs for that long then the Flash Player will be crashed. That&#8217;s fine for people consuming content, but for developers it is not acceptable.</p>
<p>The solution is to modify <code>about:config</code>, and to amend the value of <code>dom.ipc.plugins.timeoutSecs</code> to the number of seconds before a crash is triggered. You can choose -1 for never, or some sufficiently long period of time.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/working-with-firefox/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple List</title>
		<link>http://alecmce.com/as3/a-simple-list</link>
		<comments>http://alecmce.com/as3/a-simple-list#comments</comments>
		<pubDate>Sat, 22 Jan 2011 04:21:09 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1071</guid>
		<description><![CDATA[I have lost count of the number of times I&#8217;ve needed to create a UI list in the years since I started writing ActionScript. Most of the time, most of the lists that need to be created have very narrow, very simple requirements. If you ignore the visual design most lists require elements of the [...]]]></description>
			<content:encoded><![CDATA[<p>I have lost count of the number of times I&#8217;ve needed to create a UI list in the years since I started writing ActionScript. Most of the time, most of the lists that need to be created have very narrow, very simple requirements. If you ignore the visual design most lists require elements of the same size, uniformly positioned to be scrolled so that a subset of the list is visible within a given &#8216;viewing&#8217; area at any one time.</p>
<h2>The design FLA</h2>
<p>There are lots of different ways to approach putting a list together. For a bunch of different reasons I tend to work by loading SWFs that have no code into a code-base and then adding functionality by composition. In that way, artists can manipulate assets unencumbered by the code, and I can reuse code across an application with multiple swfs in a very easy-to-manage way.</p>
<p>To create my list then, I create an &#8216;item&#8217; MovieClip, and iterate it vertically or horizontally in a secondary &#8216;list&#8217; MovieClip. Then, to demarcate the visual limits of the list I apply a mask to it, like this:</p>
<p><img src="http://alecmce.com/wp-content/uploads/2011/01/structure.png" alt="" title="structure" width="530" height="400" class="aligncenter size-full wp-image-1078" /></p>
<p>Notice that there is at least one, but more often two &#8216;overflow&#8217; elements defined on the list; that is, list items that don&#8217;t actually show up initially. These are used later on when the list has to scroll.</p>
<h2>Compositing the FLA into VList</h2>
<p>When this swf is loaded into the application, the <a href="https://github.com/alecmce/SimpleList/blob/master/src/alecmce/list/VList.as">VList class</a> configures it very straightforwardly, creating a vector of ListItem objects that wrap each item MovieClip.</p>
<p>When this swf is loaded into the application, the <a href="https://github.com/alecmce/SimpleList/blob/master/src/alecmce/list/ListItem.as">ListItem</a> objects that wrap each list-item MovieClips.</p>
<p>In order to separate functionality from the scrolling mechanism (which could be scrolling arrows, a scrollbar, drag-fling functionality, or whatever else), the position of the list is defined by the <code>VList.position</code> property. When this property changes, the list updates its position by doing the following:</p>
<ul>
<li>The list container is moved upwards as the position increases;</li>
<li>As the top list items disappear out of the masked area, they are repositioned to the bottom and reassigned different data;</li>
</ul>
<p>In this way, no extra visual items need to be constructed or destructed, and as few objects are moved per change of position as possible. It is fast, clean and efficient.</p>
<h2>VList Code</h2>
<p>The <code>position</code> setter immediately repositions the container clip when a new position is asserted. (The first line merely checks for <code>isNaN(value)</code> in a more efficient way). Then, it checks whether the top-most element visible in the list is the same as it was before. If it is not, then <code>updateItems()</code> is called.</p>
<pre class="brush: as3; title: ; notranslate">
/**
 * baseY is the position that container.y has when _position is 0
 * dy is the distance between the same point on two adjacent ListItems
 * _index retains the integer value of the previous list position
 */
public function set position(value:Number):void
{
	_position = value != value ? 0 : value;
	container.y = baseY - _position * dy;

	var newIndex:int = _position | 0;
	if (_index == newIndex)
		return;

	_index = newIndex;
	updateItems();
}
</pre>
<p><code>updateItems()</code> then iterates through all the ListItems, positions them appropriately within the container clip and asserts data into each item</p>
<pre class="brush: as3; title: ; notranslate">
/**
 * items is a Vector of ListItem, one for each MovieClip list item
 * count is the number of ListItems in items
 * _data is the data that differentiates each item
 */
private function updateItems():void
{
	var i:int = count;
	while (i--)
	{
		var n:int = i + _index;
		var item:ListItem = items[n % count];

		item.mc.y = n * dy;
		item.datum = n &lt; dataLength ? _data[n] : null;
	}
}
</pre>
<p>ListItem will check whether it&#8217;s current datum is the same as the one entered, and if it is it will not update the visual component. If the datum does change, then ListItem passes it&#8217;s MovieClip into <code>ListDatum.apply(mc:MovieClip)</code> to be updated.</p>
<h2>Add A Scrollbar &#8211; Job Done</h2>
<p>And that&#8217;s it really. It needs a few trimmings of course, like a scrollbar or arrows to actually trigger the scrolling. In the example below a scrollbar class is added, and when the scrollbar changes it relays the position back to the list:</p>
<div style="margin: auto; 0px; text-align: center;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_5" width="400" height="600" align="center">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/01/Example.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/01/Example.swf" width="400" height="600" align="center">
      <!--<![endif]-->
        An example of the list that this article discusses
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
</div>
<p>This sturcture is fairly simple too, and can be found in the <a href="https://github.com/alecmce/SimpleList/blob/master/src/Example.as">Example class</a>.</p>
<pre class="brush: as3; title: ; notranslate">
	...

	list = new VList(content.list);

	scrollbar = new VScrollbar(content.knob, content.groove);
	scrollbar.reposition.add(onReposition);

	...

	list.data = data;
	scrollbar.setup(4, data.length);
	scrollbar.isVisible = data.length &gt; 4;
}

private function onReposition(value:Number):void
{
	list.position = value;
}
</pre>
<h2>Summary</h2>
<p>I am very satisfied with this implementation. It might need a tweak here or there, but it does it&#8217;s job very cleanly.  There are more complex cases where you have could have list data of different sizes, or you could have an absolutely enormous data set. Then, this list may not be appropriate, but for the 99% of cases where this is not the case, I think this serves its purpose well.</p>
<p>The complex problem facing most people making lists is choosing which control functionality to implement: drag-fling, scrollbars, little Apple dots, or arrows. Maybe you also want to add touches like bounce effects when you hit the limits of the list. All of these solutions can be developed separately from the core list class and coupled together in a way similar to my basic VScrollbar.</p>
<p>As ever, this code is available on <a href="https://github.com/alecmce/SimpleList">GitHub</a>. I would welcome any comments, improvements or suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/a-simple-list/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gotcha &#8211; BitmapData.draw(stage) and FullScreen Mode</title>
		<link>http://alecmce.com/as3/drawfullscreengotcha</link>
		<comments>http://alecmce.com/as3/drawfullscreengotcha#comments</comments>
		<pubDate>Thu, 14 Oct 2010 03:26:02 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[gotcha]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1038</guid>
		<description><![CDATA[When you set stage.displayState to StageDisplayState.FULL_SCREEN a display overlays your application: Where does it come from? Clearly it&#8217;s built into the Flash Player, but what may be surprising is that when it displays, it is actually added to the stage. It doesn&#8217;t float above the stage, it is added to the stage. This is no [...]]]></description>
			<content:encoded><![CDATA[<p>When you set <code>stage.displayState</code> to <code>StageDisplayState.FULL_SCREEN</code> a display overlays your application:</p>
<p><img src="http://alecmce.com/wp-content/uploads/2010/10/PressEscToExitFullScreenMode.png" alt="" title="PressEscToExitFullScreenMode" width="608" height="70" class="aligncenter size-full wp-image-1042" /></p>
<p>Where does it come from? Clearly it&#8217;s built into the Flash Player, but what may be surprising is that when it displays, it is actually added to the stage. It doesn&#8217;t float above the stage, it is added to the stage. This is no big deal&#8230; usually.</p>
<p>To consider when it might be a problem, try hitting the fullscreen button then hitting the draw button in the demo below. (Depending on the size of your screen, mouse skills will probably be required!)</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_6" width="640" height="480" align="center">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2010/10/Main6.swf" />
      <param name="align" value="center" />
      <param name="allowfullscreen" value="true" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2010/10/Main6.swf" width="640" height="480" align="center" allowfullscreen="true">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>One of the problems with adding the display to the stage is that it sits in a different security domain to your application. If your application attempts to reference the stage, for example to draw the stage into a <code>BitmapData</code>, then you get hit with a <code> Security sandbox violation</code>. Of course, if your mouse skills weren&#8217;t up to it and the element had removed itself from the stage, the error would not occur.</p>
<p>Now, there is probably no good reasons why you should ever need to take draw a copy of the stage, and in fact I found this error because I had (or maybe a colleague had?) done it when I wanted to draw a copy of a particular element. However, since screen-wipe transitions and other effects could easily be implemented in such a way (and since their implementation usually precedes implementing a fullscreen button), the potential for this error does exist.</p>
<p>It doesn&#8217;t look like anyone has noticed this error before. I searched for <code>https://www.macromedia.com/support/flashplayer/sys/</code> in JIRA and Google and didn&#8217;t find anything useful. I present it here in the hope that at least one other person won&#8217;t be skewered on this AS3 Gotcha like me!</p>
</p>
<p>ps. I took some liberties with the code as displayed in the demo above. For full disclosure, <a href="http://gist.github.com/625470">view the real source code on GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/drawfullscreengotcha/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Scribble</title>
		<link>http://alecmce.com/as3/scribble</link>
		<comments>http://alecmce.com/as3/scribble#comments</comments>
		<pubDate>Sun, 03 Oct 2010 20:58:38 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1022</guid>
		<description><![CDATA[I wanted to block out some area of the screen and noticed that when I do that on my pad, I scribble over the space to indicate that it is blocked out&#8230; So why not do that in projects too? Clearly this is a waste of time, but having done it, I thought I&#8217;d share [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to block out some area of the screen and noticed that when I do that on my pad, I scribble over the space to indicate that it is blocked out&#8230; So why not do that in projects too? Clearly this is a waste of time, but having done it, I thought I&#8217;d share it with you:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_7" width="640" height="480" align="center">
      <param name="movie" value="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/10/Main11.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/10/Main11.swf" width="640" height="480" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>If you would like the code, I have put the <a href="http://gist.github.com/608921">Scribble.as source code</a> up on GitHub as a gist. It won&#8217;t do you the whole demo, but it&#8217;ll give you the idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/scribble/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Invalidation Manager</title>
		<link>http://alecmce.com/as3/invalidation-manager</link>
		<comments>http://alecmce.com/as3/invalidation-manager#comments</comments>
		<pubDate>Thu, 12 Aug 2010 06:45:27 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=961</guid>
		<description><![CDATA[Introduction Invalidation is a pattern employed to solve problems where updating a model&#8217;s data may happen multiple times per frame, but updating the view&#8217;s rendering should happen only once. When dependencies exist between multiple models this can get complicated and potentially messy. This article looks at a solution to this mess by unifying invalidation logic [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Invalidation is a pattern employed to solve problems where updating a model&#8217;s data may happen multiple times per frame, but updating the view&#8217;s rendering should happen only once. When dependencies exist between multiple models this can get complicated and potentially messy. This article looks at a solution to this mess by unifying invalidation logic into a single manager class.</p>
<p>The purpose of this discussion is not to offer a new class for people to take and use in their libraries so much, though you are welcome, if you should want to. Rather it is to discus a problem and my solution. Hopefully some people will learn something from reading it, and hopefully I will learn something by getting feedback about it!</p>
<h2>The Invalidation Pattern</h2>
<p>Consider the following simple implementation for drawing a coloured circle:</p>
<pre class="brush: as3; title: ; notranslate">
public class Circle extends Sprite
{

	private var _color:uint;
	private var _radius:Number;

	public function get color():Number { return _color; }
	public function set color(value:Number):void
	{
		_color = value;
		resolve();
	}

	public function get radius():Number { return _radius; }
	public function set radius(value:Number):void
	{
		_radius = value;
		resolve();
	}

	private function resolve():void
	{
		graphics.clear();
		graphics.beginFill(_color);
		graphics.drawCircle(0, 0, _radius);
		graphics.endFill();
	}

}
</pre>
<p>The problem here is that if in one frame I changed both the radius and the color, the resolve() function would be called twice. Though not a problem in this case, it could be if the resolve() function involved a lot of complex logic.</p>
<p>The invalidation pattern resolves it this way:</p>
<pre class="brush: as3; title: ; notranslate">
public class Circle extends Sprite
{

	private var _color:uint;
	private var _radius:Number;

	public function get color():Number { return _color; }
	public function set color(value:Number):void
	{
		_color = value;
		invalidate();
	}

	public function get radius():Number { return _radius; }
	public function set radius(value:Number):void
	{
		_radius = value;
		invalidate();
	}

	public function invalidate():void
	{
		... at some future point of my choosing, trigger resolve() ...
	}

	public function resolve():void
	{
		graphics.clear();
		graphics.beginFill(_color);
		graphics.drawCircle(0, 0, _radius);
		graphics.endFill();
	}

}
</pre>
<p>Often in AS3, the invalidate() function looks like this:</p>
<pre class="brush: as3; title: ; notranslate">
public function invalidate():void
{
	addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

private function onEnterFrame(event:Event):void
{
	removeEventListener(Event.ENTER_FRAME, onEnterFrame);
	resolve();
}
</pre>
<p>It is a good pattern that solves the problem of multiple resolve() calls. The actual mechanism contained inside invalidate() which causes resolve() to be called once at a convenient point is unimportant. For this sort of structure, this simple implementation does the job.</p>
<h2>Where The Invalidation Pattern Becomes Complicated</h2>
<p>Imagine that you have two classes: a line, and a circle, the intersection of which defines two circular segments. In fact, don&#8217;t imagine: look at this:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_8" width="640" height="480">
      <param name="movie" value="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/CircleSegmentFromCircleAndLine11.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/CircleSegmentFromCircleAndLine11.swf" width="640" height="480">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>Both the line and circle implementations consist of two points which, on moving, invalidate the their equations. On resolve() the equations are resolved. The segments depend upon the the line and circle; when the line or circle is invalidated, they should be invalidated also.</p>
<p>A mechanism for the segments to know when their definiens (that which defines them) are resolved is required, suggesting that each element conforms to a common interface:</p>
<pre class="brush: as3; title: ; notranslate">
public interface Invalidates
{

	function invalidate():void;

	function get invalidated():Signal;

	function resolve():void;

}
</pre>
<p>and an implementation along these lines:</p>
<pre class="brush: as3; title: ; notranslate">
public class Line implements Invalidates
{

	private var _ax:Number;
	private var _ay:Number;
	private var _bx:Number;
	private var _by:Number;

	private var _invalidated:Signal;

	public function Line()
	{
		_invalidated = new Signal(Invalidates);
	}

	public function get ax():Number { return _ax; }
	public function set ax(value:Number):void
	{
		_ax = value;
		invalidate();
	}

	... missing a few uninteresting methods ...

	public function invalidate():void
	{
		_invalidated.dispatch(this);
	}

	public function resolve():void
	{
		... resolve the line ...
	}

}

public class Segment implements Invalidates
{
	private var _line:Line;
	private var _circle:Circle;

	... missing the constructor ...

	public function get line():Line { return _line; }
	public function set line(value:Line):void
	{
		_line = line;
		_line.invalidated.add(onInvalidated);
	}

	... missing a few uninteresting methods ...

	private function onInvalidated(definien:Invalidates):void
	{
		invalidate();
	}

	public function resolve():void
	{
		_line.resolve();
		_circle.resolve();

		... the rest of the resolution ...
	}
}
</pre>
<p>The problem here is the same problem that led us to consider the Invalidation Pattern in the first place: namely, that the Line&#8217;s resolve() method is going to get called a lot. Sure, we can pack the methods with lots if calls like:</p>
<pre class="brush: as3; title: ; notranslate">
private function invalidate():void
{
	if (_isInvalidated)
		return;

	_isInvalidated = true;
	invalidate();
}

public function resolve():void
{
	if (!_isInvalidated)
		return;

	_isInvaldiated = false;
	_line.resolve();
	_circle.resolve();

	... the rest of the resolution ...
}
</pre>
<p>However, it starts to feel like the classes are consumed with handling the invalidation management, rather than with what should be their single responsibility of properly modelling the geometrical entities for which they are named.</p>
<p>An important feature of this implemenation is that it guarantees that the Line&#8217;s and Circle&#8217;s resolve() methods are called before the sgement resolves. If B depends on A, then A must resolve before B resolves. This is a key feature of the Invalidation Manager, below.</p>
<h2>Managing Invalidation</h2>
<p>The current <a href="http://github.com/alecmce/as3geometry">as3geometry</a> library attempts to solve the problem of invalidation using the <a href="http://github.com/alecmce/as3geometry/blob/master/src/alecmce/invalidation/InvalidationManager.as">InvalidationManager.as</a> class.</p>
<p>The Invalidation Manager handles classes that satisfy the <a href="http://github.com/alecmce/as3geometry/blob/master/src/alecmce/invalidation/Invalidates.as">Invalidates.as</a> interface. Invalidates objects can be registered to the InvalidationManager, and dependencies can be established. As this happens, objects are categorized into <em>tiers</em>.</p>
<p>Initially, since every object is independent of each other when registered, newly registered elements are considered in tier 0. However, if a dependency is established such that B depends on A, B is put into the tier above A, so if A is in tier 0, B is in tier 1. If then C depends on B, since B is already in tier 1, C goes into tier 2.</p>
<p>The utility of the tiers comes from the fact that all objects in tier 0 are independent of each other and may be resolved in any order. Tiers are resolve in ascending order, ensuring that any object that is depended upon is resolved before any object which depends on it.</p>
<p>The problem with this approach comes when, for example, A depends on B depends on C already so they have the following tiers:</p>
<p><img src="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/diagram11.png" alt="" title="diagram1" width="236" height="84" class="aligncenter size-full wp-image-962" /></p>
<p>Then, if I have another object D already in tier 3, and define that B depends on D, I must move B to tier 4 and therefore also move C to tier 5.</p>
<p><img src="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/diagram21.png" alt="" title="diagram2" width="365" height="75" class="aligncenter size-full wp-image-963" /></p>
<p>Circularity presents an interesting problem within this system. If A depends on B depends on C, and then I define that C depends on A, the tier system breaks down. Currently attempting to create a circular reference will fail and an error will be thrown.</p>
<p>In order to keep the InvalidationManager clean, it does not actually handle when it resolves, but instead dispatches a signal when it has elements that require resolution. In the <a href="http://github.com/alecmce/as3geometry">as3geometry</a> implementation the <a href="http://github.com/alecmce/as3geometry/blob/master/src/as3geometry/AS3GeometryContext.as">AS3GeometryContext.as</a> wraps the InvalidationManager and hooks it to the player events to so that when invalidation occurs it is resolved in good time.</p>
<p>The Invalidates classes, other than telling the contxt what it has a relationship to and what it does not, no longer contains any code that tries to manage other objects&#8217; invalidations:</p>
<pre class="brush: as3; title: ; notranslate">
public class Line implements Invalidates
{

	private var _ax:Number;
	private var _ay:Number;
	private var _bx:Number;
	private var _by:Number;

	private var _context:InvalidationManagerContext;
	private var _invalidated:Signal;

	public function Line(context:InvalidationManagerContext)
	{
		_invalidated = new Signal(Invalidates);

		// elements that don't depend on other classes  like this don't really need the
		// context stored, but I store it here for consistency, and in case the structure
		// changes
		_context = context;
		context.register(this);
	}

	public function get ax():Number { return _ax; }
	public function set ax(value:Number):void
	{
		_ax = value;
		invalidate();
	}

	... missing a few uninteresting methods ...

	public function invalidate():void
	{
		_invalidated.dispatch(this);
	}

	public function resolve():void
	{
		... resolve the line ...
	}

}

public class Segment implements Invalidates
{
	private var _line:Line;
	private var _circle:Circle;

	private var _context:InvalidationManagerContext;
	private var _invalidated:Signal;

	public function Segment(context:InvalidationManagerContext)
	{
		_invalidated = new Signal(Invalidates);

		_context = context;
		_context.register(this);
	}

	public function get line():Line { return _line; }
	public function set line(value:Line):void
	{
		_line = line;
		_context.addDependency(_line, this);
	}

	... missing a few uninteresting methods ...

	private function onInvalidated(definien:Invalidates):void
	{
		invalidate();
	}

	public function resolve():void
	{
		... just resolve here! this is the big win ...
	}
}
</pre>
<h2>Conclusion</h2>
<p>A benefit to this approach is that Invalidates classes need very little boiler-plate code. The author of an Invalidates class need know only that changes should call invalidate() and that all resolution logic happens in resolve(). Responsibilities are extremely well separated.</p>
<p>The <a href="http://github.com/alecmce/as3geometry">as3geometry</a> implementation wraps the InvalidationManager into an <a href="http://github.com/alecmce/as3geometry/blob/master/src/as3geometry/AS3GeometryContext.as">AS3GeometryContext.as</a> class that has a little more logic than the InvalidationManager, which does not have a mechanism for actually triggering the mass resolution. While the InvalidationManager handles the internal logic set-out above, the AS3GeometryContext handles hooking up the InvalidationManager to the player events.</p>
<p>There is a downside, of course. Currently in <a href="http://github.com/alecmce/as3geometry">as3geometry</a>, the constructor of every class contains a reference to the AS3GeometryContext, and every class stores a reference to it. It is not clear to me that this approach is avoidable, unless the manager is defined as a singleton. <a href="http://www.google.com/search?sourceid=chrome&#038;ie=UTF-8&#038;q=why+are+singletons+bad%3F">There are lots of good reasons why singletons are bad</a>, not least because I might have good reason to have two parallel geometric contexts in one application.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/invalidation-manager/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Parabolas and Quadratic Bezier Curves</title>
		<link>http://alecmce.com/as3/parabolas-and-quadratic-bezier-curves</link>
		<comments>http://alecmce.com/as3/parabolas-and-quadratic-bezier-curves#comments</comments>
		<pubDate>Tue, 10 Aug 2010 15:00:34 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=923</guid>
		<description><![CDATA[As a follow-up to my as3geometry update on parabolas and quadratic bezier curves, I wanted to record the mathematics used to make the translation from parabola to quadratic bezier curve. Hoping to avoid the work of thinking about this for myself, I went online to understand the relationship, but could not find the calculation explained [...]]]></description>
			<content:encoded><![CDATA[<p>As a follow-up to my <a href="http://github.com/alecmce/as3geometry">as3geometry</a> update on parabolas and quadratic bezier curves, I wanted to record the mathematics used to make the translation from parabola to quadratic bezier curve. Hoping to avoid the work of thinking about this for myself, I went online to understand the relationship, but could not find the calculation explained anywhere. The answer presented itself once I started to draw this diagram in Illustrator. It is amazing how a well-drawn, careful diagram can give you the insights you need!</p>
<p><img src="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/parabola-quadratic_bezier11.png" alt="" title="Parabola &amp; Quadratic Bezier Curve" width="276" height="341" style="float: left; border: 0px; padding-top: 5px; padding-bottom: 5px; padding-right: 20px" /></p>
<p>The parabola is defined by the directrix AB and the focus C</p>
<p>It was apparent from the diagram that:</p>
<ul>
<li>H is the midpoint of the line segment AC;</li>
<li>AD is perpendicular to AB, and HD is perpendicular to AC, so D can be calculated as the intersection of these lines;</li>
<li>J is the midpoint of the line segment BC;</li>
<li>BE is perpendicular to AB and JE is perpendicular to BC, so E can be calculated as the intersection of these lines;</li>
<li>K is the intersection of the lines JE and HD, so E can be calculated as the intersection of these lines;</li>
<li>The parabolic segment defined by the line segment directrix AB and the focus C is also defined by a quadratic bezier curve with the start point D, the end point E and the control point K.</li>
</ul>
<p>The full calculation (with some different variable names I&#8217;m afraid!) was codified in the <a href="http://github.com/alecmce/as3geometry/blob/master/src/as3geometry/geom2D/ui/ParabolaDrawer.as">ParabolaDrawer.as</a> class.</p>
<p><br clear="all" /></p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/parabolas-and-quadratic-bezier-curves/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>as3geometry &#8211; Parabolas</title>
		<link>http://alecmce.com/as3/as3geometry-parabolas</link>
		<comments>http://alecmce.com/as3/as3geometry-parabolas#comments</comments>
		<pubDate>Mon, 09 Aug 2010 15:00:33 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=913</guid>
		<description><![CDATA[The as3geometry library has been neglected of late, but I have managed to push out a couple of important updates this week: the invalidation manager and parabola handling. I will discuss the invalidation manager later in the week since it is quite a technical and complex update. The implementation of parabolas is rather more straightforward. [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://github.com/alecmce/as3geometry">as3geometry</a> library has been neglected of late, but I have managed to push out a couple of important updates this week: the invalidation manager and parabola handling. I will discuss the invalidation manager later in the week since it is quite a technical and complex update. The implementation of parabolas is rather more straightforward.</p>
<p>Parabola defined by a line and vertex</p>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_9" width="640" height="480" align="center">
      <param name="movie" value="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/ParabolaFromLineAndVertex11.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/ParabolaFromLineAndVertex11.swf" width="640" height="480" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/ParabolaFromSegmentAndVertex.as">view source</a> | click-and-drag the red points to interact</div>
<p>Parabola segment defined by a line segment and vertex:</p>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_10" width="640" height="480" align="center">
      <param name="movie" value="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/ParabolaFromSegmentAndVertex11.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2010/08/ParabolaFromSegmentAndVertex11.swf" width="640" height="480" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/ParabolaFromLineAndVertex.as">view source</a> | click-and-drag the red points to interact</div>
<p>Usefully, a parabola (which, precisely, is &#8220;the locus of points equidistant from a point and a line&#8221;) can be expressed as a quadratic bezier curve. The implementation &#8216;simply&#8217; finds the three control points of a quadratic bezier curve and then uses the Flash Player&#8217;s Graphics.curveTo method to draw.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/as3geometry-parabolas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

