<?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; library</title>
	<atom:link href="http://alecmce.com/category/library/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>Asynchronous Processes and RobotLegs</title>
		<link>http://alecmce.com/library/asynchronous-processes-and-robotlegs</link>
		<comments>http://alecmce.com/library/asynchronous-processes-and-robotlegs#comments</comments>
		<pubDate>Tue, 23 Aug 2011 20:15:05 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[library]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[robotlegs]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1192</guid>
		<description><![CDATA[Asynchronous processes are a common feature of ActionScript applications: we often need to initiate some asynchronous process, wait for a response and handle it. We have good language tools and design patterns for solving these sorts issues. RobotLegs is an MVCS framework that aims to decrease inter-dependency between different parts of code, so that code [...]]]></description>
			<content:encoded><![CDATA[<p>Asynchronous processes are a common feature of ActionScript applications: we often need to initiate some asynchronous process, wait for a response and handle it. We have good language tools and design patterns for solving these sorts issues.</p>
<p>RobotLegs is an MVCS framework that aims to decrease inter-dependency between different parts of code, so that code is more robust, and more reusable. It does this through a combination of dependency injection and the model-view-controller (+services) design pattern. The &#8216;controller&#8217; portion of RobotLegs&#8217; MVCS implementation is achieved by offering coders a simple way of implementing the Command pattern and binding commands to events that can be called from other areas of the code.</p>
<p>Problematically, commands are stateless and synchronous. They are not wired up to handle asynchronicity under-the-hood. &#8220;Async Commands&#8221; amend the Command structure to attempt to solve this problem, but they still contain architectural limitations that force us to restrict the way we code to the potential of the framework. Using Commands for asynchronous processes often require us to &#8216;double wire&#8217; between different application elements to solve the problem of passing data between classes.</p>
<p>What I am calling Processes are a redesign of the Async Command concept that seek to resolve these issues. They can be used in parallel with Commands to elegantly handle the problems of asynchronous code in RobotLegs.</p>
<h2>The Async Pattern</h2>
<p>The event model exists explicitly because we often need to wire up code to be triggered at an indeterminate future event. Fundamentally, client-side programming is about state and asynchronicity: events handle the asynchronicity. We handle them with this sort of pattern:</p>
<pre class="brush: as3; title: ; notranslate">
public function init():void
{
	var process:AsyncProcess = new MyAsyncProcess();
	process.addEventListener(AsyncProcessEvent.COMPLETE, onProcessComplete);
	process.init();
}

private function onProcessComplete(event:AsyncProcessEvent):void
{
	var processs:AsyncProcess = event.process;
	process.removeEventListener(AsyncProcessEvent.COMPLETE, onProcessComplete);

	parse(process.data);
}
</pre>
<p>Signals improves upon this structure by removing the necessity of event classes and offers some added features like automatically handling the removal of listener functions:</p>
<pre class="brush: as3; title: ; notranslate">
public function init():void
{
	var process:AsyncProcess = new MyAsyncProcess();
	process.completed.addOnce(onProcessComplete);
	process.init();
}

private function onProcessComplete(process:AsyncProcess):void
{
	parse(process.data);
}
</pre>
<p>This pattern is simple but powerful &#8211; create an object to tokenise or act-as-delegate-to the process, bind to some generic event/signal defined on the token, then initialise the process. I take the signal implementation to be a substantial improvement to the original. </p>
<h2>The Async Pattern across different objects</h2>
<p>A more complex case emerges if one class wants to launch a process in another class and retrieve data from its result. Ideally we want to keep the same three-step process.</p>
<pre class="brush: as3; title: ; notranslate">
class Model
{
	public var service:Service;

	public function init():void
	{
		service.completed.addOnce(onServiceComplete);
		service.init();
	}

	private function onServiceComplete(process:AsyncProcess):void
	{
		parse(process.data);
	}
}

interface Service
{
	function get completed:Signal;

	function init():void;
}
</pre>
<p>Unfortunately, this pattern is now insufficient, because it is possible for two different objects to trigger an asynchronous process from the same service at overlapping times (such that the second one is triggered before the first response).</p>
<pre class="brush: as3; title: ; notranslate">
class InitModelsCommand
{
	public var a:Model;
	public var b:Model;

	public function execute():void
	{
		a.init();
		b.init();
	}
}
</pre>
<p>In this scenario, if modelA and modelB both call init() in turn, then modelB will receive the data for modelA, then remove its listener before its own data is retrieved (assuming that modelA&#8217;s data is returned first, otherwise vice-versa).</p>
<p>This problem comes about because the service exposes a single Signal for multiple requests. There are two options to remedy this limitation:</p>
<pre class="brush: as3; title: ; notranslate">
// option A - the calling service tells the response where to go
interface Service
{
	function init(signal:Signal):void;
}

// option B - the service generates a response signal on a per-call basis
interface Service
{
	function init():Signal;
}
</pre>
<p>There&#8217;s not a lot between the two solutions, but I prefer Option B because it keeps together the repsonsibilities for creating and managing delegates to the asynchronous process in the same place as the process itself.</p>
<p>The pattern morphs to this:</p>
<pre class="brush: as3; title: ; notranslate">
class Model
{
	public var service:Service;

	public function init():void
	{
		service.init().addOnce(onServiceComplete);
	}

	private function onServiceComplete(process:AsyncProcess):void
	{
		parse(process.data);
	}
}

interface Service
{
	function init():Signal;
}
</pre>
<p>Here, be aware that if the signal responds within the init() method then it will not be routed to onServiceComplete. This can be handled by defining a signal that once dispatched, will dispatch immediately to any methods that are then added.</p>
<h2>Asynchronous Processes in RobotLegs</h2>
<p>The point of RobotLegs is to keep as few dependencies between different parts of code as possible. Ideally a model and a service shouldn&#8217;t reference each other, so RobotLegs best-practises would suggest you separate their interaction into a Command:</p>
<pre class="brush: as3; title: ; notranslate">
class InitModelCommand
{
	[Inject]
	public var model:Model;

	[Inject]
	public var service:Service;

	public function execute():void
	{
		service.completed.addOnce(onResponse);
		service.init();

		commandMap.detain(this) // if we don't do this for an async command everything could explode
	}

	private function onResponse(process:AsyncProcess):void
	{
		commandMap.release(this) // if we don't do this for an async command commands stay in memory

		model.parse(process.data);
	}
}
</pre>
<p>There several problems with this implementation. Imagine that this command is called as part of an initialisation routine, and once complete, another command should be called:</p>
<pre class="brush: as3; title: ; notranslate">
class Context
{
	public function onStartup():void
	{
		signalCommandMap.mapCommand(InitModel, InitModelCommand);
		signalCommandMap.mapCommand(InitView, InitViewCommand);
	}
}
</pre>
<p>How should InitViewCommand be called? The only place where the InitModelCommand is known to be complete is in its own onResponse command:</p>
<pre class="brush: as3; title: ; notranslate">
class InitModelCommand
{
	[Inject]
	public var initView:InitView;

	...

	private function onResponse(process:AsyncProcess):void
	{
		model.parse(process.data);
		initView.dispatch();
	}
}
</pre>
<p>This is unsatisfactory. Without this, the command is neatly encapsulated and simple to describe and understand. Once this code is added, the command takes on two responsibilities: firstly to initialise the model, and secondarily to kick-off the InitViewCommand.</p>
<p>The stateless command design pattern is ill-suited for asynchronous processes, and the attempt to use them leads to poor code design.</p>
<h2>An asynchronous process for RobotLegs</h2>
<p>The simple cases at the start of this article are instructive if we try to design a preferred architecture from the ground up. While retaining the power of RobotLegs to remove class dependencies, we want to find a way to use the simple asynchronous process pattern to wire up processes.</p>
<p>These design considerations have led me to what I&#8217;ve tentatively called the <a href="https://github.com/alecmce/robotlegs-async-processes-extension">robotlegs-async-process-extension</a>. It&#8217;s very early stages, and as usual I&#8217;m sharing the code more to get feedback than as a polished piece of work, but it functions to provide what I think is a superior alternative to Async Commands.</p>
<p>The structure is roughly like this:</p>
<pre class="brush: as3; title: ; notranslate">
class Context
{
	public function onStartup():void
	{
		// a delegate is a new concept...
		processMap.map(InitModelDelegate, InitModelProcess);
		processMap.map(InitViewDelegate, InitViewProcess);
	}
}

Class InitModelDelegate extends ProcessDelegate {}

Class InitViewDelegate extends ProcessDelegate {}

class InitProcess extends Process
{
	[Inject]
	public var initModel:InitModelDelegate;

	[Inject]
	public var initView:InitViewDelegate;

	public function execute():void
	{
		initModel.execute().addOnce(onModelInited);
	}

	private function onModelInited():void
	{
		initView.execute().addOnce(onViewInited);
	}

	private function onViewInited():void
	{
		complete();
	}
}
</pre>
<p>Note the features here:</p>
<ul>
<li>Like the SignalCommandMap extension, a different core structure, the <a href="https://github.com/alecmce/robotlegs-async-processes-extension/blob/master/src/gaia/lib/robotlegs/process/ProcessMap.as">ProcessMap</a> is defined that allows Processes to be defined in a way similar to Commands;</li>
<li>Rather than binding an event or signal to a Process, we bind a <a href="https://github.com/alecmce/robotlegs-async-processes-extension/blob/master/src/gaia/lib/robotlegs/process/ProcessDelegate.as">ProcessDelegate</a>. We need a little bit of extra functionality in the ProcessDelegate for the structure to work satisfactorily, but this is not functionally different from the SignalCommandMap extension;</li>
<li>When a delegate is executed, it passes back a signal that the calling object binds to in order to know when the process completes (it may also send back data through this callback);</li>
<li><a href="https://github.com/alecmce/robotlegs-async-processes-extension/blob/master/src/gaia/lib/robotlegs/process/Process.as">Processes</a> can&#8217;t be duck-typed, because they also need to inherit the functionality from their base class Process. Process exposes a complete() method that is called when the Process completes. If complete() is called inside execute(), then the Process becomes functionally equivalent to a Command.</li>
</ul>
<p>In fact, this is not quite the library as developed, because I have started using <a href="https://github.com/alecmce/gaia-tween/tree/master/src/gaia/lib/notice">Notices</a> rather than Signals, so I have ported this across to Signals since it has a much broader adoption. Notices are pared down, simple implementations of Signals that allow you to expose very simple interfaces like <a href="https://github.com/alecmce/gaia-tween/blob/master/src/gaia/lib/notice/SingularNotice.as">the SingularNotice interface</a>. It&#8217;s a preference thing; if anyone would like the original implementation with Notices, I&#8217;m happy to publish it.</p>
<p>I hope that this gives you some food for thought with respect to asynchronous processes. I&#8217;d love to know what you think about the idea, the implementation, the implied critique of RobotLegs. Let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/library/asynchronous-processes-and-robotlegs/feed</wfw:commentRss>
		<slash:comments>14</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>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>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_6" 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_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/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_8" 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>
		<item>
		<title>[Embed(source=&quot;asset.swf&quot;)] Gotcha (and Workaround)</title>
		<link>http://alecmce.com/as3/embed-asset-gotcha</link>
		<comments>http://alecmce.com/as3/embed-asset-gotcha#comments</comments>
		<pubDate>Fri, 21 May 2010 07:02:58 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=894</guid>
		<description><![CDATA[It&#8217;s been a long-time without a post. Part of the reason for that has been starting work at a new job (which involves a commute), and part has been that as part of my new job, I was actually encouraged to spend time playing World of Warcraft. To me, that&#8217;s like taking a crowbar to [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long-time without a post. Part of the reason for that has been starting work at a new job (which involves a commute), and part has been that as part of my new job, I was actually encouraged to spend time playing World of Warcraft. To me, that&#8217;s like taking a crowbar to Pandora&#8217;s Box and having a peek inside. I learned quite a lot, but have also played just a few too many Warsong Gulches.</p>
<p>Back to work, and I was doing a little prototyping this evening, when I came across a familiar problem: In <code>AS3</code> we can use</p>
<pre class="brush: as3; title: ; notranslate">
[Embed(source=&quot;asset.swf&quot;, symbol=&quot;symbol&quot;)]
private var symbolClass:Class;

var symbol:MovieClip = new symbolClass();
</pre>
<p>to embed a symbol from an art <code>SWF</code> in what is probably a code-built <code>SWF</code>. That&#8217;s great, but what if you want to embed an entire <code>SWF</code>?</p>
<pre class="brush: as3; title: ; notranslate">
[Embed(source=&quot;asset.swf&quot;)]
private var assetClass:Class;

var asset:MovieClip = new assetClass();
</pre>
<p>looks like it should do the trick, but you can&#8217;t access any of the information within the asset. That&#8217;s a real pain, the reason for which is pretty convoluted. I remembered working around this problem in the past, and happily managed to unearth a long-forgotten treasure in my codebase, which I thought I&#8217;d share (having rapidly refactored it to use as3-signals, naturally).</p>
<pre class="brush: as3; title: ; notranslate">
package com.alecmce.util
{
	import org.osflash.signals.Signal;

	import mx.core.MovieClipAsset;

	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.events.Event;

	public class UnpackEmbed
	{
		private var _ready:Signal;

		private var _asset:MovieClipAsset;
		private var _content:MovieClip;

		public function UnpackEmbed(assetClass:Class)
		{
			_asset = new assetClass();
			_ready = new Signal(UnpackEmbed);

			var loader:Loader = Loader(_asset.getChildAt(0));
			var info:LoaderInfo = loader.contentLoaderInfo;
			info.addEventListener(Event.COMPLETE, onLoadComplete);
		}

		private function onLoadComplete(event:Event):void
		{
			var info:LoaderInfo = LoaderInfo(event.target);
			info.removeEventListener(Event.COMPLETE, onLoadComplete);

			_content = MovieClip(info.loader.content);
			_ready.dispatch(this);
		}

		public function get content():MovieClip
		{
			return _content;
		}

		public function get ready():Signal
		{
			return _ready;
		}

		public function get asset():MovieClipAsset
		{
			return _asset;
		}
	}
}
</pre>
<p>When you embed a SWF in this way then instantiate it, Flash somehow conspires to create a <code>MovieClipAsset</code> with a <code>Loader</code> inside, which will be &#8216;loading&#8217; the already-embedded content. The content is not available immediately (it may be sometimes, I have encountered cases where it was not), so you have to wait for an <code>Event.COMPLETE</code> to be fired before you can access it. This class exposes a signal that informs you when the content is ready. It could probably be more rigorous, such as including an <code>isComplete</code> flag, but it serves my purposes, when used in the following manner:</p>
<pre class="brush: as3; title: ; notranslate">
[Embed(source=&quot;asset.swf&quot;)]
private var assetClass:Class;

asset = new UnpackEmbed(assetClass);
asset.ready.addOnce(onAssetReady);

private function onAssetReady(asset:UnpackEmbed):void
{
	// now we can access the asset.content!
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/embed-asset-gotcha/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>RobotLegsPong Part 1 &#8211; Overview</title>
		<link>http://alecmce.com/as3/robotlegspong1</link>
		<comments>http://alecmce.com/as3/robotlegspong1#comments</comments>
		<pubDate>Tue, 19 Jan 2010 07:01:23 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[as3signals]]></category>
		<category><![CDATA[asunit]]></category>
		<category><![CDATA[RobotLegs]]></category>
		<category><![CDATA[Ticker]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=649</guid>
		<description><![CDATA[Introduction RobotLegsPong attempts to combine RobotLegs application framework with the as3signals event model and a Frame-Ticker (as well as a pinch of ASUnit unit-testing) to create a &#8216;game&#8217;. It is an open-source project, available on GitHub as an example of using RobotLegs together with these other technologies. Source Code: github/alecmce/RobotLegsPong RobotLegsPong is not a very [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>RobotLegsPong attempts to combine RobotLegs application framework with the as3signals event model and a Frame-Ticker (as well as a pinch of ASUnit unit-testing) to create a &#8216;game&#8217;.</p>
<p>It is an open-source project, available on <a href="http://github.com/alecmce/RobotLegsPong/tree/master">GitHub</a> as an example of using RobotLegs together with these other technologies.</p>
<p style="text-align: center;">Source Code: <a href="http://github.com/alecmce/RobotLegsPong/tree/master">github/alecmce/RobotLegsPong</a></p>
<p>RobotLegsPong is not a very good <em>game</em>; it is playable only in the loosest sense. Bats require to be dragged in order to move (and there is no computer-logic to play against), so you could not really play against an opponent. The purpose of the exercise was to see what structure a game like Pong would take within the RobotLegs framework.</p>
<p>The purpose of this article is to describe the particulars of the technologies and why I chose them. In a follow-up article, I will look in more detail how RobotLegsPong is wired up.</p>
<h2>Why I Chose These Technologies</h2>
<h3>RobotLegs</h3>
<p>The RobotLegs framework is a lightweight, flexible application framework that allows coders to spend less time wiring up their application, and more time working on its functionality.</p>
<p>Frameworks are often criticised because they force developers to write code in a particular way, which might be inappropriate for a particular context. I have used Cairngorm, Pure MVC, as well as some proprietary frameworks, and have found that all of them do some things well, and do other things clumsily. So far I have not found this problem with RobotLegs, because most of the time it gets out of the way and lets you code; in fact, it does more than that: it reduces the amount of code you have to write.</p>
<h3>as3signals</h3>
<p>RobotLegs comes with an application event bus, but I have decided to circumvent that and use as3signals instead. as3signals allows you to define an object which acts as an event dispatcher within an application.</p>
<p>I like as3signals because describing an event as a Signal object allows my event model to be described through interfaces. as3signals is supposed to be fast too. Then again, interfaces are slow. The relative speeds of the approaches is interesting, but not a significant factor in my decision making process.</p>
<h3>Frame-Ticker</h3>
<p>The frame-ticker is a simple idea: rather than creating multiple enter-frame event listeners, each creating event objects, create one enter-frame listener and a main game loop iterating through those methods that need to be called per-iteration.</p>
<p>This implementation came out of a discussion on Twitter that I was involved in on the fringes; I wrote about it <a href="http://alecmce.com/as3/replacing-enter_frame">in a previous blog post</a>.</p>
<h3>ASUnit</h3>
<p>Unit testing enables developers to test portions of their code in isolation, so that they can be confident that every method works exactly as the developer intended. They also represent a secondary form of documentation-in-code; if you want to know how I meant a method to work, reading the unit test will tell you almost everything you need to know (including, if a good test is missing, what I <em>didn&#8217;t</em> consider).</p>
<p>That said, I have not unit tested every method; in this example I have only unit-tested the geometric logic for the bats. This is bad practice, however under time constraints I think that it is most important to unit test what is complex, mathematical or ambiguous, since this is where behaviour is most likely to fall down.</p>
<h2>[Inject]</h2>
<p>The &#8216;trick&#8217; to using RobotLegs is that you do not need to inject dependent objects into classes when you contruct them; this is done automatically. This code:</p>
<pre class="brush: as3; title: ; notranslate">
public class Dependee {}

public class MyExample
{
	public var dependee:Dependee;

	public function MyExample(dependee:Dependee)
	{
		this.dependee = dependee;
	}
}
</pre>
<p>becomes this code:</p>
<pre class="brush: as3; title: ; notranslate">
public class Dependee {}

public class MyExample
{
	[Inject]
	public var dependee:Dependee;
}
</pre>
<p>The metadata tag <code>[Inject]</code> has the effect of automatically injecting the dependee into the class when it is constructed. This isn&#8217;t much on the face of it, but it is enough. It feels to me as though a quarter of my code is actually just wiring up classes so that they each have access to the classes that they need to function, or passing objects around methods. The <code>[Inject]</code> tag lets me shift all of that wiring into the RobotLegs framework.</p>
<h2>Context</h2>
<p>There is a little more to the RobotLegs story however; how should RobotLegs react when it comes across an <code>[Inject]</code> tag? It could construct a new <code>Dependee</code> object, or it could be that I want only one <code>Dependee</code> object to be injected wherever the <code>[Inject]</code> tag is found. This is where the <code>Context</code> class becomes meaningful.</p>
<p>In the <a href="http://github.com/alecmce/RobotLegsPong/blob/master/src/app/PongContext.as">PongContext</a>, different classes are wired up in different ways. Their definitions are defined by adding <code>injector</code> mappings and the <code>mediatorMap</code> mappings in the <code>startup</code> method.</p>
<pre class="brush: as3; title: ; notranslate">
public class PongContext extends Context
{
	override public function startup():void
	{
		...
		injector.mapSingleton(DragMechanism);
		injector.mapSingletonOf(Geometry, GeometryModel);
		injector.mapClass(BatGeometry, BatGeometryModel);
		...
	}
}
</pre>
<h3>injector.mapSingleton</h3>
<pre class="brush: as3; title: ; notranslate">injector.mapSingleton(DragMechanism)</pre>
<p><code>mapSingleton</code> indicates that only one instance of the class entered should be constructed. In this case, just one <code>DragMechanism</code> will be created, and injected whenever this is found:</p>
<pre class="brush: as3; title: ; notranslate">
[Inject]
public var mechanism:DragMechanism;
</pre>
<h3>injector.mapSingletonOf</h3>
<pre class="brush: as3; title: ; notranslate">injector.mapSingletonOf(Geometry, GeometryModel);</pre>
<p><code>mapSingletonOf</code> extends the <code>mapSingleton</code> idea to interfaces and their implementing classes. In this case the <code>Geometry</code> interface is mapped to the <code>GeometryModel</code> class. The injection is called as follows:</p>
<pre class="brush: as3; title: ; notranslate">
[Inject]
public var model:Geometry;
</pre>
<p>No reference to the <code>GeometryModel</code> is needed in any class other than the <code>PongContext</code>. This allows a very pure use of interfaces across the application.</p>
<h3>injector.mapClass</h3>
<pre class="brush: as3; title: ; notranslate">injector.mapClass(BatGeometry, BatGeometryModel)</pre>
<p><code>injector.mapClass</code> works a little differently; whenever a <code>BatGeometry</code> interface is flagged to be injected, a new instance of <code>BatGeometryModel</code> is constructed and injected into the class, so the following code is used to create the injection:</p>
<p>Each <code>BatMediator</code> needs its own <code>BatGeometry</code> object. By using the <code>mapClass</code> method, multiple <code>BatGeometryModel</code> objects will be constructed, one for each time the following code is found:</p>
<pre class="brush: as3; title: ; notranslate">
[Inject]
public var model:BatGeometry;
</pre>
<h2>Mediators and Components</h2>
<pre class="brush: as3; title: ; notranslate">
public class PongContext extends Context
{
	override public function startup():void
	{
		...
		mediatorMap.mapView(Background, BackgroundMediator);

		addChild(new Background());
	}
}
</pre>
<p><code>mediatorMap</code> references a slightly different aspect of the application: your view objects. The <code>mediatorMap</code> allows users to define associations between display objects and <code>Mediator</code>s. These two parts comprise the <em>View</em> aspect of the standard MVC pattern.</p>
<p>The <code>DisplayObject</code> &#8211; in this case <code>Background</code> &#8211; is the asset that you want to be visible on the stage. In my pong example this is essentially just a Sprite, though it might just as well have been imported as a graphical asset in a SWC.</p>
<p>The <code>Mediator</code> is associated with the <code>DisplayObject</code> so that when an instance of the <code>DisplayObject</code> is created, the corresponding <code>Mediator</code> is also constructed. The <code>BackgroundMediator</code> looks something like this:</p>
<pre class="brush: as3; title: ; notranslate">
public class BackgroundMediator extends Mediator
{
	[Inject]
	public var view:Background;

	override public function onRegister():void
	{
		...
	}
}
</pre>
<p>The <code>DisplayObject</code> <code>Background</code> is injected into the <code>BackgroundMediator</code> when it is constructed. The <code>DisplayObject</code> can then be manipulated. It is an elegant solution that separates display object from UI logic.</p>
<pre class="brush: as3; title: ; notranslate">addChild(new Background());</pre>
<p>is all that is needed to wire the entire <code>DisplayObject</code>/<code>Mediator</code> combination.</p>
<h3>RobotLegs &#038; Tickers</h3>
<p>The RobotLegs structure is particularly useful for wiring up a <code>Ticker</code>-based application because one ticker can be mapped as a singleton, and injected to all those methods that need to iterate every frame:</p>
<pre class="brush: as3; title: ; notranslate">
public class PongContext extends Context
{
	override public function startup():void
	{
		...
		injector.mapSingletonOf(Ticker, EnterFrameTicker);
		...
	}
}
</pre>
<h3>RobotLegs with as3signals</h3>
<p>I really like the style of event dispatching that <code>as3signals</code> provides, but my implementation demands that if one class requires another class then it must flag it to be injected, and then the signal wired up in a method flagged as <code>[PostConstruct]</code> (see <a href="http://github.com/alecmce/RobotLegsPong/blob/master/src/app/model/GeometryModel.as">GeometryModel</a>). This doesn&#8217;t feel like the right solution.</p>
<p>Integrating <code>as3signals</code> with RobotLegs is beyond the scope of this article. It looks like Joel Hooks and Robert Penner are making inroads into this problem through <a href="http://groups.google.com/group/as3-signals/browse_thread/thread/fabc7995e9e55ec3#">as3signals&#8217; Google Group</a>. I look forward to seeing what they come up with.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/robotlegspong1/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

