<?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>Tweenpix &#187; tech</title>
	<atom:link href="http://blog.tweenpix.net/tag/tech/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tweenpix.net</link>
	<description>Behind the mask</description>
	<lastBuildDate>Wed, 02 Mar 2011 22:54:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>PixServer &#8211; AMF game server</title>
		<link>http://blog.tweenpix.net/2009/07/22/pixserver-amf-game-server/</link>
		<comments>http://blog.tweenpix.net/2009/07/22/pixserver-amf-game-server/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 16:57:16 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[amf]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[multi-users]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=1777</guid>
		<description><![CDATA[I&#8217;m back to the scene&#8230; with an empty hard drive. That&#8217;s THE bad news, I lost all my data one month ago. Around 10 years of storage without any backup. That really sucks. The good one is that it gives to me lot of punch to start from scratch 4 new projects. They&#8217;re all linked [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back to the scene&#8230; with an empty hard drive.<br />
That&#8217;s THE bad news, I lost all my data one month ago. Around 10 years of storage without any backup. That really sucks.<br />
The good one is that it gives to me lot of punch to start from scratch 4 new projects. They&#8217;re all linked together, but I&#8217;ll give you details later about the connection.</p>
<p>So let me introduce the first one.<br />
I needed a multi-users game server. So after some googling to browse OS projects, I decided to build a new one from scratch with <a href="http://mina.apache.org/">Apache Mina 2.0</a> using my R&#038;D xp.<br />
I choosed to install Ubuntu with Parallels to have an easy workflow with a local test workstation.</p>
<p>At this time, I&#8217;ve obtained something basic which works fine. That&#8217;s full AMF (using <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/">BlazeDS</a> ) and it manages users and rooms.<br />
That&#8217;s all based on simplicity. No events, no verbosed implementation or mess with abstract design&#8230;</p>
<p>My next step and goals:<br />
- Have something robust.<br />
- Build a graphical chat showcase with text to speech feature.<br />
- Build a game showcase with realtime synchronicity. I read a lot of resources about it, and I&#8217;m looking forward to work on this.</p>
<p>But I&#8217;m wondering about few things at this time:<br />
- Should I go to open source ?<br />
- Should I mix this implementation with <a href="http://projectdarkstar.com/">Darkstar project</a> ?<br />
- Should I work on a cheap product ?<br />
Any advice would be welcome !</p>
<div class="captionfull"><img src="http://blog.tweenpix.net/wp-content/themes/tma/images/latest/pixserver.jpg" alt="" />
</p>
</div>
<p>Here&#8217;s a basic echo demo to end this thread and showcase the concept:</p>
<pre lang="actionscript3">
import net.tweenpix.pixserver.amf.AMFClient;

	public class EchoAMFClient
	{
		protected var _client : AMFClient;

		public function EchoAMFClient()
		{
			_client = new AMFClient( );
			_client.registerClass( TestVO );
			_client.connect( "10.211.55.4", 9123 );

			_client.addEventListener( "EchoMessage",  onEchoMessage );
			_client.sendRequest( 	"EchoMessage",
								new TestVO( "francis", 38 ),
								new TestVO( "virginie", 35 ) );
		}

		public function onEchoMessage( vo1 : TestVO, vo2 : TestVO ) : void
		{
			// do something
		}
	}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2009/07/22/pixserver-amf-game-server/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Facebook &#8211; Flash Client Library</title>
		<link>http://blog.tweenpix.net/2009/01/11/facebook-flash-client-library/</link>
		<comments>http://blog.tweenpix.net/2009/01/11/facebook-flash-client-library/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 21:42:17 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=1107</guid>
		<description><![CDATA[Today, I spent few hours to play with Facebook Javascript client library. While I was playing with it, I started to build a little library to fit my needs for a game project. I built something compact, there&#8217;s only 2 classes at the moment (client class and its event class). Sobriety ! It uses a [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I spent few hours to play with Facebook Javascript client library. While I was playing with it, I started to build a little library to fit my needs for a game project.<br />
I built something compact, there&#8217;s only 2 classes at the moment (client class and its event class). Sobriety !<br />
It uses a JavaScript proxy like <a href="http://blog.tweenpix.net/2009/01/09/facebook-et-la-plateforme-flash/">FaceBookBridge library from ZeroFractal</a>, but the approach is a bit different. That&#8217;s a matter a lot of design and code perspective. I wanted simplicity and visibility, like remoting API.<br />
Let me show you !</p>
<div class="captionfull"><img src="http://blog.tweenpix.net/wp-content/themes/tma/images/latest/fbflashclientlib.jpg" alt="" />
</p>
</div>
<p>You have to make direct method calls on the client (as you would with JavaScript library). It returns a responder instance on each call:</p>
<pre lang="actionscript3">
var responder : EventDispatcher = client.Friends.get() as EventDispatcher;
</pre>
<p>To get some request results, you can suscribe listeners (as many as you want) to any responder:</p>
<pre lang="actionscript3">
responder.addEventListener(FacebookClientEvent.ON_RESULT, onFriends);
responder.addEventListener(FacebookClientEvent.ON_FAULT, onError);
</pre>
<p>And guess what, results are encapsulated in events passed as arguments to your callback methods:</p>
<pre lang="actionscript3">
public function onFriends( e : FacebookClientEvent ) : void
{
	trace ( e.methodName + " call: " + e.result.length );
}
</pre>
<p>Clean and easy as I like it.<br />
Last but not least, you got some errors reporting. I had hard time on this part, coz the JS implementation was acting weird. I&#8217;m not even sure at this time to have understood the whole error process. I must finalize this part, few errors aren&#8217;t caught at this time but every transaction is logged in firebug with Debug.dump JS calls.</p>
<pre lang="actionscript3">
public function onError( e : FacebookClientEvent = null ) : void
{
	trace ( "onGetInfoError(" + "method:" + e.methodName
				+ ", error_code:" + e.result.error_code
				+ ", error_msg:" + e.result.error_msg + ")" );
}
</pre>
<p>Here&#8217;s a short demo to end the teasing around this project.<br />
In this example, client retrieves all the name and profile photos urls of a user friends list through 2 API calls.</p>
<pre lang="actionscript3">
package
{
	import com.bourre.facebookflashapi.FacebookClient;
	import com.bourre.facebookflashapi.FacebookClientEvent;

	import flash.display.Sprite;
	import flash.events.EventDispatcher;

	public class FacebookClientTest
		extends Sprite
	{
		protected var client : FacebookClient;

		public function FacebookClientTest()
		{
			client = new FacebookClient();

			var responder : EventDispatcher = (client.Friends.get() as EventDispatcher);
			responder.addEventListener(FacebookClientEvent.ON_RESULT, onFriends);
			responder.addEventListener(FacebookClientEvent.ON_FAULT, onError);
		}

		public function onError( e : FacebookClientEvent = null ) : void
		{
			trace ( "onGetInfoError(" + "method:" + e.methodName
						+ ", error_code:" + e.result.error_code
						+ ", error_msg:" + e.result.error_msg + ")" );
		}

		public function onFriends( e : FacebookClientEvent ) : void
		{
			trace ( e.methodName + " call" );

			( client.users.getInfo( {uids:e.result, fields:["name", "pic_big"]} )
			as EventDispatcher).addEventListener(FacebookClientEvent.ON_RESULT, onGetInfo);
		}

		public function onGetInfo( e : FacebookClientEvent ) : void
		{
			for each ( var o : Object in e.result )
				trace ( "Nom:" + o.name + ", Image:" + o.pic_big );
		}
	}
}
</pre>
<p>I will release the source code under an open source licence when it&#8217;ll be a bit more polished for people who want to try it, and maybe I&#8217;ll make a video tutorial, who knows !</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2009/01/11/facebook-flash-client-library/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Tweensy, toujours plus vite !</title>
		<link>http://blog.tweenpix.net/2009/01/05/tweensy-toujours-plus-vite/</link>
		<comments>http://blog.tweenpix.net/2009/01/05/tweensy-toujours-plus-vite/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 14:39:23 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[tween]]></category>
		<category><![CDATA[tweensy]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=901</guid>
		<description><![CDATA[Ce billet pour signaler la release en beta publique de Tweensy, une nouvelle librairie d&#8217;animation qui compte bien tenir la dragée haute à Tweener, TweenLite, GTween et consorts. Comme la librairie de GreenSock, cette librairie est déclinée en 2 versions. D&#8217;un côté la version complète, de l&#8217;autre la version light pour les projets à haute [...]]]></description>
			<content:encoded><![CDATA[<p>Ce billet pour signaler la release en beta publique de <a href="http://code.google.com/p/tweensy/wiki/GettingStarted">Tweensy</a>, une nouvelle librairie d&#8217;animation qui compte bien tenir la dragée haute à <a href="http://code.google.com/p/tweener/">Tweener</a>, <a href="http://blog.greensock.com/tweenliteas3/">TweenLite</a>, <a href="http://www.gskinner.com/libraries/gtween/">GTween</a> et consorts.</p>
<p>Comme la librairie de <a href="http://blog.greensock.com">GreenSock</a>, cette librairie est déclinée en 2 versions. D&#8217;un côté la version complète, de l&#8217;autre la version light pour les projets à haute contrainte de poids comme les bannières publicitaires.</p>
<div class="captionleft"><img src="http://blog.tweenpix.net/wp-content/gallery/general/tweensy.jpg" alt="" />
</p>
</div>
<p><a href="http://www.lostinactionscript.com/blog/index.php/category/Work/">Shane McCartney</a> nous vante les prouesses de sa librairie en matière de performances avec <a href="http://www.flashdynamix.com/examples/Tweensy/0.2/SuperRenderTweenTest.html">preuve</a> à l&#8217;appui: <em>&laquo;&nbsp;J&#8217;ai réussi à rendre Tweensy plus rapide que l&#8217;ancien tenant du titre AS3: <a href="http://blog.greensock.com/tweenliteas3/">TweenLite</a>/<a href="http://blog.greensock.com/tweenmaxas3/">TweenMax</a>.</em>&nbsp;&raquo;</p>
<p>Il n&#8217;est pas en reste non plus concernant la puissance de l&#8217;API de son bébé: <em>&laquo;&nbsp;Mais ne pensez pas que Tweensy est juste un moteur de tween efficace de plus, il est aussi conçu pour rivaliser (dépasser à mon humble avis) n&#8217;importe quel moteur de tween AS3 existant. S&#8217;il manque quelque chose, n&#8217;hésitez pas à le demander.&nbsp;&raquo;</em></p>
<p>Concernant cette partie, j&#8217;avoue avoir été assez bluffé par l&#8217;étendue des possibilités disponibles. <a href="http://docs.flashdynamix.com/tweensy/fx/">La documentation</a> et certaines parties du <a href="http://code.google.com/p/tweensy/wiki/MotionGuides">wiki</a> permettent de se faire une idée du potentiel mis en oeuvre.</p>
<p>En résumé, une librairie à tester de toute urgence pour voir ce qu&#8217;elle a  dans le ventre en cas pratique !</p>
<p>Via <a href="http://www.lostinactionscript.com/blog/index.php/2009/01/05/tweensy-goes-public/">lostinactionscript.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2009/01/05/tweensy-toujours-plus-vite/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>old school fire effect</title>
		<link>http://blog.tweenpix.net/2009/01/04/old-school-fire-effect/</link>
		<comments>http://blog.tweenpix.net/2009/01/04/old-school-fire-effect/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 17:26:39 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[fire]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=857</guid>
		<description><![CDATA[After my last plasma experiments, I feel motivated to play again with pixels and old school demoscene effects. I continued to explore the same great C++ CG resource So, here&#8217;s another one effect that I&#8217;m glad to share. This is the old shool fire effect. No tricks deployed this time to optimize Flash rendering. That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>After my last <a href="http://blog.tweenpix.net/2008/12/16/smooth-plasma-experiment/">plasma experiments</a>, I feel motivated to play again with pixels and old school demoscene effects. I continued to explore the same great <a href="http://student.kuleuven.be/~m0216922/CG/fire.html">C++ CG resource</a><br />
So, here&#8217;s another one effect that I&#8217;m glad to share. This is the old shool fire effect.</p>
<p>No tricks deployed this time to optimize Flash rendering. That&#8217;s a standard implementation.</p>
<p>[kml_flashembed movie="http://www.tweenpix.net/files/fire.swf" width="450" height="175"/]<br />
</br></p>
<p>Here&#8217;s the source code. Enjoy !</p>
<pre lang="actionscript3">
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	[SWF( width="450", height="175", frameRate="25" , backgroundColor="0x000000")]
	public class Fire
		extends Sprite
	{
		protected const w : int = 450;
		protected const h : int = 175;

		protected var bd : BitmapData;
		protected var p : Point;
		protected var rect : Rectangle;
		protected var blur : BlurFilter;

		protected var palette : Vector.<int>;
		protected var fire : Array;

		public function Fire()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.quality = StageQuality.LOW;

			p = new Point(0, 0);
			rect = new Rectangle( 0, 0, w, h );
			blur = new BlurFilter( 4, 4, 1 );
			bd = new BitmapData( w, h, false, 0xFFFFFF );
			addChild( new Bitmap( bd ) );

			var x : int, y : int;
			palette = new Vector.<int>( 256, false );
			fire = [];
			for ( x = 0; x < w; x++ ) fire[x] = new Vector.<int>( h, false );
		    for ( x = 0; x < w; x++ )
		    	for ( y = 0; y < h; y++ )
					fire[x][y] = 256;
			for ( x = 0; x < 256; x++ )
				palette[x++] = HSLtoRGB( x/(3 * 256), 1, Math.min( 256, x * 2 )/256 );

			addEventListener( Event.ENTER_FRAME, enterFrame );
		}

		protected function enterFrame( e : Event ) : void
		{
			bd.lock();
			var x : int, y : int;
		    for ( x = 0; x < w; x++ ) fire[x][h - 1] = Math.random()*32768 % 256;
		    for ( y = 0; y < h - 1; y++ )
    			for ( x = 0; x < w; x++ )
			      fire[x][y] = ((fire[(x - 1 + w) % w][(y + 1) % h]
					+ fire[(x) % w][(y + 1) % h]
			        + fire[(x + 1) % w][(y + 1) % h]
			        + fire[(x) % w][(y + 2) % h]) * 32) / 129;
		    for ( x = 0; x < w; x++ )
			    for ( y = 0; y < h-1; y++ )
			    	bd.setPixel( x, y, palette[fire[x][y]]);
			bd.applyFilter( bd, bd.rect, p, blur );
			bd.unlock();
		}

		public static function HSLtoRGB( h :Number, s : Number , l : Number ) : Number
		{
		    var r : Number = 0, g : Number = 0, b : Number = 0, v1 : Number, v2 : Number;
		    if ( s == 0 )
		    {
		       r = l * 255;
		       g = l * 255;
		       b = l * 255;

		    } else
		    {
		       v2 = ( l < .5 ) ? l * ( 1 + s ) : ( l + s ) - ( s * l );
		       v1 = 2 * l - v2;
		       r = 255 * HueToRGB( v1, v2, h + ( 1 / 3 ) );
		       g = 255 * HueToRGB( v1, v2, h );
		       b = 255 * HueToRGB( v1, v2, h - ( 1 / 3 ) );
		    }
		    return ((r << 16)|(g << 8)|b);
		}

		private static function HueToRGB( v1 : Number, v2 : Number, vH : Number ) : Number
	    {
		    if ( vH < 0 ) vH += 1;
		    if ( vH > 1 ) vH -= 1;
		    if ( ( 6 * vH ) < 1 ) return ( v1 + ( v2 - v1 ) * 6 * vH );
		    if ( ( 2 * vH ) < 1 ) return ( v2 );
		    if ( ( 3 * vH ) < 2 ) return ( v1 + ( v2 - v1 ) * ( ( 2 / 3 ) - vH ) * 6 );
	    	return ( v1 );
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2009/01/04/old-school-fire-effect/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FlashSDL</title>
		<link>http://blog.tweenpix.net/2009/01/04/flashsdl/</link>
		<comments>http://blog.tweenpix.net/2009/01/04/flashsdl/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 22:01:58 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[alchemy]]></category>
		<category><![CDATA[flashsdl]]></category>
		<category><![CDATA[sdl]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=841</guid>
		<description><![CDATA[Petite brève pour signaler l&#8217;existence d&#8217;un projet qui devrait intéresser tous ceux qui se passionnent pour Alchemy. FlashDSL est un portage de SDL pour ActionScript 3.0 et plus spécifiquement Alchemy. Le son n&#8217;est pas supporté pour l&#8217;instant, l&#8217;affichage assez lent (on s&#8217;en serait douté, souvenez-vous des conclusions de ce billet), mais l&#8217;ensemble est fonctionnel. Merci [...]]]></description>
			<content:encoded><![CDATA[<p>Petite brève pour signaler l&#8217;existence d&#8217;un projet qui devrait intéresser tous ceux qui se passionnent pour <a href="http://labs.adobe.com/technologies/alchemy/">Alchemy</a>.<br />
<a href="http://github.com/emcmanus/flashsdl">FlashDSL</a> est un portage de <a href="http://fr.wikipedia.org/wiki/Simple_DirectMedia_Layer">SDL</a> pour ActionScript 3.0 et plus spécifiquement Alchemy. Le son n&#8217;est pas supporté pour l&#8217;instant, l&#8217;affichage assez lent (on s&#8217;en serait douté, souvenez-vous des conclusions de <a href="http://blog.tweenpix.net/2008/12/04/full-double-buffering-alchemist/">ce billet</a>), mais l&#8217;ensemble est fonctionnel.</p>
<p>Merci à Ed Mc Manus pour ce joli travail !<br />
Dommage que Scott Petersen n&#8217;ait jamais publié la version qu&#8217;il utilise dans ses différents portages (Quake, émulateur Nintendo&#8230;).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2009/01/04/flashsdl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>smooth plasma experiment</title>
		<link>http://blog.tweenpix.net/2008/12/16/smooth-plasma-experiment/</link>
		<comments>http://blog.tweenpix.net/2008/12/16/smooth-plasma-experiment/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 15:05:12 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[double-buffering]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[plasma]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=259</guid>
		<description><![CDATA[While playing with Alchemy, I focused a lot on C and C++ CG resources (like this great one). Like many coders, I&#8217;ve always been fascinated by old school demoscene effects. ^^ Inspiration finally came, and I had good time producing some little experiments to play with. Here&#8217;s one of them that I&#8217;m glad to share [...]]]></description>
			<content:encoded><![CDATA[<p>While playing with <a href="http://blog.tweenpix.net/2008/12/04/full-double-buffering-alchemist/">Alchemy</a>, I focused a lot on C and C++ CG resources (like this great <a href="http://student.kuleuven.be/~m0216922/CG">one</a>).<br />
Like many coders, I&#8217;ve always been fascinated by old school demoscene effects. ^^</p>
<p>Inspiration finally came, and I had good time producing some little experiments to play with.<br />
Here&#8217;s one of them that I&#8217;m glad to share with you.<br />
That&#8217;s two animated plasmas mixed together using same color palette. Color palette is splitted in 3 collections, one for red channel, another for green. Blue is unused. The last one is for handling pixels transparency.</p>
<p>[kml_flashembed movie="http://www.tweenpix.net/files/plasma.swf" width="400" height="400"/]<br />
</br><br />
Some optimizations tricks deployed to get display smoothness:<br />
- Plasmas are mixed together without blending. I&#8217;m drawing one pixel of each (with boolean checker) while generation.<br />
- I use ByteArray (as video ram like low-level languages do) with BitmapData.setPixels for rendering. I discover it&#8217;s faster to not compute each channel if you don&#8217;t need it.<br />
- As often, few as3 optimizations tips (Vector collections, int indexes, binary shifting for arithmetical operations, while loop without coordinates&#8230;)</p>
<p>Here&#8217;s the source code. Enjoy !</p>
<pre lang="actionscript3">
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.ByteArray;

	[SWF( width="400", height="400", frameRate="25" , backgroundColor="0x000000")]
	public class Plasma
		extends Sprite
	{
		protected const w : int = 400;
		protected const h : int = 400;

		protected var bd : BitmapData;
		protected var ba : ByteArray;
		protected var position : uint;
		protected var p : Point;
		protected var rect : Rectangle;
		protected var shifter : int;
		protected var blur : BlurFilter;

		protected const A : Vector.<int> = new Vector.<int>( 256, true );
		protected const R : Vector.<int> = new Vector.<int>( 256, true );
		protected const G : Vector.<int> = new Vector.<int>( 256, true );
		protected var plasma : Vector.<int>;

		public function Plasma()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.quality = StageQuality.LOW;

			ba = new ByteArray();
			p = new Point(0, 0);
			rect = new Rectangle( 0, 0, w, h );
			bd = new BitmapData( w, h, true, 0 );
			blur = new BlurFilter( 4, 4, 1 );
			addChild( new Bitmap( bd ) );

			// generate palette
			var i : int = 256;
			while( --i > - 1 )
    		{
    			A[i] = int(128 + 128 * Math.sin( 3.1415 * i / 32));
        		R[i] = int(128 + 128 * Math.sin( 3.1415 * i / 16));
        		G[i] = int(128 + 128 * Math.sin( 3.1415 * i / 64));
    		}

    		// generate plasma
    		var x : int, y : int, l : int = w*h, b : Boolean = true;
    		plasma = new Vector.<int>( l, false );

			while(  --l > - 1 )
			{
  				x = l % w;
				y = (l - x) / w;
				var color : Number;

				if ( b )
					color = (128+(128*Math.sin(x/128))+128
					+(128*Math.sin(y/128)))/2;
				else
					color = (128+(128*Math.sin(x/16))+128
					+(128*Math.sin(y/8))+128
					+(128*Math.sin((x+y)/16))+128
					+(128*Math.sin(Math.sqrt(x*x+y*y)/8)))/4;

        		plasma[l] = color;
        		b = !b;
    		}

			// init screen
			for( x = 0; x < w; x++ )
			{
				for( y = 0; y < h; y++ )
				{
					var pos : Number = (x+(y*w))*4;
					ba[pos] = 255;
					ba[pos+1] = 0;
					ba[pos+2] = 0;
					ba[pos+3] = 0;
				}
			}

			addEventListener( Event.ENTER_FRAME, enterFrame );
		}

		protected function enterFrame( e : Event ) : void
		{
			bd.lock();
			var t : int = ++shifter, pos : int = w*h, palID : int, ID : int;
			while ( --pos > - 1 )
			{
					palID = int((plasma[pos] + t) % 255);
					// to process ARGB channels, same as pos *= 4;
					ID = int(pos << 2);
					ba[ID]	= A[palID];
					ba[ID+1]= R[palID];
					ba[ID+2]= G[palID];
        	}
			ba.position = 0;
			bd.setPixels( rect, ba );
			bd.applyFilter( bd, bd.rect, p, blur );
			bd.unlock();
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2008/12/16/smooth-plasma-experiment/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>hello world en amfphp avec flex 2.0</title>
		<link>http://blog.tweenpix.net/2006/01/03/hello-world-en-amfphp-avec-flex-20/</link>
		<comments>http://blog.tweenpix.net/2006/01/03/hello-world-en-amfphp-avec-flex-20/#comments</comments>
		<pubDate>Tue, 03 Jan 2006 09:53:12 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=235</guid>
		<description><![CDATA[En complément du billet de Jesse Warden, voici un exemple synthétique de connexion AMFPHP en AS3. Un billet qui me permet d’inaugurer la sortie officielle d’AMFPHP 1.0 et saluer Patrick Mineault pour son dévouement. Pour ceux que ça intéresse, pixlib proposera en révision 23 un puissant configurateur d’application + une suppression totale des dépendances avec [...]]]></description>
			<content:encoded><![CDATA[<p>En complément du <a hreflang="fr" href="http://www.jessewarden.com/archives/2005/12/amfphp_10_works.html">billet</a> de Jesse Warden, voici un exemple synthétique de connexion AMFPHP en AS3.</p>
<p>Un billet qui me permet d’inaugurer la sortie officielle d’<a hreflang="fr" href="http://www.amfphp.org/">AMFPHP 1.0</a> et saluer <a hreflang="fr" href="http://www.5etdemi.com/blog/">Patrick Mineault</a> pour son dévouement.</p>
<p>Pour ceux que ça intéresse, pixlib proposera en révision 23 un puissant configurateur d’application + une suppression totale des dépendances avec le package <a hreflang="fr" href="http://www.luminicbox.com/blog/?page=post&amp;id=2">Luminic</a> et dans une prochaine révision, un package remoting autonome, c’est à dire sans aucune dépendance avec le package mx d’Adobe.</p>
<p>Je vous souhaite une bonne année à tous!</p>
<pre>package
<span style="color: #000000;">{</span>
	<span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">net</span>.<span style="color: #0000cc;">NetConnection</span>;
	<span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">net</span>.<span style="color: #0000cc;">ObjectEncoding</span>;

	<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">class</span> RemotingConnection <span style="color: #0000cc;">extends</span> <span style="color: #0000cc;">NetConnection</span>
	<span style="color: #000000;">{</span>
		<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> RemotingConnection<span style="color: #000000;">(</span> sURL:<span style="color: #0000cc;">String</span> <span style="color: #000000;">)</span>
		<span style="color: #000000;">{</span>
			objectEncoding = ObjectEncoding.<span style="color: #0000cc;">AMF0</span>;
			<span style="color: #0000cc;">if</span> <span style="color: #000000;">(</span>sURL<span style="color: #000000;">)</span> <span style="color: #0000cc;">connect</span><span style="color: #000000;">(</span> sURL <span style="color: #000000;">)</span>;
		<span style="color: #000000;">}</span>

		<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> AppendToGatewayUrl<span style="color: #000000;">(</span> s : <span style="color: #0000cc;">String</span> <span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
		<span style="color: #000000;">{</span>
			<span style="font-style: italic; color: #990000;">//</span>
		<span style="color: #000000;">}</span>
	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<pre>&lt;?<span style="color: #0000cc;">xml</span> <span style="color: #0000cc;">version</span>=<span style="color: #006600;">"1.0"</span> encoding=<span style="color: #006600;">"utf-8"</span>?&gt;

	&lt;mx:Application xmlns:mx=<span style="color: #006600;">"http://www.macromedia.com/2005/mxml"</span>
					xmlns=<span style="color: #006600;">"*"</span>
					creationComplete=<span style="color: #006600;">"initApplication()"</span>&gt;

	&lt;mx:Canvas <span style="color: #0000cc;">width</span>=<span style="color: #006600;">"100%"</span> <span style="color: #0000cc;">height</span>=<span style="color: #006600;">"100%"</span>&gt;
		&lt;mx:TextArea <span style="color: #0000cc;">width</span>=<span style="color: #006600;">"100%"</span> <span style="color: #0000cc;">height</span>=<span style="color: #006600;">"100%"</span> id=<span style="color: #006600;">"output"</span>/&gt;
	&lt;/mx:Canvas&gt;

	&lt;mx:Script&gt;
		&lt;!<span style="color: #000000;">[</span>CDATA<span style="color: #000000;">[</span>
			<span style="color: #0000cc;">import</span> flash.<span style="color: #0000cc;">net</span>.<span style="color: #0000cc;">Responder</span>;

			<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">var</span> gateway : RemotingConnection;

			<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> initApplication<span style="color: #000000;">(</span><span style="color: #000000;">)</span>
			<span style="color: #000000;">{</span>
				gateway = <span style="font-weight: bold; color: #0000cc;">new</span> RemotingConnection<span style="color: #000000;">(</span> <span style="color: #006600;">"http://localhost/flashservices/gateway.php"</span> <span style="color: #000000;">)</span>;
				gateway.<span style="color: #0000cc;">call</span><span style="color: #000000;">(</span> <span style="color: #006600;">"HelloWorld.say"</span>, <span style="font-weight: bold; color: #0000cc;">new</span> Responder<span style="color: #000000;">(</span>onResult, onFault<span style="color: #000000;">)</span>, <span style="color: #006600;">"hello world"</span><span style="color: #000000;">)</span>;
			<span style="color: #000000;">}</span>

			<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> onResult<span style="color: #000000;">(</span> result : <span style="color: #0000cc;">Object</span> <span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
			<span style="color: #000000;">{</span>
				output.<span style="color: #0000cc;">text</span> = result;
			<span style="color: #000000;">}</span>

			<span style="color: #0000cc;">public</span> <span style="font-weight: bold; color: #0000cc;">function</span> onFault<span style="color: #000000;">(</span> fault : <span style="color: #0000cc;">Object</span> <span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
			<span style="color: #000000;">{</span>
				output.<span style="color: #0000cc;">text</span> = fault;
			<span style="color: #000000;">}</span>
		<span style="color: #000000;">]</span><span style="color: #000000;">]</span>&gt;
	&lt;/mx:Script&gt;

&lt;/mx:Application&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2006/01/03/hello-world-en-amfphp-avec-flex-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Patterns #4 &#8211; Command Pattern</title>
		<link>http://blog.tweenpix.net/2004/08/15/command-pattern/</link>
		<comments>http://blog.tweenpix.net/2004/08/15/command-pattern/#comments</comments>
		<pubDate>Sun, 15 Aug 2004 17:20:45 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=306</guid>
		<description><![CDATA[Aujourd&#8217;hui nous allons aborder le command pattern. Ce modèle de conception est assez intuitif. Il s&#8217;agit d&#8217;encapsuler à l&#8217;intérieur d&#8217;un objet (plus communément appellé commande) le déroulement d&#8217;une action. A chaque fois que je voudrais exécuter cette action à l&#8217;intérieur d&#8217;une application, il me suffira d&#8217;appeller la méthode execute() de mon objet commande. Commençons par [...]]]></description>
			<content:encoded><![CDATA[<p>Aujourd&#8217;hui nous allons aborder le command pattern.</p>
<p>Ce modèle de conception est assez intuitif. Il s&#8217;agit d&#8217;encapsuler à l&#8217;intérieur d&#8217;un objet (plus communément appellé commande) le déroulement d&#8217;une action. A chaque fois que je voudrais exécuter cette action à l&#8217;intérieur d&#8217;une application, il me suffira d&#8217;appeller la méthode execute() de mon objet commande.</p>
<p>Commençons par un exemple basique :</p>
<pre><span style="color: #0000cc; font-weight: bold;">class</span> RebootCommand
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		<span style="color: #0000cc;">trace</span><span style="color: #000000;">(</span><span style="color: #006600;">"reboot my PC"</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<pre><span style="color: #0000cc;">import</span> RebootCommand;

<span style="color: #0000cc; font-weight: bold;">var</span> oReboot:RebootCommand = <span style="color: #0000cc; font-weight: bold;">new</span> RebootCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
oReboot.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</pre>
<p>La classe <em>RebootCommand</em> une fois instanciée me permet de rebooter mon ordinateur à chaque appel de sa méthode execute.</p>
<p>A partir de ce postulat, il devient évident que pour pouvoir être exécutée, une commande doit obligatoirement implémenter une méthode execute. Cette méthode contiendra les éléments nécéssaires au bon déroulement de l&#8217;action sollicitée.</p>
<p>Par conséquent, une commande devra obligatoirement implémenter l&#8217;interface suivante :</p>
<pre><span style="color: #0000cc;">interface</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>;
<span style="color: #000000;">}</span></pre>
<p>Reprenons maintenant le même exemple en utilisant l&#8217;interface ci-dessus :</p>
<pre><span style="color: #0000cc;">import</span> Command;

<span style="color: #0000cc; font-weight: bold;">class</span> RebootCommand <span style="color: #0000cc;">implements</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		<span style="color: #0000cc;">trace</span><span style="color: #000000;">(</span><span style="color: #006600;">"reboot my PC"</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<p>L&#8217;utilisation de l&#8217;interface Command : &#8211; Garantit que ma commande possède bien une méthode execute pour être déployée. &#8211; Permet (comme nous le verrons plus tard) de recourir au polymorphisme pour exécuter des commandes diverses sans se soucier de leur implémentation concrète.</p>
<p>Point essentiel et souvent controversé, la méthode execute ne renvoit rien mais <ins>SURTOUT</ins> n&#8217;autorise aucun paramètre. En effet, une commande, au moment de son exécution est censée déjà détenir les éléments nécessaires pour pouvoir interagir avec le système.</p>
<p>De prime abord, cela peut paraître un peu rigide et vous devez vous demander comment procéder pour spécifier des interactions avec le coeur de l&#8217;application ?</p>
<p>Il suffit tout simplement d&#8217;utiliser le constructeur de votre classe concrète pour pouvoir stocker les propriétés qui seront nécessaires au moment de l&#8217;exécution.</p>
<p>Prenons un deuxième exemple pour illustrer ceci :</p>
<pre><span style="color: #0000cc;">import</span> Command;

<span style="color: #0000cc; font-weight: bold;">class</span> DisplayDateCommand <span style="color: #0000cc;">implements</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">private</span> <span style="color: #0000cc; font-weight: bold;">var</span> _tViewHelper:<span style="color: #0000cc;">TextField</span>;

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> DisplayDateCommand<span style="color: #000000;">(</span>tViewHelper:<span style="color: #0000cc;">TextField</span><span style="color: #000000;">)</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper = tViewHelper;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper.<span style="color: #0000cc;">text</span> = <span style="color: #0000cc;">String</span><span style="color: #000000;">(</span><span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Date</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span>	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<p>Dans l&#8217;exemple ci-dessus on utilise un helper en paramètre dans le constructeur pour spécifier la cible graphique qui affichera la date du jour.</p>
<p>Il est biensûr possible d&#8217;ajouter des accesseurs dans votre classe concrète pour pouvoir modifier à tout moment les propriétés requises pour l&#8217;exécution de votre commande :</p>
<pre><span style="color: #0000cc;">import</span> Command;

<span style="color: #0000cc; font-weight: bold;">class</span> DisplayDateCommand <span style="color: #0000cc;">implements</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">private</span> <span style="color: #0000cc; font-weight: bold;">var</span> _tViewHelper:<span style="color: #0000cc;">TextField</span>;

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> DisplayDateCommand<span style="color: #000000;">(</span>tViewHelper:<span style="color: #0000cc;">TextField</span><span style="color: #000000;">)</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper = tViewHelper;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper.<span style="color: #0000cc;">text</span> = <span style="color: #0000cc;">String</span><span style="color: #000000;">(</span><span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Date</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> setViewHelper<span style="color: #000000;">(</span>tViewHelper:<span style="color: #0000cc;">TextField</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		_tViewHelper = tViewHelper;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<pre><span style="color: #0000cc;">import</span> DisplayDateCommand;

<span style="color: #0000cc;">this</span>.<span style="color: #0000cc;">createTextField</span><span style="color: #000000;">(</span><span style="color: #006600;">"__txt"</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">200</span>, <span style="color: #000000;">20</span><span style="color: #000000;">)</span>;
<span style="color: #0000cc; font-weight: bold;">var</span> ddc:DisplayDateCommand = <span style="color: #0000cc; font-weight: bold;">new</span> DisplayDateCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
ddc.<span style="color: #0000cc;">setViewHelper</span><span style="color: #000000;">(</span><span style="color: #0000cc;">this</span>.__txt<span style="color: #000000;">)</span>;
ddc.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</pre>
<p>Maintenant, passons à la question phare, celle que vous êtes tous en droit de vous poser : Quel est l&#8217;intérêt de ce modèle de conception ?</p>
<p>L&#8217;intérêt majeur, c&#8217;est de pouvoir découpler l&#8217;objet qui crée une requête pour une action donnée et l&#8217;action elle-même ou le receveur de celle-ci. L&#8217;exemple récurrent pour illustrer ce concept, c&#8217;est l&#8217;utilisation d&#8217;UIs (interfaces utilisateur) à l&#8217;interieur d&#8217;une application. Une interface utilisateur est censée ignorer l&#8217;implémentation et le déroulement des requêtes qu&#8217;elle formule. Autrement dit, le code des requêtes doit donc en aucun cas être exposé à celle-ci. On préférera l&#8217;encapsuler à l&#8217;intérieur de commandes, classes concrètes implémentant la classe abstraite Command (interface Command en AS2.0). Les UIs n&#8217;auront plus qu&#8217;à invoquer les commandes disponibles pour obtenir satisfaction à leurs requêtes.</p>
<pre><span style="color: #0000cc;">import</span> DisplayDateCommand;
<span style="color: #0000cc;">import</span> mx.<span style="color: #0000cc;">controls</span>.<span style="color: #0000cc;">Button</span>;

<span style="color: #0000cc;">this</span>.<span style="color: #0000cc;">createTextField</span><span style="color: #000000;">(</span><span style="color: #006600;">"__txt"</span>, <span style="color: #000000;">2</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">200</span>, <span style="color: #000000;">20</span><span style="color: #000000;">)</span>;
<span style="color: #0000cc; font-weight: bold;">var</span> tDisplay:<span style="color: #0000cc;">TextField</span> = <span style="color: #0000cc;">this</span>.__txt;

<span style="color: #0000cc; font-weight: bold;">var</span> oDdC:DisplayDateCommand = <span style="color: #0000cc; font-weight: bold;">new</span> DisplayDateCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
oDdC.<span style="color: #0000cc;">setViewHelper</span><span style="color: #000000;">(</span>tDisplay<span style="color: #000000;">)</span>;

<span style="color: #0000cc; font-weight: bold;">var</span> pbGetDate:<span style="color: #0000cc;">Button</span> = <span style="color: #0000cc;">this</span>.<span style="color: #0000cc;">createClassObject</span><span style="color: #000000;">(</span><span style="color: #0000cc;">Button</span>, <span style="color: #006600;">"__pbGetDate"</span>, <span style="color: #000000;">1</span><span style="color: #000000;">)</span>;
pbGetDate.<span style="color: #0000cc;">move</span><span style="color: #000000;">(</span><span style="color: #000000;">30</span>, <span style="color: #000000;">60</span><span style="color: #000000;">)</span>;
pbGetDate.<span style="color: #0000cc;">label</span> = <span style="color: #006600;">"Display"</span>;
pbGetDate.<span style="color: #0000cc;">addEventListener</span><span style="color: #000000;">(</span><span style="color: #006600;">"click"</span>, <span style="color: #0000cc;">this</span><span style="color: #000000;">)</span>;

<span style="color: #0000cc; font-weight: bold;">function</span> click<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
<span style="color: #000000;">{</span>
 	oDdC.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
<span style="color: #000000;">}</span></pre>
<p>Deuxième aspect non négligeable, c&#8217;est la possibilité d&#8217;atomiser les fonctionnalités d&#8217;une application en objets indépendants pour ne pas surcharger le contrôleur d&#8217;une application. On constatera par expérience que niveau design, il est toujours plus facile et élégant de changer par exemple l&#8217;implémentation d&#8217;une commande SeConnecter à l&#8217;intérieur d&#8217;une classe dédiée que de parcourir 2.000 lignes de code d&#8217;un contrôleur pour modifier celle-ci.</p>
<p>L&#8217;atomisation des fonctionnalités peut permettre aussi de créer des classes composites pour définir des macro-commandes (enchaînement de plusieurs commandes).</p>
<pre><span style="color: #0000cc;">import</span> Command;

<span style="color: #0000cc;">interface</span> MacroCommand <span style="color: #0000cc;">extends</span> Command
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> addCommand<span style="color: #000000;">(</span>oCommand:Command<span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>;
<span style="color: #000000;">}</span></pre>
<pre><span style="color: #0000cc;">import</span> MacroCommand;

<span style="color: #0000cc; font-weight: bold;">class</span> MyMacroCommand <span style="color: #0000cc;">implements</span> MacroCommand
<span style="color: #000000;">{</span>
 	<span style="color: #0000cc;">private</span> <span style="color: #0000cc; font-weight: bold;">var</span> _aCommands:<span style="color: #0000cc;">Array</span>;

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> MyMacroCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>
 	<span style="color: #000000;">{</span>
  		_aCommands = <span style="color: #0000cc; font-weight: bold;">new</span> <span style="color: #0000cc;">Array</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> addCommand<span style="color: #000000;">(</span>oCommand:Command<span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		_aCommands.<span style="color: #0000cc;">push</span><span style="color: #000000;">(</span>oCommand<span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>

 	<span style="color: #0000cc;">public</span> <span style="color: #0000cc; font-weight: bold;">function</span> execute<span style="color: #000000;">(</span><span style="color: #000000;">)</span> : <span style="color: #0000cc;">Void</span>
 	<span style="color: #000000;">{</span>
  		<span style="color: #0000cc; font-weight: bold;">var</span> l:<span style="color: #0000cc;">Number</span> = _aCommands.<span style="color: #0000cc;">length</span>;
  		<span style="color: #0000cc;">for</span> <span style="color: #000000;">(</span><span style="color: #0000cc; font-weight: bold;">var</span> i:<span style="color: #0000cc;">Number</span> = <span style="color: #000000;">0</span>; i&lt;l; i++<span style="color: #000000;">)</span> _aCommands<span style="color: #000000;">[</span>i<span style="color: #000000;">]</span>.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
  	<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<pre><span style="color: #0000cc;">import</span> MyMacroCommand;
<span style="color: #0000cc;">import</span> RebootCommand;
<span style="color: #0000cc;">import</span> DisplayDateCommand;

<span style="color: #0000cc;">this</span>.<span style="color: #0000cc;">createTextField</span><span style="color: #000000;">(</span><span style="color: #006600;">"__txt"</span>, <span style="color: #000000;">2</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">200</span>, <span style="color: #000000;">20</span><span style="color: #000000;">)</span>;

<span style="color: #0000cc; font-weight: bold;">var</span> oMMC:MyMacroCommand = <span style="color: #0000cc; font-weight: bold;">new</span> MyMacroCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
oMMC.<span style="color: #0000cc;">addCommand</span><span style="color: #000000;">(</span> <span style="color: #0000cc; font-weight: bold;">new</span> RebootCommand<span style="color: #000000;">(</span><span style="color: #000000;">)</span> <span style="color: #000000;">)</span>;
oMMC.<span style="color: #0000cc;">addCommand</span><span style="color: #000000;">(</span> <span style="color: #0000cc; font-weight: bold;">new</span> DisplayDateCommand<span style="color: #000000;">(</span><span style="color: #0000cc;">this</span>.__txt<span style="color: #000000;">)</span> <span style="color: #000000;">)</span>;

oMMC.<span style="color: #0000cc;">execute</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</pre>
<p><em>addCommand</em> utilise le polymorphisme d&#8217;interface que j&#8217;évoquais au début de cet article. Cette méthode attend en paramètre un objet de la famille Command, la nature exacte de celui-ci lui importe peu.</p>
<p>Le dernier aspect est le plus intéressant à mon goût. Il s&#8217;agit de déployer le command pattern à l&#8217;intérieur d&#8217;un front controller pour gagner en souplesse lors du développement et la maintenance d&#8217;une application.</p>
<p>Ceci sera le sujet du prochain volet. <img src='http://blog.tweenpix.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Voici pour finir une fiche technique résumant les caractéristiques du modèle <strong>Command</strong> :</p>
<p><strong>Nom</strong> : Command pattern<br />
<strong>Le problème</strong> :<br />
Découpler les objets qui invoquent une action de ceux qui l&#8217;exécutent.<br />
<strong>La solution</strong> :<br />
Créer une classe abstraite Command (interface) avec une méthode execute. Chaque commande (action) d&#8217;une application sera une classe concrète implémentant la méthode virtuelle execute. Les objets qui en feront la requête n&#8217;auront plus qu&#8217;à trigger celle-ci sans en connaître l&#8217;implémentation<br />
<strong>Les conséquences</strong> :<br />
- Le command pattern éradique tout couplage potentiel entre l&#8217;objet qui invoque une opération et celui qui sait comment la réaliser.<br />
- Une commande est un objet à part entière. Elle peut être manipulée, voire même étendue comme bon vous semble.<br />
- On peut créer des commandes composites (cf: MacroCommand).<br />
- Les commandes peuvent offrir la possibilité de faire et défaire (undo et niveaux d&#8217;undos).<br />
- Les commandes jugulées à un front-controller offrent à une application une souplesse et une capacité de maintenance indéniables.</p>
<p>Les fichiers sources sont disponibles <a hreflang="fr" href="http://www.tweenpix.net/files/commandpattern.rar">ici</a>.</p>
<p>Voilà, cet article touche à sa fin. J&#8217;ai tenté plus ou moins adroitement de vulgariser ce modèle de conception et de l&#8217;illustrer avec des exemples qui restent le plus simple possible afin que tout le monde puisse y trouve son compte. La suite bientôt, avec au programme quelques notions un peu plus avancées cette fois-ci : Création d&#8217;un <strong>Front Controller</strong> déployant le <strong>Command</strong> pattern avec <strong>ViewHelper</strong> à l&#8217;appui.</p>
<p>Il est possible qu&#8217;entre temps je vous fasse d&#8217;abord faire un petit détour par le modèle <strong>Observer</strong> et vous propose une manière qui me semple plus adéquate pour gérer les événements en AS 2.0 que celle proposée par EventDispatcher. (Avis 100% subjectif bien entendu) En effet, la force d<em>&#8216;EventDispatcher</em> c&#8217;est sa souplesse, mais c&#8217;est malheureusement aussi son talon d&#8217;achille. Je déplore son typage faible, son incapacité à scinder les écouteurs en plusieurs groupes (statique oblige) et l&#8217;impossibilité de savoir si pour un événement donné un ou plusieurs objets sont abonnés. Ce sera l&#8217;occasion pour moi de vous faire découvrir une autre façon de travailler avec les événements (plus rigide) et vous faire partager le package com.bourre.events de <a hreflang="fr" href="http://www.pixlib.org">pixLib</a> en avant-première.</p>
<p>En attendant n&#8217;hésitez pas à me faire partager vos éventuelles questions ou commentaires.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2004/08/15/command-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pixLib</title>
		<link>http://blog.tweenpix.net/2004/06/02/pixlib/</link>
		<comments>http://blog.tweenpix.net/2004/06/02/pixlib/#comments</comments>
		<pubDate>Wed, 02 Jun 2004 18:55:27 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[pixlib]]></category>
		<category><![CDATA[polymorphism]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=876</guid>
		<description><![CDATA[Me voici de retour dans mon home sweet home après un voyage éclair sur Paris. J&#8217;en profite pour vous présenter un petit aperçu de mes derniers travaux. Je code depuis deux semaines une nouvelle librairie dont l&#8217;objectif final sera de faciliter la programmation des jeux en Flash. Nom de code : pixLib Mon premier challenge [...]]]></description>
			<content:encoded><![CDATA[<p>Me voici de retour dans mon home sweet home après un voyage éclair sur Paris.<br />
J&#8217;en profite pour vous présenter un petit aperçu de mes derniers travaux.</p>
<p>Je code depuis deux semaines une nouvelle librairie dont l&#8217;objectif final sera de faciliter la programmation des jeux en Flash.<br />
Nom de code : pixLib</p>
<p>Mon premier challenge fut de réaliser un tiles engine abstrait qui puisse être injecté dans le code principal de n&#8217;importe quel view d&#8217;un jeu afin obtenir un affichage 2D, isométrique, pseudo 3d &#8230;<br />
Ce week-end, j&#8217;ai pris une journée pour développer quelques exemples basiques illustrant l&#8217;utilisation du premier set de classes disponible.</p>
<p>Une classe abstraite VisualGrid sert de fondation pour les différentes représentations graphiques. Elle permet grâce à la magie du polymorphisme d&#8217;interchanger à tout moment l&#8217;univers visuel d&#8217;un jeu et ce sans changer une ligne de code de celui-ci.</p>
<pre lang="actionscript">
// exemple avec view 2d

import com.bourre.tests.tetris.Tetris;
import com.bourre.visual.Visual2DGrid;

var game:Tetris = new Tetris();
game.main(new Visual2DGrid(this, 1, 12, 21, 32, 32, 100, 10));
</pre>
<pre lang="actionscript">
// exemple avec view iso

import com.bourre.tests.tetris.Tetris;
import com.bourre.visual.VisualIsoGrid;

var game:Tetris = new Tetris();
game.main(new VisualIsoGrid(this, 1, 12, 21, 28.5, 14.25, 625, 120));
</pre>
<p>Pour les ébauches en image, ça se passe <a href="http://www.tweenpix.net/pixlib/snake2d.htm">ici</a>, <a href="http://www.tweenpix.net/pixlib/snakeiso.htm">ici</a>, <a href="http://www.tweenpix.net/pixlib/tetris2d.htm">ici</a> et <a href="http://www.tweenpix.net/pixlib/tetrisiso.htm">ici</a>.<br />
On sera indulgent sur les graphismes, ceci n&#8217;étant pas mon domaine de prédilection. ^^</p>
<p>Prochaine étape, créer un moteur d&#8217;animations. En effet, le tiles engine est pour l&#8217;instant statique.</p>
<p>A suivre donc !</p>
<p>ps : Merci à rosyflower pour le sweety logo ! <img src='http://blog.tweenpix.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2004/06/02/pixlib/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Design Patterns #3 &#8211; Abstract Factory</title>
		<link>http://blog.tweenpix.net/2004/04/20/design-patterns-3-abstract-factory/</link>
		<comments>http://blog.tweenpix.net/2004/04/20/design-patterns-3-abstract-factory/#comments</comments>
		<pubDate>Tue, 20 Apr 2004 18:47:24 +0000</pubDate>
		<dc:creator>Francis Bourre</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[abstract factory]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[design pattern]]></category>

		<guid isPermaLink="false">http://blog.tweenpix.net/?p=649</guid>
		<description><![CDATA[La dernière fois, nous avons abordé les classe abstraites et je vous ai proposé une implémentation possible en AS 2.0 pour contourner l’absence du mot-clef abstract. Petit rappel de rigueur, créer une classe abstraite, c’est définir une classe mère non instantiable qui décrit les comportements génériques de classes plus spécialisées, les classes concrètes. Aujourd’hui, nous [...]]]></description>
			<content:encoded><![CDATA[<p>La dernière fois, nous avons abordé les classe abstraites et je vous ai<br />
proposé une implémentation possible en AS 2.0 pour contourner l’absence<br />
du mot-clef <em>abstract</em>.</p>
<p>Petit rappel de rigueur, créer une classe abstraite, c’est définir<br />
une classe mère non instantiable qui décrit les comportements<br />
génériques de classes plus spécialisées, les classes concrètes.</p>
<p>Aujourd’hui, nous allons étudier le modèle fabrique abstraite, en<br />
nous servant des notions acquises lors des deux précédents<br />
volets&nbsp;: <a href="http://tweenpix.net/blog/?p=122" hreflang="fr">Singleton</a> et <a href="http://tweenpix.net/blog/?p=131" hreflang="fr">abstract</a>.</p>
<p>Entrons tout de suite dans le vif du sujet !</p>
<p>L’intérêt de la fabrique abstraite, c’est de proposer une interface<br />
pour créer des familles d’objet sans avoir à manipuler directement<br />
leurs classes concrètes.</p>
<p>Quand dois-je avoir recours à ce pattern&nbsp;? Quand je veux<br />
pouvoir utiliser une famille d’objets et pouvoir la substituer à tout<br />
moment par une autre à l’intérieur de mon application.</p>
<p>Mais qu’est-ce qu’une fabrique&nbsp;? Une fabrique, c’est une classe<br />
permettant de créer des instances d’une classe ou d’un set de classes.<br />
Son rôle est d’encapsuler la création des dites instances et de servir<br />
(le plus souvent) de référence globale pour la création de celles-ci en<br />
deployant le pattern Singleton.</p>
<p>Pour illustrer ce concept, j’ai repris l’exemple cliché souvent<br />
associé à ce pattern, créer deux famille de widgets et offrir à tout<br />
moment la possibilité de remplacer l’une par l’autre. Mais rien ne vous<br />
interdit de l’appliquer à des domaines totalement différents. Quelques<br />
exemples divers&nbsp;: &#8211; Génération des éléments d’un jeu avec des<br />
familles d’objets classées par niveaux de difficulté ou par univers. -<br />
Création d’un environnement skinnable. &#8211; Réalisation d’un framework<br />
modulable avec des familles d’objets liées à certaines utilisations<br />
spécifiques. …</p>
<p>Le principe fondamental, c’est de créer une classe abstraite listant<br />
les méthodes communes à chaque fabrique. Ces méthodes une fois<br />
implémentées dans les fabriques concrètes (fabrique de chaque famille)<br />
permettront d’instancier chaque type d’objet spécifique.</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// UIsFactory.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactory</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> createScrollBar:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> createContainer:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> createMenuBox:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> UIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// UIsFactoryMethods.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">interface</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactoryMethods</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : ScrollBar;
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : Container;
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : MenuBox;

<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>Les objets sont donc pour l’instant abstraits eux aussi. Ceci nous<br />
permettra plus tard de spécialiser chacun d’eux en corrélation avec la<br />
famille à laquelle ils appartiennent.</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ScrollBar.as</span>

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> <span style="color: rgb(0, 0, 204);">scroll</span>:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ScrollBarMethods.as</span>

<span style="color: rgb(0, 0, 204);">interface</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBarMethods</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">scroll</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>;

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// Container.as</span>

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> empty:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> Container<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ContainerMethods.as</span>

<span style="color: rgb(0, 0, 204);">interface</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ContainerMethods</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> empty<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>;

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// MenuBox.as</span>

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> display:<span style="font-weight: bold; color: rgb(0, 0, 204);">Function</span>;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> MenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// MenuBoxMethods.as</span>

<span style="color: rgb(0, 0, 204);">interface</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBoxMethods</span>
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> display<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>;

<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>Je peux donc maintenant créer mes deux familles, Rebound et Water,<br />
avec pour chacune d’elle, une fabrique concrète me permettant<br />
d’instancier mes widgets.</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ReboundUIsFactory.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactory</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactoryMethods</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticContainer</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticMenuBox</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">ReboundUIsFactory</span> <span style="color: rgb(0, 0, 204);">extends</span> UIsFactory <span style="color: rgb(0, 0, 204);">implements</span> UIsFactoryMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="color: rgb(0, 0, 204);">static</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oInstance = <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ReboundUIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ReboundUIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="color: rgb(0, 0, 204);">static</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> getInstance<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : ReboundUIsFactory <span style="color: rgb(0, 0, 0);">{</span> <span style="color: rgb(0, 0, 204);">return</span> _oInstance; <span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : ScrollBar
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ElasticScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : Container
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ElasticContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : MenuBox
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ElasticMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">//WaterUIsFactory.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactory</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactoryMethods</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">liquid</span>.<span style="color: rgb(0, 0, 204);">LiquidScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">liquid</span>.<span style="color: rgb(0, 0, 204);">LiquidContainer</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">classic</span>.<span style="color: rgb(0, 0, 204);">ClassicMenuBox</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">WaterUIsFactory</span> <span style="color: rgb(0, 0, 204);">extends</span> UIsFactory <span style="color: rgb(0, 0, 204);">implements</span> UIsFactoryMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="color: rgb(0, 0, 204);">static</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oInstance = <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> WaterUIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> WaterUIsFactory<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="color: rgb(0, 0, 204);">static</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> getInstance<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : WaterUIsFactory <span style="color: rgb(0, 0, 0);">{</span> <span style="color: rgb(0, 0, 204);">return</span> _oInstance; <span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : ScrollBar
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> LiquidScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : Container
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> LiquidContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> createMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : MenuBox
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> ClassicMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>On remarquera au passage qu’il est facile de modifier le contenu de<br />
chacune des familles, vu que les composants sont tous abstraits. Encore<br />
un des bénéfices de l’abstract. ^^</p>
<p>Voici les classes concrètes des objets instanciés à partir des deux fabriques (familles virtuelles)&nbsp;:</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ClassicMenuBox.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBoxMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">classic</span>.<span style="color: rgb(0, 0, 204);">ClassicMenuBox</span> <span style="color: rgb(0, 0, 204);">extends</span> MenuBox <span style="color: rgb(0, 0, 204);">implements</span> MenuBoxMethods

<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ClassicMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> display<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" display()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"ClassicMenuBox"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ElasticContainer.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ContainerMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticContainer</span> <span style="color: rgb(0, 0, 204);">extends</span> Container <span style="color: rgb(0, 0, 204);">implements</span> ContainerMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ElasticContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> empty<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" empty()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"ElasticContainer"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>
<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ElasticMenuBox.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBoxMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticMenuBox</span> <span style="color: rgb(0, 0, 204);">extends</span> MenuBox <span style="color: rgb(0, 0, 204);">implements</span> MenuBoxMethods

<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ElasticMenuBox<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> display<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" display()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"ElasticMenuBox"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// ElasticScrollBar.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBarMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">elastic</span>.<span style="color: rgb(0, 0, 204);">ElasticScrollBar</span> <span style="color: rgb(0, 0, 204);">extends</span> ScrollBar <span style="color: rgb(0, 0, 204);">implements</span> ScrollBarMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> ElasticScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">scroll</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" scroll()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"ElasticScrollBar"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>
<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// LiquidContainer.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ContainerMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">liquid</span>.<span style="color: rgb(0, 0, 204);">LiquidContainer</span> <span style="color: rgb(0, 0, 204);">extends</span> Container <span style="color: rgb(0, 0, 204);">implements</span> ContainerMethods

<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> LiquidContainer<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> empty<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" empty()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>
 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"LiquidContainer"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

<span style="color: rgb(0, 0, 0);">}</span></pre>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// LiquidScrollBar.as</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBarMethods</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">liquid</span>.<span style="color: rgb(0, 0, 204);">LiquidScrollBar</span> <span style="color: rgb(0, 0, 204);">extends</span> ScrollBar <span style="color: rgb(0, 0, 204);">implements</span> ScrollBarMethods
<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> LiquidScrollBar<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" was created"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">scroll</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 204);">this</span> + <span style="color: rgb(0, 102, 0);">" scroll()"</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> <span style="color: rgb(0, 0, 204);">toString</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">String</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="color: rgb(0, 0, 204);">return</span> <span style="color: rgb(0, 102, 0);">"LiquidScrollBar"</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>
<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>Pour finir, déployons notre système à l’intérieur d’une classe nommée pour l’occasion&nbsp;: <em>UserInterface</em>.</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">// UserInterface.as</span>

<span style="font-style: italic; color: rgb(153, 0, 0);">// On importe la fabrique abstraite</span>
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">UIsFactory</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">ScrollBar</span>;

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">Container</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">abstract</span>.<span style="color: rgb(0, 0, 204);">MenuBox</span>;

<span style="font-weight: bold; color: rgb(0, 0, 204);">class</span> factory.<span style="color: rgb(0, 0, 204);">UserInterface</span>

<span style="color: rgb(0, 0, 0);">{</span>
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oFactory:UIsFactory;

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oScrollBar:ScrollBar;
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oContainer:Container;
 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> _oMenuBox:MenuBox;

 	<span style="color: rgb(0, 0, 204);">public</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> myUserInterface<span style="color: rgb(0, 0, 0);">(</span>oFactory:UIsFactory<span style="color: rgb(0, 0, 0);">)</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="font-style: italic; color: rgb(153, 0, 0);">// on stocke une instance de la fabrique concrÃ¨te spécifiée</span>
  		_oFactory = oFactory;
  		_makeView<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>

 	<span style="color: rgb(0, 0, 204);">private</span> <span style="font-weight: bold; color: rgb(0, 0, 204);">function</span> _makeView<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> : <span style="color: rgb(0, 0, 204);">Void</span>

 	<span style="color: rgb(0, 0, 0);">{</span>
  		<span style="font-style: italic; color: rgb(153, 0, 0);">// On instancie les objets de la famille choisie (fabrique concrète)</span>
  		_oScrollBar = _oFactory.<span style="color: rgb(0, 0, 204);">createScrollBar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  		_oContainer = _oFactory.<span style="color: rgb(0, 0, 204);">createContainer</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  		_oMenuBox = _oFactory.<span style="color: rgb(0, 0, 204);">createMenuBox</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;

  		<span style="font-style: italic; color: rgb(153, 0, 0);">// On utilise le polymorphisme pour manipuler chacun des objets</span>

  		_oScrollBar.<span style="color: rgb(0, 0, 204);">scroll</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  		_oContainer.<span style="color: rgb(0, 0, 204);">empty</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  		_oMenuBox.<span style="color: rgb(0, 0, 204);">display</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span>;
  	<span style="color: rgb(0, 0, 0);">}</span>
<span style="color: rgb(0, 0, 0);">}</span></pre>
<p>Il ne nous reste plus qu’à lancer l’application en spécifiant la fabrique concrète que l’on veut utiliser, comme ceci&nbsp;:</p>
<pre><span style="font-style: italic; color: rgb(153, 0, 0);">//</span>

<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">UserInterface</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">ReboundUIsFactory</span>;
<span style="color: rgb(0, 0, 204);">import</span> factory.<span style="color: rgb(0, 0, 204);">WaterUIsFactory</span>;

<span style="font-style: italic; color: rgb(153, 0, 0);">// J'instancie UserInterface en passant en paramètre une instance</span>
<span style="font-style: italic; color: rgb(153, 0, 0);">// de la fabrique Rebound</span>
<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 102, 0);">"ui1:UserInterface &gt;&gt; using ReboundUIsFactory"</span><span style="color: rgb(0, 0, 0);">)</span>;
<span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> ui1:UserInterface = <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> UserInterface<span style="color: rgb(0, 0, 0);">(</span> ReboundUIsFactory.<span style="color: rgb(0, 0, 204);">getInstance</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">)</span>;

<span style="font-style: italic; color: rgb(153, 0, 0);">// Même chose avec une instance de la fabrique Water</span>
<span style="color: rgb(0, 0, 204);">trace</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 102, 0);">"<span style="font-weight: bold; color: rgb(0, 0, 0);">\n</span>"</span> + <span style="color: rgb(0, 102, 0);">"ui2:UserInterface &gt;&gt; using WaterUIsFactory"</span><span style="color: rgb(0, 0, 0);">)</span>;
<span style="font-weight: bold; color: rgb(0, 0, 204);">var</span> ui2:UserInterface = <span style="font-weight: bold; color: rgb(0, 0, 204);">new</span> UserInterface<span style="color: rgb(0, 0, 0);">(</span> WaterUIsFactory.<span style="color: rgb(0, 0, 204);">getInstance</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">)</span> <span style="color: rgb(0, 0, 0);">)</span>;</pre>
<p>Voici pour finir une fiche technique résumant les caractéristiques du modèle <strong>Abstract Factory</strong> :</p>
<p><strong>Nom</strong> : Abstract Factory<br />
<strong>Le problème</strong> : Créer une interface pour produire des familles d’objet sans avoir à manipuler directement leurs classes concrètes.<br />
<strong>La solution</strong> : Utiliser une fabrique abstraite en guise<br />
de patron et créer des fabriques concrètes sur ce modèle. Réaliser une<br />
classe abstraite pour chaque type d’objet et créer des classes<br />
concrètes implémentant leurs spécificités au sein de chaque famille.</p>
<p><strong>Les conséquences</strong> :<br />
- On élabore un système qui permet de choisir une famille d’objets parmi plusieurs.<br />
- Ce système est totalement indépendant de la manière dont ses<br />
composants ont été créés, combinés ou sont représentés. Celà facilite<br />
donc la substitution d’une famille par une autre.<br />
- On renforce le couplage au sein d’une famille d’objets afin de les<br />
utiliser par lot. Au résultat, on favorise la cohérence et le maintien<br />
de ceux-ci.</p>
<p>La suite, bientôt&nbsp;!</p>
<p>En attendant n’hésitez pas à me faire partager vos éventuelles questions ou commentaires.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tweenpix.net/2004/04/20/design-patterns-3-abstract-factory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

