<?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>Eamonn Faherty &#187; actionscript3</title>
	<atom:link href="http://blog.eamonnfaherty.co.uk/tag/actionscript3/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.eamonnfaherty.co.uk</link>
	<description>technology enthusiast and public speaker</description>
	<lastBuildDate>Tue, 21 Jun 2011 10:14:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Signals</title>
		<link>http://blog.eamonnfaherty.co.uk/2011/06/13/signals/</link>
		<comments>http://blog.eamonnfaherty.co.uk/2011/06/13/signals/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 19:53:12 +0000</pubDate>
		<dc:creator>eamonn</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[signals]]></category>

		<guid isPermaLink="false">http://blog.eamonnfaherty.co.uk/?p=463</guid>
		<description><![CDATA[Anyone that knows me offline has probably heard me singing the praises of signals. I really like the stricter typing of signals compared to events.  For me, strict typing means that my code is checked by the compiler (instantly, at compile time) as apposed to being checked by the AVM (eventually, at runtime).  I have had countless times where I have seen code fail due to the event types declared in the handler method being wrong, even when the string values are stored as variables instead of using literals. The checking that event handlers are added correctly is not checkableRead more


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Anyone that knows me offline has probably heard me singing the praises of signals.</p>
<p>I really like the stricter typing of signals compared to events.  For me, strict typing means that my code is checked by the compiler (instantly, at compile time) as apposed to being checked by the AVM (eventually, at runtime).  I have had countless times where I have seen code fail due to the event types declared in the handler method being wrong, even when the string values are stored as variables instead of using literals. The checking that event handlers are added correctly is not checkable by the compiler.  This means we need to either blindly hope it all works out or rely on testing.</p>
<p>Signals (out of the box) fixes this issue but there is still another issue for me, the contract between an event (also a signal) and its handler.  With events there are two contracts, the event type (the Event.type String) and the event data.  Signals (out of the box) handles the event type issue by moving the name of the type into an interface as a signal, which is a great idea!  The data problem is harder to solve.</p>
<p>There are two checks that should be performed on the data.</p>
<p>The first is validation. At the moment this is limited to type checking.  When you set up a signal, you specify that the signal should be an int, String etc.  I think this is a great start but I think there should be more (optional) validation checks available; range checks for ints and regex checks for Strings.  When these validations fail then the signal should have a built in mechanism to throw an InvalidSignalError.  This would tighten up the robustness of projects using signals and would definitely reduce the amount of code I write.</p>
<p>The second check is verification. This is a lot harder to check but is a much more valuable check to perform. I think this is up to developers to check when developing. I am currently using signals to send messages between objects. I like to keep the implementation of my objects hidden from others so when writing a class I am always mindful of what values are available to other objects. So, when writing a signal I often find myself doing the following:</p>
<div class="syntaxhighlighter_container" ><pre class="brush: as3">
public class ShowScreenSignal extends Signal
{
private static const MENU:int = 0;
private static const PLAY:int = 1;
...
public function ShowScreenSignal()
{
super(int);
}
public function dispatchMenu():void
{
dispatch(MENU);
}
public function dispatchPlay():void
{
dispatch(PLAY);
}
...
public function isMenu(message:int):Boolean
{
return message = MENU;
}
public function isPlay(message:int):Boolean
{
return message = PLAY;
}
...
}
</pre></div>
<p>This means in my controller/mediator I call signal.dispatchPlay() and in my listener/command I check signal.isPlay(message) to check the message. This means nothing knows about the message values other than the signal. I can change the message to be a String without changing any of my controllers/mediators/command. This is better encapsulation. This works really well when using RobotLegs + Signals as you can subtype your command classes and have a condition in your execute method if (message.isPlay(message)).</p>
<p>This is solving one problem. I want to have one signal with many handlers based on the message. eg:</p>
<div class="syntaxhighlighter_container" ><pre class="brush: as3">
public class ShowPlayCommand extends SignalCommand
{
[Inject]
public var message:int;
[Inject]
public var signal:ShowScreenSignal;
override public function execute():void {
if (!signal.isPlay(message)) {
return;
}
//do something
}
}
</pre></div>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.eamonnfaherty.co.uk/2011/06/13/signals/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Actionscript3 Design Patterns:Creation Method</title>
		<link>http://blog.eamonnfaherty.co.uk/2009/11/11/actionscript3-design-patternscreation-method/</link>
		<comments>http://blog.eamonnfaherty.co.uk/2009/11/11/actionscript3-design-patternscreation-method/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 20:17:35 +0000</pubDate>
		<dc:creator>eamonn</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[creation method]]></category>
		<category><![CDATA[design patterns]]></category>

		<guid isPermaLink="false">http://blog.eamonnfaherty.co.uk/?p=242</guid>
		<description><![CDATA[Background Reading The factory method pattern The Problem? You have a complex object, which has a lot of arguments in its constructor or you always want to construct the object using different sets of parameters. Examples? Socket Manager How? The constructor of my complex object: public function ComplicatedButton(colour:uint, mouseOverColour:uint, mouseOutColour:uint) { _mouseOverColour = mouseOverColour; _mouseOutColour = mouseOutColour; setUpGraphics(colour); addEventListeners(); } The using of the creation method: var redButton : ComplicatedButton = ComplicatedButton.getRedButton(); var blueButton : ComplicatedButton = ComplicatedButton.getBlueButton(); Why is it good? ‚Ä¢ It is easy to understand; it is a simple pattern that needs little extra code. It buildsRead more


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><strong>Background Reading</strong><br />
The factory method pattern</p>
<p><strong>The Problem?</strong><br />
You have a complex object, which has a lot of arguments in its constructor or you always want to construct the object using different sets of parameters.</p>
<p><strong>Examples?</strong><br />
Socket Manager</p>
<p><strong>How?</strong><br />
The constructor of my complex object:</p>
<pre class=‚Äùbrush:as3‚Äù>
public function ComplicatedButton(colour:uint, mouseOverColour:uint, mouseOutColour:uint) {
	_mouseOverColour = mouseOverColour;
	_mouseOutColour = mouseOutColour;
	setUpGraphics(colour);
addEventListeners();
}
</pre>
<p>The using of the creation method:</p>
<pre class=‚Äùbrush:as3‚Äù>
var redButton : ComplicatedButton = ComplicatedButton.getRedButton();
var blueButton : ComplicatedButton = ComplicatedButton.getBlueButton();
</pre>
<p><strong>Why is it good?</strong><br />
‚Ä¢	It is easy to understand; it is a simple pattern that needs little extra code.  It builds on the singleton pattern, which is well known.<br />
‚Ä¢	Anyone using one of the creation methods to create the object is guaranteed to have an object in an identical state as the other users of the method.<br />
‚Ä¢	Objects that complicated or a lot of constructor parameters can be simplified.</p>
<p><strong>Why is it bad?</strong><br />
‚Ä¢	The class now has two responsibilities, the main purpose of the class plus the instantiation of its instances.<br />
‚Ä¢	The class can often grow in size as the creators in declared inside the class.  This makes the class harder to read for a developer.</p>
<p><strong>Further Reading</strong><br />
Read about the factory patterns. </p>
<p><strong>More</strong><br />
Creation methods are a great first move towards using factories.  Their concept is easy to grasp and doesn‚Äôt require much extra code.  The class can grow quite big, quite quickly but it is up to you to spot when the acceptable size has been passed for you to put your refactoring hat on.  I would use them when I have a graphical component that accepts integer colours as parameters or when I have components that need a lot of initial set up.  In the example above I have colours specified as integers.  To ensure that all of the buttons considered to be red or blue are the same shades of red or blue I protect users of my ComplicatedButton by adding creation methods with the colours hard coded.  Once I have more than one group of setups I would refactor, replacing the creation method with a factory method.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.eamonnfaherty.co.uk/2009/11/11/actionscript3-design-patternscreation-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionscript3 Design Patterns:The Singleton</title>
		<link>http://blog.eamonnfaherty.co.uk/2009/11/09/actionscript3-design-patternsthe-singleton/</link>
		<comments>http://blog.eamonnfaherty.co.uk/2009/11/09/actionscript3-design-patternsthe-singleton/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 00:25:33 +0000</pubDate>
		<dc:creator>eamonn</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://blog.eamonnfaherty.co.uk/?p=234</guid>
		<description><![CDATA[Background Reading None The Problem? You want to ensure you have only a single instance of an object and want global access to it. This may be because the object uses a resource, such as sounds, or because the object needs a lot of configuration, such as a currency formatter, or needs global access, an event dispatcher. Examples? Currency formatter, sound controller, global event dispatcher How? The Singleton: package singletonpattern { /** * @author eamonn faherty */ public class SocketManagerSingleton { private static var _instace : SocketManagerSingleton; public static function getInstace() : SocketManagerSingleton { ensureInstanceExists(); return _instace; } private staticRead more


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><strong>Background Reading</strong><br />
None</p>
<p><strong>The Problem?</strong><br />
You want to ensure you have only a single instance of an object and want global access to it.  This may be because the object uses a resource, such as sounds,  or because the object needs a lot of configuration, such as a currency formatter, or needs global access, an event dispatcher.</p>
<p><strong>Examples?</strong><br />
Currency formatter, sound controller, global event dispatcher</p>
<p><strong>How?</strong><br />
The Singleton:</p>
<pre class="brush:as3">package singletonpattern {

	/**
	 * @author eamonn faherty
	 */
	public class SocketManagerSingleton {
		private static var _instace : SocketManagerSingleton;

		public static function getInstace() : SocketManagerSingleton {
			ensureInstanceExists();
			return _instace;
		}

		private static function ensureInstanceExists() : void {
			if (_instace == null) {
				_instace = new SocketManagerSingleton();
			}
		}

		public function send(message : String) : void {
		}
	}
}</pre>
<p>Example Usage:</p>
<pre class="brush:as3">
package singletonpattern {
	import common.Example;		

	/**
	 * @author eamonn faherty
	 */
	public class SingletonPatternExample extends Example {

		public function SingletonPatternExample() {
			var socket : SocketManagerSingleton = SocketManagerSingleton.getInstace();

			socket.send("Hello world");
		}
	}
}</pre>
<p><strong>Why is it good?</strong><br />
‚Ä¢	It works well; if you use an instance protector then you can be sure that only a single instance will exist.<br />
‚Ä¢	It is well understood; it is widely used in the actionscript world.<br />
‚Ä¢	It is easy to understand; it is a simple pattern that needs little extra code.<br />
‚Ä¢	It is easy to implement; actionscript allows us to check the caller of a method and allows us to use private classes.</p>
<p><strong>Why is it bad?</strong><br />
‚Ä¢	It tightly couples the classes that use the singleton to the fact that they are using a singleton.<br />
‚Ä¢	It is not possible to extend the singleton class if you wanted to add functionality.<br />
‚Ä¢	You cannot use your singleton class again; you cannot extend it or reuse it with composition.<br />
‚Ä¢	If you are unit testing a class that uses a singleton you need to add some code to your singleton to make testing possible.</p>
<p><strong>Further Reading</strong><br />
Read about the factory and inversion of control patterns.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.eamonnfaherty.co.uk/2009/11/09/actionscript3-design-patternsthe-singleton/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

