<?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>martian arts</title>
	<atom:link href="http://blog.martian-arts.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.martian-arts.org</link>
	<description>webcode experiments</description>
	<lastBuildDate>Mon, 14 Nov 2011 19:40:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>martian.sta7es, a state machine package</title>
		<link>http://blog.martian-arts.org/martian-sta7es/</link>
		<comments>http://blog.martian-arts.org/martian-sta7es/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 19:40:20 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[as3]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=171</guid>
		<description><![CDATA[What is a state machine. According to wikipedia, a &#8220;final&#8221; state machine is a mathematical model used to design computer programs and digital logic circuits. It is conceived as an abstract machine that can be in one of a finite number of states. The machine is in only one state at a time; the state [...]]]></description>
			<content:encoded><![CDATA[<h3>What is a state machine.</h3>
<p>According to wikipedia, a &#8220;final&#8221; state machine is</p>
<blockquote><p>a mathematical model used to design computer programs and digital logic circuits. It is conceived as an abstract machine that can be in one of a finite number of states.<span id="more-171"></span> The machine <strong>is in only one state at a time</strong>; the state it is in at any given time is called the current state. It can <strong>change from one state to another when initiated by a triggering event or condition</strong>, thisis called a transition. A particular FSM is defined by a list of the possible states it can transition to from each state, and the triggering condition for each transition.</p></blockquote>
<p>Applied to flash, a state machine could be an entity that manage levels in a game or, more advanced, <strong>manage the display list in order to be at the good state at any time</strong>. And that&#8217;s exactly what i did.</p>
<p>In order to make a decision of which transition it should trigger, the state machine needs the ability to choose, by knowning the <em>triggering event or condition</em> ; but for more flexibility, we&#8217;ll introduce to our state machine an object named : the <strong>Front Controller</strong>.</p>
<h3>The smart guy</h3>
<p>It should be very familiar to you if you come from the <em>server-side</em> world. In this world, there&#8217;s only need of a such an object, and not a state machine, since every webpage is a new instance of the program.</p>
<p>In the <em>client-side</em> world, the application is always the same instance. It needs to know if it&#8217;s displaying the homepage or the contact form, and how <em>translate</em> from one to each other.</p>
<p>So the plan is simple, <strong>the front controller</strong> will <strong>decide</strong> which state to apply, and <strong>the state machine</strong> will only <strong>apply</strong> the change.</p>
<p>Let&#8217;s do some code. To make lines shorter and cleaner, i called the state machine <code>State</code>, and the interface of a FrontController <code>Controller</code>.</p>
<p>First, we create the state machine, and initialize it.</p>
<pre class="brush: as3; title: ; notranslate">
var state:State = new State();
state.hook(this, new MyController());
</pre>
<p>and to trigger a change :</p>
<pre class="brush: as3; title: ; notranslate">state.load('/home');</pre>
<p>As said in the wikipedia definition, a finite state machine should know about all the states and all the triggers. But since the task is separated into two objects, only the front controller needs to know about that.</p>
<p>Let&#8217;s have a look at our <code>MyController()</code> :</p>
<pre class="brush: as3; title: ; notranslate">
public class MyController implements Controller
{
	public function handle(slug:String):Statement
	{
		switch(slug)
		{
			case '/home':
				return new Statement(HomeClip);

			case '/contact':
				return new Statement(ContactClip);
		}

		return null;
	}
}
</pre>
<p>Ok that&#8217;s it.</p>
<p>Now, when the state machine will be aware of a triggering event, it will ask the front controller what it should do.</p>
<p>Here, the <code>Statement</code> object represents a wrapper for data about the next state. It&#8217;s holding : the next state itself, and also some parameters you would pass to it, the type of transition to apply, and maybe some parameters for that transition.</p>
<p>Yes ; because it&#8217;s visual, you may want to pass transitions so your clips just don&#8217;t appear/disappear straight in a millisecond.</p>
<h3>Transitions</h3>
<p>I spent a lot of time thinking about modularity, and what would be the best compromize between a dummy implementation and a brain fucking one. After a while, i went to this simple idea : a transition only needs to know about where it comes from and where it goes. That&#8217;s it.</p>
<p>Let&#8217;s say we want to create something like a <em>crossfading</em> transition :</p>
<pre class="brush: as3; title: ; notranslate">
public class CrossFading extends Transition
{
	public function CrossFading(a:DisplayObject, b:DisplayObject):void
	{
		super(a, b);
	}

	override public function start():void
	{
	}
}
</pre>
<p>That&#8217;s all you need to start. The end of your transition should be notified by a Transition.STOP event dispatch.</p>
<p>Because of the diversity of the effects you would want to perform, i figured out that the state machine <strong>should not</strong> care about dealing with the addChild/removeChild stuff. <strong>It&#8217;s up to the transition to know what to display at any time</strong>.</p>
<pre class="brush: as3; title: ; notranslate">
public class CrossFading extends Transition
{
	private var duration:Number;

	public function CrossFading(a:DisplayObject, b:DisplayObject):void
	{
		super(a, b);
	}

	override public function setup(mod_params:Object = null, trans_params:Object = null):void
	{
		this.duration = trans_params.duration;
	}

	override public function start():void
	{
		TweenMax.to(a, 400, { autoAlpha:0, onComplete:p.removeChild, onCompleteParams:[a] });

		TweenMax.from(b, 400, { autoAlpha:0, onComplete:dispatchEvent, onCompleteParams:[new Event(Transition.STOP)] });
	}
}
</pre>
<p>There are some details about what&#8217;s going on here :</p>
<p>• the <code>setup</code> function is called by the state machine right after the construction of the transition, and it initializes it with some given parameters.</p>
<p>• the Transition has a function start():void; function that remember the <a href="martian-t1me"><code>Stackable</code> interface from martian.t1me package</a>. Maybe because it implements it :) ! So any transition is <code>Stackable</code> and can be used in sequences of transitions (madness).</p>
<p>• An other good thing is that if you take some time to code your transition and design it well, you can keep it in a separate toolbox.</p>
<p>• Finally, it&#8217;s also very cool to notice that <strong>Transition could also work in <em>standalone</em> mode</strong>. If you need a special fx for a project that doesn&#8217;t use any state machine, it doesn&#8217;t matter.</p>
<p>So now, how to plug this nice transition into our front controller :</p>
<pre class="brush: as3; title: ; notranslate">
public class MyController implements Controller
{
	public function handle(slug:String):Statement
	{
		switch(slug)
		{
			case '/home':
				return new Statement(HomeClip, { transition:CrossFading, transition_parameters:{ duration:200 } });

			case '/contact':
				return new Statement(ContactClip, { transition:CrossFading, transition_parameters:{ duration:200 } });
		}

		return null;
	}
}
</pre>
<p>I had lots of differents tries with that implementations. Thing is, <em>sometimes</em> i was passing parameters to the state itself, <em>sometimes</em> not ; <em>sometimes</em> i was using a Transition, and <em>sometimes</em> with parameters. Too much <em>sometimes</em>, i decided to give the only mandatory parameter, and then, extra parameters all together in a big anonymous object — it can be lame, but it&#8217;s pretty handy.</p>
<p>So now, when triggering an changing event, the state machine will take the condition, give it to the front controller, receive a Statement of what to do. It will create the new state, the given transition and let the transition do its work until it finished.</p>
<p>The first transition i did was a core transition which&#8217;s named Cut and does a simple addChild/removeChild switch. Then, i realized sometimes, a displayobject should want to manage itself how it should appear and disappear. Then, i coded my second core transition, called Slave.</p>
<h3>Introducing Module</h3>
<p>What&#8217;s a Module ? It could be seen as a super Sprite. A Sprite that is <strong>aware of the different steps of being a part of a state changing process</strong>. It knows about initialization, appearance, disappearance, and destruction.</p>
<p>I chose not calling it a State because it&#8217;s not a State. As it&#8217;s pretty useful, it could be used as a replacement of the regular Sprite, without any state machine. It&#8217;s a common concept, but i think it has to be separated to keep in mind the modularity.</p>
<p>It has 4 main functions : <strong>init</strong>, <strong>show</strong>, <strong>hide</strong>, and <strong>kill</strong> for initialization, appearance, disappearance, and destruction.</p>
<p>As this type is known by the state machine, this one can handle initialization and destruction processes. The initialization one is known as completed by the state machine by dispatching a <code>Module.READY</code>. That way, the state machine knows that the module is ready to be added to the stage and displayed. Appearance and disappearance processes should be handled, naturally, by a Transition  since it&#8217;s a visual effect.</p>
<p>And that&#8217;s what the <code>Slave</code> transition does. It performs a simple hide/show sequence as the visual transition, letting each module (current and next) deal with their visual animations ; and to let the Slave transition know about the progression of appearance/disappearance, each module needs to dispatch a <code>Module.SHOWN</code> or <code>Module.HIDDEN</code> event.</p>
<div><img src="http://blog.martian-arts.org/wp-content/uploads/2011/11/transition.jpg" alt="" title="transition" width="529" height="333" class="alignnone size-full wp-image-198" /></div>
<p>With that kind of system, it&#8217;s damn easy to do whatever you want :</p>
<p>• If you need a kind of &#8220;external&#8221; transition, extend Transition and let&#8217;s go<br />
• If you need a kind of <em>internal</em> transition, use Slave directly<br />
• If you need an overlaping <em>kind-of</em> internal transition, use Slave, and dispatch your <code>Module.HIDDEN</code> before the end of your transition<br />
• If you need both internal and external transition system, you can try your own Transition and take care internally of the events</p>
<p>That way, it&#8217;s fully customizable with staying the best compromize between flexibility and hard coding.</p>
<h3>Deeplinking</h3>
<p>As i already worked on my own deeplinking solution, it has been <strong>very</strong> easy to insert the deeplinking idea into the state machine. But. As it&#8217;s not <em>necessary</em> to use it, i prefered to separate it.</p>
<p>That way, the deeplinking part is away from the state machine, and should be initialized separatly ; when it&#8217;ll be done, the state machine will know it automatically, and any external change will be treated as a triggering event by the state machine.</p>
<pre class="brush: as3; title: ; notranslate">
var deeplinking:Deeplinking = new Deeplinking();
deeplinking.hook(stage);
</pre>
<p>What it does under the hood is that both State and Deeplinking classes inherits from a common class which registers each of them in a common static dictionary, so they can ask for each other.</p>
<h3>Cherry on the cake</h3>
<p>Because medium to big projects can have the same front controller structure, i decided to create an xml based configurable controller.</p>
<p>It&#8217;s highly inspired from the C# routing system, and that&#8217;s maybe why it&#8217;s called &#8220;Router&#8221;.</p>
<p>Let&#8217;s see how it works, and then, its xml definition scheme.</p>
<pre class="brush: as3; title: ; notranslate">
var state:State = new State();
state.hook(this, new Router(someXML, customValidationObject));
</pre>
<p>For now, that&#8217;s it. Focus on <code>someXML</code>. If you give an XML, it will use it directly. If you pass a String containing a &#8216;.xml&#8217; or &#8216;.php&#8217;, it will embed the process of loading and can be queued since <code>Router</code> is a <code>Stackable</code> object.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;data&gt;
	&lt;states app=&quot;app.states&quot; default=&quot;/&quot;&gt;
		&lt;state&gt;
			&lt;id&gt;home&lt;/id&gt;
			&lt;module&gt;Home&lt;/module&gt;
			&lt;slug&gt;/&lt;/slug&gt;
			&lt;title&gt;&lt;/title&gt;
			&lt;keywords&gt;&lt;/keywords&gt;
		&lt;/state&gt;

		&lt;state&gt;
			&lt;id&gt;page1&lt;/id&gt;
			&lt;module&gt;Page1&lt;/module&gt;
			&lt;slug&gt;
				&lt;pattern&gt;/page/1&lt;/pattern&gt;
				&lt;parameters&gt;
					&lt;color&gt;0xff0000&lt;/color&gt;
				&lt;/parameters&gt;
			&lt;/slug&gt;
			&lt;title&gt;&lt;/title&gt;
			&lt;keywords&gt;&lt;/keywords&gt;
		&lt;/state&gt;

		&lt;state&gt;
			&lt;id&gt;pages&lt;/id&gt;
			&lt;module&gt;OtherPage&lt;/module&gt;
			&lt;slug&gt;
				&lt;pattern&gt;/page/{var1}/{var2}/{var3}&lt;/pattern&gt;
				&lt;constraints&gt;
					&lt;var1&gt;@[0-9]&lt;/var1&gt;
					&lt;var2&gt;delegatefunction&lt;/var2&gt;
					&lt;var3 optional='true' /&gt;
				&lt;/constraints&gt;
			&lt;/slug&gt;
			&lt;title&gt;&lt;/title&gt;
			&lt;keywords&gt;&lt;/keywords&gt;
		&lt;/state&gt;

		&lt;state&gt;
			&lt;id&gt;404&lt;/id&gt;
			&lt;module&gt;Error404&lt;/module&gt;
			&lt;slug&gt;/404&lt;/slug&gt;
			&lt;title&gt;&lt;/title&gt;
			&lt;keywords&gt;&lt;/keywords&gt;
		&lt;/state&gt;
	&lt;/states&gt;

	&lt;notfound&gt;/404&lt;/notfound&gt;

	&lt;transitions app=&quot;app.transitions&quot; default=&quot;Slave&quot;&gt;
		&lt;transition from=&quot;home&quot; to=&quot;*&quot;&gt;OverlapIn&lt;/transition&gt;

		&lt;transition from=&quot;*&quot; to=&quot;home&quot;&gt;
			&lt;name&gt;MyCustomTransitionBack&lt;/name&gt;

			&lt;parameters&gt;
				&lt;duration&gt;2&lt;/duration&gt;
			&lt;/parameters&gt;
		&lt;/transition&gt;
	&lt;/transitions&gt;
&lt;/data&gt;
</pre>
<p>Hum.</p>
<p>So here, nothing complicated.</p>
<p>Each state is defined into a <code>state</code> node, nested in the <code>states</code> area.</p>
<p>The <code>states</code> area has only 2 attributes, which are <code>app</code>, the package of the states, and <code>default</code>, a default url to launch (if needed).</p>
<p>Each <code>state</code> node has the same structure :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;state&gt;
	&lt;id&gt;a unique id for this state&lt;/id&gt;
	&lt;module&gt;the name of the module's class&lt;/module&gt;
	&lt;title&gt;&lt;/title&gt;
	&lt;keywords&gt;&lt;/keywords&gt;
&lt;/state&gt;
</pre>
<p>And a specific and modulable <code>slug</code> node which can have multiple definitions :</p>
<p>The <em>static url</em> one :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;slug&gt;/url/to/match&lt;/slug&gt;
</pre>
<p>The <em>dynamic url</em> one :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;slug&gt;
	&lt;pattern&gt;/url/{to}/{match}&lt;/pattern&gt;
&lt;/slug&gt;
</pre>
<p>The <em>constraint driven dynamic url</em> one :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;slug&gt;
	&lt;pattern&gt;/url/{to}/{match}&lt;/pattern&gt;
	&lt;constraints&gt;
		&lt;to&gt;@^regex_expression[0-9]*&lt;/to&gt;
		&lt;match&gt;delegateFunctionCall&lt;/match&gt;
	&lt;/constraints&gt;
&lt;/slug&gt;
</pre>
<p>In those constraints, you can type a regular regex, or the name of a function. This function must be part of my <code>customValidationObject</code>, given in the <code>hook</code> of the state machine, and must take a String, an return a Boolean.</p>
<p>You can also pass optional parameters, which can have default values. Any time a default value is written, the parameter becomes optional :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;slug&gt;
	&lt;pattern&gt;/url/{to}/{match}/{eventually}&lt;/pattern&gt;
	&lt;constraints&gt;
		&lt;to&gt;@^regex_expression[0-9]*&lt;/to&gt;
		&lt;match&gt;delegateFunctionCall&lt;/match&gt;
		&lt;eventually default=&quot;false&quot;&gt;@(true|false)&lt;/eventually&gt;
	&lt;/constraints&gt;
&lt;/slug&gt;
</pre>
<p>If any pattern matches, the code will eventually throw an Error and break your swf. To prevent that, you can give a <code>notfound</code> node inside of the <code>states</code> node, and this will be handled as your 404 document url.</p>
<pre class="brush: as3; title: ; notranslate">
var customValidationObject:Object = new Object();
customValidationObject.delegateFunctionCall = function(s:String):Boolean { return s.indexOf('valid') != -1; };

var state:State = new State();
state.hook(this, new Router(someXML, customValidationObject));
</pre>
<p>All those parameters will be given in an object in the init call of your module. You can even force passing extra parameters with a <code>parameters</code> node (as seen in the &#8216;page1&#8242; module above).</p>
<p>Transitions can also be set up from here. There&#8217;s a <code>transitions</code> area where you can find the same <code>app</code> and <code>default</code> concepts than in <code>states</code>.</p>
<p>Each transition node has a <code>name</code> node, which holds the name of the transition&#8217;s class, and a <code>parameters</code> one, similar to <code>slug</code>&#8216;s one. Those datas will be given in an object at the transition&#8217;s setup call. You can also set Flex-like filters to define where transitions should apply with the <code>from</code> and <code>to</code> attributes, which can be defined separatly, or together, with the <code>id</code> value of a <code>state</code> or <code>*</code> to match all.</p>
<p>I know it can be a <em>bit</em> complex, but as i&#8217;m using it all the time, i can affirm that the daily use is very easy.</p>
<p>Other thing to notice is that you must force inclusion of your states and transitions since they should&#8217;nt be linked to your application.</p>
<p>Here&#8217;s a simple <a href='http://dev.martian-arts.org/sta7es/' target='_blank'>working example</a>, and <a href='http://dev.martian-arts.org/sta7es/src.zip' target='_blank'>the app-side sources</a>.</p>
<p><a href='https://github.com/ynk/martian-as3lib/tree/master/src/martian/sta7es' target='_blank'>Sources for this package can be found here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/martian-sta7es/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>martian.t1me, a sequencing package</title>
		<link>http://blog.martian-arts.org/martian-t1me/</link>
		<comments>http://blog.martian-arts.org/martian-t1me/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 13:30:50 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[as3]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=134</guid>
		<description><![CDATA[Why start with the last package ? Because this sequencing package holds a concept that is used on many parts of the library. So, by using other parts of the library, you may use/need to know what&#8217;s going on. Description The idea is simple. You have 3 mains objects, an 1 interface to know. Those [...]]]></description>
			<content:encoded><![CDATA[<p>Why start with the last package ? Because this sequencing package holds a concept that is used on many parts of the library. So, by using other parts of the library, you may use/need to know what&#8217;s going on.<span id="more-134"></span></p>
<h3>Description</h3>
<p>The idea is simple. You have 3 mains objects, an 1 interface to know. Those main objects are kind of &#8220;managers&#8221; for a stack of tasks to execute. Tasks can be whatever you want, from a loading task to a tweening one. Main objects are : <code>Sequence, Group, and Queue</code>. Interface for a task is <code>Stackable</code>.</p>
<p>• A <strong>sequence</strong> is an object that executes one task by one task :</p>
<div><img src="http://blog.martian-arts.org/wp-content/uploads/2011/11/sequence.jpg" alt="" title="sequence" width="280" height="20" class="alignnone size-full wp-image-163" /></div>
<p>• A <strong>group</strong> executes all its tasks in parallel :</p>
<div><img src="http://blog.martian-arts.org/wp-content/uploads/2011/11/groupe.jpg" alt="" title="groupe" width="112" height="140" class="alignnone size-full wp-image-161" /></div>
<p>• A <strong>queue</strong> is a mix of sequence and group. It executes N tasks of a stack in parallel, and pick an other task of the stack when a task ends until the queue ends :</p>
<div><img src="http://blog.martian-arts.org/wp-content/uploads/2011/11/queue.jpg" alt="" title="queue" width="147" height="40" class="alignnone size-full wp-image-162" /></div>
<p>To quickly highlight the benefits of each, think that each task of the images above are actually assets. The width of the image represents the amount of time to complete the tasks, but the height represents a kind of how slow your downloads will be, because of the parallelism of the tasks.</p>
<p>The black line represents when those 3 types of objects dispatch an event : when their stack of task is finished.</p>
<p>• The <strong>Stackable</strong> interface represents an object that can be stored in a stack of tasks.</p>
<p>A nice thing to notice is that Sequence, Group ans Queue are Stackable. So you can make sequences of sequences, groups of sequences, sequences of queues, or whatever that may fit your needs at any time.</p>
<p>Because of the daily use, i already made Stackable objects :</p>
<p>• <strong>Load</strong>, which attempts to uniform in a unique way most of the loaders of the flash APi, Loader, URLLoader, Sound.</p>
<p>• <strong>Message</strong> is a Stackable AMFphp call.</p>
<p>• <strong>Call</strong> is a single function call with custom arguments. It looks useless alone, but it can be very handy embedded into a stack.</p>
<p>• <strong>Delay</strong> makes a pause into a stack.</p>
<p>• <strong>Shell</strong> is a wrapper for any existing object to be Stackable without having to extends or create something special. Good for edge cases.</p>
<p>Cherry on the cake, i&#8217;ve implemented two more interfaces :</p>
<p>• <strong>Progressive</strong> which defines a &#8220;progress:Number&#8221; getter.</p>
<p>• <strong>Pausable</strong> which is a pause/resume concept.</p>
<p>Both are implemented on the Queue/Sequence/Group objects already (and some other objects, such as Load).</p>
<p>That&#8217;s it ! Some misc classes :</p>
<p>• <strong>Preloader</strong> holds an abstract logic to handle preloaders with Stackable objects.</p>
<p>• <strong>Time</strong> is only made of static constants.</p>
<h3>Examples</h3>
<p>• Load uniformity (events, content access) :</p>
<pre class="brush: as3; title: ; notranslate">
var image:Load = new Load('img.png', Load.IMAGE);
image.addEventListener(Event.COMPLETE, oncomplete);
image.load();

function oncomplete(e:Event):void { var bm:Bitmap = e.target.data as Bitmap; }
</pre>
<pre class="brush: as3; title: ; notranslate">
var xml:Load = new Load('config.xml', Load.TEXT);
xml.addEventListener(Event.COMPLETE, oncomplete);
xml.load();

function oncomplete(e:Event):void { var data:XML = new XML(e.target.data); }
</pre>
<p>Let&#8217;s try to embed Load into our containers :</p>
<p>• Using a sequence to preloads assets of a website :</p>
<pre class="brush: as3; title: ; notranslate">
var config:Load = new Load('config.xml', Load.TEXT);
var locale:Load = new Load('fr_FR.xml', Load.TEXT);
var brands:Load = new Load('brands.png', Load.IMAGE);
var themes:Load = new Load('themes.swf', Load.RSL);

var data:Message = new Message('News.getAll');
var pics:Library = new Library('lib.xml');

var sequence:Sequence = new Sequence();
sequence.addEventListener(Time.STOP, oncomplete);
sequence.stack.push(config, locale, brands, themes, new Call(setup_ui), assets);
sequence.start();

function setup_ui():void { /*do something directly with the RSL*/ }
function oncomplete(e:Event):void { /* display your data */ }
</pre>
<p>• Using a Group to synchronize ending of custom objects :</p>
<pre class="brush: as3; title: ; notranslate">
var shell1:Shell = new Shell(myCustomObject1, &quot;startFunction&quot;, &quot;endingEvent&quot;);
var shell2:Shell = new Shell(myCustomObject2, &quot;anotherStartFunction&quot;, &quot;diffEndingEvent&quot;);

var group:Group = new Group();
group.addEventListener(Time.STOP, oncomplete);
group.stack.push(shell1, shell2);
group.start();

function oncomplete(e:Event):void { /* continue process */ }
</pre>
<p>• Using a Queue to parallelize some heavy downloads while small are sequenced :</p>
<pre class="brush: as3; title: ; notranslate">
var bigEmbedVideo:Load = new Load('video.swf', Load.SWF);

var queue:Queue = new Queue(2);
queue.addEventListener(Time.STOP, oncomplete);
queue.stack.push(bigEmbedVideo);
for (var i:int = 0; i &lt; 50; i++) { queue.stack.push(new Load(i + '.jpg', Load.IMAGE)); }
queue.start();

function oncomplete(e:Event):void { /* loading done */ }
</pre>
<p>I think those examples are covering most of the main topics of the package !</p>
<p>As usual, comments are welcome :)</p>
<p><a href='https://github.com/ynk/martian-as3lib/tree/master/src/martian/t1me' target='_blank'>Sources for this package can be found here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/martian-t1me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing martianlib</title>
		<link>http://blog.martian-arts.org/introducing-martianlib/</link>
		<comments>http://blog.martian-arts.org/introducing-martianlib/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 15:00:59 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[as3]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=127</guid>
		<description><![CDATA[I think my own toolbox is now mature enough to be shared. A lot of things to say in this lib, maybe because i wrote it for a looong time :) First is, as i&#8217;m tired of huge structures, i decided not to deliver it as a framework. No big need to start a project [...]]]></description>
			<content:encoded><![CDATA[<p>I think my own toolbox is now mature enough to be shared. A lot of things to say in this lib, maybe because i wrote it for a looong time :)<span id="more-127"></span></p>
<p>First is, as i&#8217;m tired of huge structures, i decided not to deliver it as a framework. No <strong>big need</strong> to start a project with something, and apply to an obscure skeleton. There&#8217;s only small-to-medium tools which can be used all together, or not. I separated this library in many packages, let&#8217;s try to describe them quickly :</p>
<p>• <code>daem0n</code> is a suite of tools that are meant to act just like computer daemons. Most of them are managers, mainly used as singletons, but i&#8217;m sure they can do more.</p>
<p>• <code>ev3nts</code> contains some tools around the event model</p>
<p>• <code>m4gic</code> is full of small tools which looks magic for the everyday use</p>
<p>• <code>sta7es</code> keeps my state/transition machine and a very powerful and flexible routing system</p>
<p>• <code>t1me</code> is my <a href='martian.t1me' target='_blank'>abstracted sequencing lib</a>.</p>
<p>I&#8217;ll try to add a serie of posts for each package soon.<br />
For now, here&#8217;s the github :</p>
<p><a href='https://github.com/ynk/martian-as3lib' target='_blank'>let&#8217;s fork !</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/introducing-martianlib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random talk #0</title>
		<link>http://blog.martian-arts.org/random-talk-0/</link>
		<comments>http://blog.martian-arts.org/random-talk-0/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 11:30:31 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=106</guid>
		<description><![CDATA[Well, it&#8217;s a bit off-topic but i&#8217;m proud to say i&#8217;ve finished a cool website with a gifted artistic director known as urbanplastic. My company decided to build it in C#, so as being a php server side developer, i had to discover this language and the beauty of its mvc framework, MVC. As said, [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it&#8217;s a bit off-topic but i&#8217;m proud to say i&#8217;ve finished a <a href='http://lesabonnesfontcourt.com/' target='_blank'>cool website</a> with a gifted artistic director known as <a href='http://cargocollective.com/urbanplastic' target='_blank'>urbanplastic</a>. My company decided to build it in C#, so as being a php server side developer, i had to discover this language and the beauty of its mvc framework, MVC.<span id="more-106"></span></p>
<h3>As said, C# was first a big discovery.</h3>
<p>Quickly, the pros i can see from my own background are :</p>
<p>• Brackets based Object initializators. After typing <code>new</code> and your class name, add <code>{}</code> and define some of its property.</p>
<p>• This fucking awesome technology which is the lamdba expression system. It a kind of inline delegation declaration system, but strongly typed and highly flexible. I still don&#8217;t get all the power of it ; the best way to summarize it is to provide a very simple and understandable example, and its C# lambda equivalent<br/>Let&#8217;s say, in javascript :</p>
<pre class="brush: jscript; title: ; notranslate">
var strings = ['My', 'rAnDomlY', 'caSEd', 'sTRInG'];
for (var i = 0; i &lt; strings.length; i++) { strings[i] = strings[i].toUpperCase(); }
</pre>
<p>C# Lambda made :</p>
<pre class="brush: csharp; title: ; notranslate">
List&lt;String&gt; strings = new List&lt;String&gt;{ &quot;My&quot;, &quot;rAnDomlY&quot;, &quot;caSEd&quot;, &quot;sTRInG&quot; };
strings.ConvertAll(i =&gt; i.ToLower());
</pre>
<p>It&#8217;s <strong>D.A.M.N cool</strong>.</p>
<p>• Linq, which is also an amazing thing. It looks like sql queries, but strongly typed as it&#8217;s no longer a String, but rather some language keywords. The main idea with it is to make a kind of <code>select * from table</code>, store the instance of the query, and then execute some filters on it ; but as long as you&#8217;re not executing the query, the SQL server is not polled : the instance is prepared and optimized to handle your first query and then its filtering or whatever kind of process. I didn&#8217;t had to use it directly because i wasn&#8217;t involved in the database design and its related queries, but i&#8217;ve been seduced by the clarity of it. Best thing is to have a look on an introduction to Linq <a href='http://msdn.microsoft.com/en-us/library/bb397906.aspx' target='_blank'>there</a></p>
<p>Saying that, i feel some cons. Most of the time, shortcuts like Lambda and so on are decreasing the time of development ; sometimes, a very smart language can be long and fastidious.<br/>Have a look at this PHP Post request :</p>
<pre class="brush: php; title: ; notranslate">
$c = curl_init();
curl_setopt($c, CURLOPT_URL, &quot;http://some.distant.url&quot;);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_POST,true);
curl_setopt($c, CURLOPT_POSTFIELDS,array('param0'=&gt;'value0','param1'=&gt;'value1'));
$output = curl_exec($c);
var_dump($output);
curl_close($c);
</pre>
<p>See how easy it is ? I&#8217;m sure it can be reduced easily.<br/>Same in C# :</p>
<pre class="brush: csharp; title: ; notranslate">
WebRequest request = WebRequest.Create (&quot;http://some.distant.url&quot;);
request.Method = &quot;POST&quot;;
string postData = &quot;param0=value0&amp;param1=value1&quot;;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = &quot;application/x-www-form-urlencoded&quot;;
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
</pre>
<p>Do you get what i mean now ?</p>
<p>Otherwise, it&#8217;s not a big deal if you&#8217;re not on a mac. Visual Studio is the smartest IDE i ever seen so far, tons of features, and a great memory management. I recognize more than ever FlashDevelop&#8217;s influences now :) You should really have a look on this one.</p>
<h3>I worked with the .NET MVC framework</h3>
<p>It&#8217;s also a great tool, well designed, with simplicity in mind. There&#8217;s nothing special around it when you know how great are tools like the Zend Framework or Symfony.</p>
<p>By the way, a very good feature in it is the templating engine, named Razor. It&#8217;s pretty simple, and all the calls are easily findable since they&#8217;re prefixed with an <code>@</code>. You can even type strong C# embedded in a <code>@{}</code> block. It&#8217;s not something new for php people, because there are dozen of templating engines, such as Smarty, etc&#8230;, but since it&#8217;s a Microsoft technology, it looked for C# devs that it&#8217;s no longer a pain in the ass, since the older templating engine was a very big crap, so it&#8217;s noticeable.</p>
<p>I also loved of the Routing system. I had to deal with it very deeply with it, and since i had needs like regex and custom validation on urls, i appreciated how simple it is to manage those in a single line of code.</p>
<p>I reproduced some concepts in my own actionscript 3 library. More to come on this subject soon ; i&#8217;m about to publish it on github. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/random-talk-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deeplinking with HTML5</title>
		<link>http://blog.martian-arts.org/deeplinking-with-html5/</link>
		<comments>http://blog.martian-arts.org/deeplinking-with-html5/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 21:05:52 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=70</guid>
		<description><![CDATA[Since i had different needs that the one given with swfaddress, i decided to write my own. Plus being a real challenge to rewrite such a library, it&#8217;s a good opportunity to add the html5 window.history.pushState feature and get clean non hashed urls. The basic is very simple. Put a timer which checks everytime the [...]]]></description>
			<content:encoded><![CDATA[<p>Since i had different needs that the one given with swfaddress, i decided to write my own. Plus being a real challenge to rewrite such a library, it&#8217;s a good opportunity to add the html5 <code>window.history.pushState</code> feature and get clean non hashed urls.<span id="more-70"></span></p>
<p>The basic is very simple. Put a timer which checks everytime the current browser values against some stored values. If different, the url has changed and a function is called. That&#8217;s it.</p>
<p>The current <a href="http://www.asual.com/swfaddress/" target="_blank">SWFAddress</a> system works like that with old browsers. It listens to browser&#8217;s events with modern ones. With both, it checks the <code>window.location.hash</code> property, which holds only what&#8217;s after the hash character. Pretty easy hu ?</p>
<p>As you may know, some new parts of javascript includes nice history handling methods, such as <code>pushState</code> which, for our case, has the ability to rewrite the current url without having to use a hash. Prettier urls indeed.</p>
<p>Having this new kind of url introduces a new technical problem. Remember, the hash system is relative. It only cares about what&#8217;s after the hash. With manipulating the history with <code>pushState</code>, things are differents. As you&#8217;re not manipulating the hash anymore, you need to get your data in the <code>window.location.href</code> property. But as you could guess, it stores the absolute request uri, which holds your base url and some subfolder you could requests ; and mess up any kind of comparison you may try because of it.<br />
Solving that is easy. There are plenty of solutions. The html best practice i found is that writing a base tag which describes the base url could help my code to know what&#8217;s relative to the web application in the url. With this data, the script will be able to substract the base url from <code>window.location.href</code> and will be able to compare stored value against browser&#8217;s current url.</p>
<p>So, for now, that&#8217;s required.</p>
<p>As for now a big amount of (dummy) users are still using some old browsers, i also implemented the regular hash engine, and choose what method to use with <code>window.history.pushState != undefined</code> test. I really thought that compatibility wouldn&#8217;t be a problem, but since internet explorer doesn&#8217;t store hash values in its history, i had to hack a bit with an iframe, thanks to <a href="http://stackoverflow.com/questions/680785/on-window-location-hash-change/1647331#1647331" target="_blank">stackoverflow</a>.</p>
<p>So, it&#8217;s working both ways : with and without hash.</p>
<p>I decided to write it as a jQuery plugin because it was easier for me, especially with crossbrowser domready detection. After, i rewrote it in a pure javascript object. It&#8217;s less automatic but there&#8217;s no dependencies.</p>
<p>So it can be embedded in <code>jQuery.deeplinking</code> or used without dependencies as a global <code>Deeplinking</code> javascript object.</p>
<p>The plugin is also able to hook on the top of swfobject directly (both jQuery and standalone). It will try to fire a single function called &#8216;deeplinking&#8217; with the event type as the first argument. Because jQuery&#8217;s swfobject plugin had a different behavior — including the object element in the selector instead of replacing it — i had to fork it.</p>
<p>So you can use it with flash.</p>
<p>Btw, if you&#8217;re kind of people to use that jquery plugin for a flash projet, you may be interested in fixing an <a href="http://stackoverflow.com/questions/2184900/my-flash-reinitializes-reloads-when-its-container-is-resized-via-javascript/2837120#2837120" target="_blank">annoying resizing bug</a> generated by jQuery itself.</p>
<h3>Documentation</h3>
<p>You&#8217;ll referer to the deeplinking lib with the <code>deeplinking</code> object for the standalone lib and <code>$.deeplinking</code> for the jQuery plugin.</p>
<p>After that, you&#8217;ve a bunch of methods you may be interested in :</p>
<p><strong>deeplinking.onready</strong> : It&#8217;s a function you&#8217;ve to set to know when the deeplinking object is ready and running.</p>
<p><strong>deeplinking.oninternalchange</strong> : It&#8217;s a function you&#8217;ve to set to handle any internal url update (basically, when you set the deeplinking value by the code).</p>
<p><strong>deeplinking.onexternalchange</strong> : It&#8217;s a function you&#8217;ve to set to handle any external url update. It&#8217;s the most useful. It&#8217;ll be fired when the user changes the url, or press back/forward buttons.</p>
<p><strong>deeplinking.value()</strong> : It&#8217;s a getter/setter (depending if you provide an argument or not). It will set the url the way you want and fire the oninternalchange function you provided.</p>
<p><strong>deeplinking.initialize()</strong> : With jQuery, it&#8217;s automatically fired on domready. <u>When using the standalone library, it&#8217;s your business to call it first.</u> <u>When used with flash, the best practice i found is to let Flash call himself this method with an ExternalInterface.call().</u></p>
<p><strong>deeplinking.activate()</strong> : Enables the url watching functions</p>
<p><strong>deeplinking.deactivate()</strong> : Disables the url watching functions.</p>
<p><strong>deeplinking.debug</strong> : Boolean which is used to know if some debug calls have to be fired</p>
<p><strong>deeplinking.log</strong> : A function you can set to know what&#8217;s going on inside when debug is true. Its default is console.log if defined.</p>
<p><strong>deeplinking.html5</strong> : You can force this to false to use only the hash system even on modern browser.</p>
<p>After that, there might be other public properties/methods you want to call.</p>
<h3>Compatibility</h3>
<p>It&#8217;s now working on my testing browsers, known as :</p>
<p>Mozilla Firefox 6 and 7, Chrome 14, Internet Explorer 6/7/8 and Safari 4 for Windows for the PC part, and Mozilla Firefox 7, Chrome 14, Safari 4 for the MacOSX part.</p>
<h3>Downloads</h3>
<p>Deeplinking Library : <a href="http://dev.martian-arts.org/deeplinking/deeplinking standalone.zip" target="_blank">standalone</a> &#8211; <a href="http://dev.martian-arts.org/deeplinking/deeplinking jquery.zip" target="_blank">jQuery</a></p>
<h3>Demos</h3>
<p><a href="http://dev.martian-arts.org/deeplinking/javascript/standalone/" target="_blank">Javascript Standalone demo</a> &#8211; (<a href="http://dev.martian-arts.org/deeplinking/javascript/standalone/src.zip" target="_blank">zip</a>)<br />
<a href="http://dev.martian-arts.org/deeplinking/javascript/jquery/" target="_blank">Javascript jQuery demo</a> &#8211; (<a href="http://dev.martian-arts.org/deeplinking/javascript/jquery/src.zip" target="_blank">zip</a>)</p>
<p><a href="http://dev.martian-arts.org/deeplinking/flash/standalone/" target="_blank">Flash Standalone demo</a> &#8211; (<a href="http://dev.martian-arts.org/deeplinking/flash/standalone/src.zip" target="_blank">zip</a>)<br />
<a href="http://dev.martian-arts.org/deeplinking/flash/jquery/" target="_blank">Flash jQuery demo</a> &#8211; (<a href="http://dev.martian-arts.org/deeplinking/flash/jquery/src.zip" target="_blank">zip</a>)</p>
<p><a href="https://github.com/ynk/martian-deeplinking" target="_blank">Fourchette it on github :)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/deeplinking-with-html5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding MVC</title>
		<link>http://blog.martian-arts.org/understanding-mvc/</link>
		<comments>http://blog.martian-arts.org/understanding-mvc/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 23:56:06 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=61</guid>
		<description><![CDATA[For a project i worked on, i had to build a php website from scratch. The timing was good, and the project was tiny enough to let some freestyle happen. I had the chance to work with great people before, and had lots of talks about the zend framework or symfony. I heard a lot [...]]]></description>
			<content:encoded><![CDATA[<p>For a project i worked on, i had to build a php website from scratch. The timing was good, and the project was tiny enough to let some freestyle happen.<span id="more-61"></span></p>
<p>I had the chance to work with great people before, and had lots of talks about <a href="http://framework.zend.com/" target="_blank">the zend framework</a> or <a href="http://www.symfony-project.org/" target="_blank">symfony</a>. I heard a lot about their processes, their pros and cons, but didn&#8217;t get the point with using those big engines for small/medium projects.</p>
<p>It was a good time for me. I enjoyed a lot scratching my head on problems that i knew Zend or Symfo writers had. About the structure, about performances. Since i still feel newbie with php, i didn&#8217;t matter that much on execution&#8217;s performances.</p>
<p>Since my project folder was fully empty, I first put some basics concepts, such as a lib folder that would have contained common framework code, a src folder that would have contained my app code, and a www folder in which i would have put public files.</p>
<p>Then, i started with a single monolithic static object called &#8220;App&#8221; in that lib/ folder, and a index.php in www/ that triggers my App::dispatch method, with also an .htaccess file that redirects any non-physical request to the index.php file.</p>
<p>After that, my strategy was to parse the url with a single type of route which was <code>/{controller}/{action}/{parameters}</code>.</p>
<p>Project changed, and a second app was also needed : the backend. I added a src/ folder that would contain a specific folder for each application handled by the framework. Since i didn&#8217;t know the best way to link urls to specific applications, i built a simple file which was called &#8220;config.php&#8221; containing an associative array was describing this relationship between urls and application.</p>
<p>When it was about to choose how i would do to call my actions, i started to understand why framework suffixes controller and action names : they probably needed to avoid multiple definition that could occurs between lib code and app code that couldn&#8217;t be under control.</p>
<p>I was not very happy with having a big structure with controller objects that had actions as methods, it looked very huge to me. As i&#8217;m a wordpress fan, i decided to use filesystem&#8217;s file as controller&#8217;s concept and simple global functions as action.</p>
<p>I only had to have function index($params = null) {} in my src/front/controllers/index.php file and it was working ! YAY ! After that, all was easy :) My process was kind of defined, so it was only about pimping it up&#8230; and that&#8217;s what i did !</p>
<p>I added a functions.php file which acted as a starter file of each application, and so i learnt about the &#8220;pre&#8221; and &#8220;post&#8221; dispatch concept i heard so much about from <a href="http://www.kosmidis.me/" target="_blank">panosru</a>.</p>
<p>I also changed the config.php file to a more simple xml file that would be parsed automatically&#8230; MUCH easier, and also inspired by the Zend&#8217;s ini file. I still ask myself if xml is the best format. I still prefer it from others, but i&#8217;ll like to consider using json, yaml or ini too.</p>
<p><a href="http://arnaud-tanielian.fr/" target="_blank">Danetag</a> told me a long time ago about orms, and about doctrine was working. I wanted to try myself, something more humble of course. I wrote a first &#8220;Model&#8221; object that would contain all the logic of a single abstract model object. I thought it was logic to have a static &#8220;get&#8221; method, since any model object should perform a get action to a database. Then, the instances should be able to be saved or deleted. The save method should know if an insert or update query should occur. My implementation was working fine, but i was too deep in the code to see that i would had to call Model::get any time i would get something. That was very bad because i was expecting something like User::get, or Admin::get&#8230; Hopefully for myself, php keeps inheritance of static methods. It&#8217;s still a strange and disturbing thing to me but it looks like php won&#8217;t change, since it&#8217;s still working wih php6.</p>
<p>I&#8217;m still not able to make NN requests, and i&#8217;m not that confident with execution&#8217;s performances. But as a piece of learning, i really enjoy what i did. I learnt a lot, and i highly recommand to try this trip into mvc. You&#8217;re in front of choices that others took before, you&#8217;re passing through some state of mind they probably had, and you take decisions that may be different than them. If the timing is good, try yourself, you&#8217;ll know what i meant ;)</p>
<p>I&#8217;m currently re-writing the url parsing, to let the coder choose the url pattern. I also want to taste the difficulty of i18n better than i tried to do (aka &#8216;DIY&#8217;).</p>
<p>I put my code on <a href="https://github.com/ynk/martian-phpmvc" target="_blank">github</a>, if you give it a try, feel free to comment.</p>
<p>Don&#8217;t be rude, it&#8217;s a 0.1 alpha :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/understanding-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dynamic Alpha</title>
		<link>http://blog.martian-arts.org/dynamic-alpha/</link>
		<comments>http://blog.martian-arts.org/dynamic-alpha/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 23:19:05 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[as3]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=21</guid>
		<description><![CDATA[Since few years, coverflows have been successfull. The best way to show lots of things in a small space. Most of the time, you can expect a simple box with an image, and a overlay, with a transparent black background and white font color. Even if you can predict that it could easily turn to [...]]]></description>
			<content:encoded><![CDATA[<p>Since few years, coverflows have been successfull. The best way to show lots of things in a small space.</p>
<p>Most of the time, you can expect a simple box with an image, and a overlay, with a transparent black background and white font color. Even if you can predict that it could easily turn to crap, and teach your client about it, most of the time, what you predicted comes to reality.<span id="more-21"></span></p>
<p>With a bright image, if the black background is too opaque, you loose some data about the image, and more, you change the perception you had about shape of the image. If the black background is too transparent, you may find the white font unreadable very quickly.</p>
<div class='center'><img class="aligncenter size-full wp-image-22" title="illusion" src="http://blog.martian-arts.org/wp-content/uploads/2011/07/illusion.jpg" alt="" width="200" height="100" /></div>
<p>So i went up with this stupid and almost useless idea to adapt the alpha of the background depending on what&#8217;s behind. That way, wherever the overlay could be, the alpha would always be the way it should to provide a good compromize between the visibility of the image and the readability of the font.</p>
<p>For a small proof of concept, i just put 4 greys and tried differents overlay. To see what i meant with visibility and readability, i made those overlays draggable:</p>
<div>
    <div id="flash1">
      
    </div>
</div>
<p>I turned to be usefull with a real image:</p>
<div class='center'>
    <div id="flash2">
      
    </div>
</div>
<p>Here, i put the .8 alpha overlay on the eye, to show how a too opaque background could hide image data ; and the .2 alpha overlay on a bright shoulder to show that a too transparent background could affect the readability of a text. The perfect case would be to switch them but&#8230; they&#8217;re still different (.8 vs .2 alpha). The dynamic overlay fits everywhere correctly !</p>
<p>I used a small object for my overlay. I think the methods written are clear enough.</p>
<pre class="brush: as3; title: ; notranslate">
var rect:Rectangle = new Rectangle(overlay.x, overlay.y, overlay.width, overlay.height);
var ba:ByteArray = image.bitmapData.getPixels(rect);

ba.position = 0;
var total:uint, color:Array;
while (ba.position &lt; ba.length)
{
	color = int2rgb(ba.readUnsignedInt() - 0xff000000);
	total += color[0] &lt; color[1] ? color[1] &lt; color[2] ? color[2] : color[1] : color[0];
}

var average:Number = (total / luminosity.position) / 100;
var ratio:Number = total / (0xff * luminosity.position);

overlay.refresh({ text:'dynamic alpha (' + average.toFixed(2) + ')', alpha:average });
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/dynamic-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://blog.martian-arts.org/hello-world/</link>
		<comments>http://blog.martian-arts.org/hello-world/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 20:49:15 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=1</guid>
		<description><![CDATA[I&#8217;m back. It&#8217;s a big reset, and i wish i&#8217;ll be able to re-post old things i kept somewhere on my hard drive. I expect more blogposts on subjects i care about. More as3, more php, more code. &#160; &#160; Moar !]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back. <span id="more-1"></span>It&#8217;s a big reset, and i wish i&#8217;ll be able to re-post old things i kept somewhere on my hard drive.</p>
<p>I expect more blogposts on subjects i care about. More as3, more php, more code.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Moar !</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.martian-arts.org/feed/ ) in 1.18190 seconds, on Feb 7th, 2012 at 8:52 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 7th, 2012 at 9:52 am UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  blog.martian-arts.org/feed/ ) in 0.00059 seconds, on Feb 7th, 2012 at 9:15 am UTC. -->
