<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://flex.scoutant.org/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>A Flex &amp; Adobe AIR Blog</title>
  <link>http://flex.scoutant.org/</link>
  <atom:link href="http://flex.scoutant.org/feed/rss2" rel="self" type="application/rss+xml"/>
  <description>Technical Blog on Flex, AS3 and Adobe AIR. Rich Internet Application, Rich Desktop Application. Drag &amp; Drop, AMF3 remoting with BlazeDS, E4X, Build Maven with Flex-mojos, SWFobject, FlexBuilder, Flash Catalyst, Flex4, FlashPlayer10, etc.</description>
  <language>en</language>
  <pubDate>Mon, 11 Jul 2011 08:24:13 +0200</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Un &quot;Hello 3D World&quot; en Blender, animé en Flash avec Papervision3D</title>
    <link>http://flex.scoutant.org/post/2010/02/Un-Hello-3D-World-en-Blender-anime-avec-Papervision3D</link>
    <guid isPermaLink="false">urn:md5:93405a372076b105b14e41dbc08c0d29</guid>
    <pubDate>Fri, 26 Feb 2010 21:35:00 +0100</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>3D</category><category>blender</category><category>collada</category><category>papervision</category><category>shading</category>    
    <description>    &lt;h3&gt;Démo&lt;/h3&gt;

&lt;p&gt;Passez la souris sur l'objet 3D ci-dessous...&lt;/p&gt;
	&lt;div  id=&quot;lego0&quot;&gt;You need JavaScript enabled!&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	       var flashvars =  {
	       };
	       swfobject.embedSWF(&quot;http://flex.scoutant.org/assets/LegoWithLightAndShader.swf&quot;, &quot;lego0&quot;, &quot;1000&quot;, &quot;500&quot;, &quot;10.0.0&quot;,&quot;expressInstall.swf&quot;, flashvars, {wmode:&quot;transparent&quot;} );
	&lt;/script&gt;



&lt;p&gt;Ouai, c'est donc un Hello World pour valider l'intégration du modeleur 3D Blender avec la librairie Papervision3D pour application Flash.&lt;/p&gt;


&lt;p&gt;Avec aussi animation de rotation 3D et le calcul d'ombres temps réel qui va avec...&lt;/p&gt;


&lt;h3&gt;Modélisation Blender et export au format Collada&lt;/h3&gt;

&lt;p&gt;Bon, quelque soit le modeleur 3D qu'on utilise (3ds Max, Maya, SketchUp, Blender), au départ il y a un petit temps d'apprentissage.&lt;/p&gt;


&lt;p&gt;Avec blender.org, on est en plein dans le développement durable&amp;nbsp;: logiciel libre, multi-plateforme. Ya plein de doc en ligne et pour n'en citer qu'une&amp;nbsp;: &lt;a href=&quot;http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro&quot;&gt;http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Après s'être familiarisé aux divers raccourcis clavier et techniques de modélisation comme l'extrusion, on peut construire sa première scène 3D.&lt;/p&gt;


&lt;p&gt;Ensuite on peut exporter au format COLLADA. Un format d'échange standard en XML. Avec Blender, c'est simplement File&amp;gt;Export&amp;gt;Collada 1.4. On cochera les options&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Triangles&lt;/li&gt;
&lt;li&gt;Only export selection&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Effectivement notre librarie Papervision 3D fonctionne exclusievment par modélisation à l'aide de triangles.&lt;/p&gt;


&lt;h3&gt;Import dans appli Flash avec librairie Papervision 3D&lt;/h3&gt;

&lt;h5&gt;Mise en place du projet Flex avec Papervision3D&lt;/h5&gt;

&lt;p&gt;Donc maintenant on est dans Eclipse avec typiquement Flash Builder 4. Enfin moi je préfère Flex Builder 3 / Linux.
Ya plus qu'à télécharger Papervision3D&amp;nbsp;: &lt;a href=&quot;http://code.google.com/p/papervision3d&quot;&gt;http://code.google.com/p/papervision3d&lt;/a&gt;. Au choix directement la librairie .swc ou alors le .zip avec le code source.&lt;/p&gt;


&lt;p&gt;Pour explication des concepts de base de papervision3d on pourra juste lire l'article&amp;nbsp;: &lt;a href=&quot;http://www.packtpub.com/article/building-first-application-with-papervision3d-part2&quot;&gt;first-application-with-papervision3d&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Effectivement il faut saisir le pourquoi de la source lumineuse et de la caméra et voir ou les placer par rapport à l'objet cible.&lt;/p&gt;


&lt;p&gt;Un modèle de projet évoqué dans la partie &quot;smart programmers use less code&quot;, servira de base. Ca peut servir de base, par exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;class&lt;/span&gt; LegoWithLightAndShader &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;extends&lt;/span&gt; BasicView &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; LegoWithLightAndShader&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;true&lt;/span&gt;, &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      init&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; model:DisplayObject3D;
    &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; init&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    opaqueBackground = 0xffffff;
      camera.&lt;span style=&quot;color: #006600;&quot;&gt;x&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;;
      camera.&lt;span style=&quot;color: #006600;&quot;&gt;y&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;400&lt;/span&gt;;
      camera.&lt;span style=&quot;color: #006600;&quot;&gt;z&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;-550&lt;/span&gt;;
&amp;nbsp;
      light = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; PointLight3D&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      light.&lt;span style=&quot;color: #006600;&quot;&gt;x&lt;/span&gt; =  &lt;span style=&quot;color: #CC0000;&quot;&gt;100&lt;/span&gt;;
      light.&lt;span style=&quot;color: #006600;&quot;&gt;y&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;1000&lt;/span&gt;;
      light.&lt;span style=&quot;color: #006600;&quot;&gt;z&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;-700&lt;/span&gt;;&lt;/pre&gt;


&lt;h5&gt;Import du modèle .dae&lt;/h5&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; model:DisplayObject3D;
		model = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; DAE&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
		&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;model &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;as&lt;/span&gt; DAE&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;load&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;assets/MyLegoSample.dae&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;Donc on le voit, l'import est très simple. Suffit de sourcer le fichier .dae.&lt;/p&gt;

&lt;h5&gt;Annimation de rotation via la souris&lt;/h5&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; vpX:Number = stage.&lt;span style=&quot;color: #006600;&quot;&gt;stageWidth&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;;
    &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; vpY:Number = stage.&lt;span style=&quot;color: #006600;&quot;&gt;stageHeight&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;;
    override &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; onRenderTick&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;event:Event=&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; angleX:Number = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;mouseY - vpY&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt; .&lt;span style=&quot;color: #CC0000;&quot;&gt;5&lt;/span&gt;;
      &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; angleY:Number = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;mouseX - vpX&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt; .&lt;span style=&quot;color: #CC0000;&quot;&gt;5&lt;/span&gt;;
      model.&lt;span style=&quot;color: #006600;&quot;&gt;rotationZ&lt;/span&gt; = -angleY;
      model.&lt;span style=&quot;color: #006600;&quot;&gt;rotationX&lt;/span&gt; = -angleX;
      &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;super&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;onRenderTick&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;event&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Oui, on peut choisir d'effectuer une rotation du modèle sur la base de la distance de la souris par rapport au milieu de l'écran.
Maintenant, on a une animation correcte, mais le résultat est beaucoup trop médiocre.&lt;/p&gt;
	&lt;div  id=&quot;lego1&quot;&gt;You need JavaScript enabled!&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	       var flashvars =  {
	       };
	       swfobject.embedSWF(&quot;http://flex.scoutant.org/assets/Lego.swf&quot;, &quot;lego1&quot;, &quot;700&quot;, &quot;300&quot;, &quot;10.0.0&quot;,&quot;expressInstall.swf&quot;, flashvars, {wmode:&quot;transparent&quot;} );
	&lt;/script&gt;


&lt;p&gt;Effectivement, on n'a pas de gestion d'ombres&amp;nbsp;: les arrêtes ne se démarquent pas et on ne voit de distinction entre les faces. Alors que les yeux et le cerveau ont l'habitude de reconstituer le 3D justement via des modifications d'intensités lumineuses entre les faces de l'objet...&lt;/p&gt;



&lt;h3&gt;Gestion des ombres&lt;/h3&gt;

&lt;h5&gt;Matériaux et import Blender -&amp;gt; Papervision&lt;/h5&gt;

&lt;p&gt;On peut avoir fait une modélisation Blender avec des matériaux présentant réflexion et réfraction. Mais à l'import du .dae, ceci est perdu et le modèle papervision3d instancié ne présente que des matériaux &lt;em&gt;ColorMeterial&lt;/em&gt;. Donc sans calcul d'effet de lumière!&lt;/p&gt;


&lt;h5&gt;Choix des matériaux dans Papervision3D&lt;/h5&gt;

&lt;p&gt;Au prix d'un surcoût CPU, on peut induire papervision à une gestion fine de la lumière. Au lieu de ColorMaterial, on optera pour&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;FlatShadeMaterial&lt;/li&gt;
&lt;li&gt;GouraudMaterial&lt;/li&gt;
&lt;li&gt;PhongMaterial&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour le premier, il s'agit d'un calcul global pour chaque face (triangle) de l'objet par rapport à la source lumineuse.
&lt;img src=&quot;http://flex.scoutant.org/public/papervision3d-light.jpg&quot; alt=&quot;p3d-light&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;p3d-light, fév 2010&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Le dernier est beaucoup plus réaliste (et couteux) avec une approche pixel par pixel. Le deuxième est un compromis&amp;nbsp;: calcul triangle par triangle et interpolation pixel par pixel.&lt;/p&gt;


&lt;p&gt;Pour notre Hello 3D World, très cubique, la première approche est parfaite.&lt;/p&gt;


&lt;h5&gt;Remplacement des materiaux en runtime&lt;/h5&gt;

&lt;p&gt;Reste à remplacer le ColorMaterial introduit lors de l'import par une instance de FlatShadeMaterial.&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;model.&lt;span style=&quot;color: #006600;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;FileLoadEvent.&lt;span style=&quot;color: #006600;&quot;&gt;LOAD_COMPLETE&lt;/span&gt;,modelLoaded&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
	&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; modelLoaded&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;e:FileLoadEvent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt;		&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
   		model.&lt;span style=&quot;color: #006600;&quot;&gt;replaceMaterialByName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; FlatShadeMaterial&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;light, 0xFFEEFF, 0x220000&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;RED&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Il suffit d'utiliser la méthode replaceMaterialByName(). Et de remplacer le matériaux dans le dictionnaire relatif à l'objet. Tout simplement!&lt;/p&gt;


&lt;p&gt;On trouve plusieurs posts qui font état d'un fonctionnement étrange de Papervision (en tout cas jusqu'à 2.1). On peut tenter d'instancier un MaterialList, d'ajouter le matériau cible et de remplacer l'ancien via model.materials = ... Mais ceci n'a pas d'effet. Pourquoi?&lt;/p&gt;


&lt;p&gt;Bon, on n'a pas toujours réponse à tout. L'essentiel est d'avoir une solution qui marche.&lt;/p&gt;


&lt;p&gt;C'était la démo présentée en introduction.&lt;/p&gt;


&lt;p&gt;Avec ce Hello 3D World, on a vu le chemin d'intégration Blender -&amp;gt; Papervision 3D. Incluant animation de rotation et surtout gestion réaliste de la lumière.&lt;/p&gt;


&lt;h3&gt;Sculpture numérique et visite virtuelle&lt;/h3&gt;

&lt;p&gt;On pourra maintenant sereinement retourner à Blender et faire un peu de sculpture numérique. On sait qu'on pourra ensuite exposer son chef d'oeuvre dans une simple application Flash, permettant au public une découverte sous tous les angles...&lt;/p&gt;


&lt;p&gt;Si on fait une modélisation avec lissage, on préfèrera alors la mise en oeuvre d'un PhongMaterial, pour un calcul pixel par pixel de la lumière et un rendu des plus réalistes.&lt;/p&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>FlexUnit4 and Flash Builder 4 in action -  A FlexUnit4-power TDD Use case</title>
    <link>http://flex.scoutant.org/post/2009/10/FlexUnit4-and-Flash-Builder-4-in-action-A-FlexUnit4-powered-TDD-Use-Case</link>
    <guid isPermaLink="false">urn:md5:675c9259f2e066c7ffc56455c3fa26b2</guid>
    <pubDate>Wed, 28 Oct 2009 21:38:00 +0100</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>as3</category><category>flashbuilder4</category><category>flex</category><category>flexunit</category><category>flexunit4</category><category>tdd</category>    
    <description>    &lt;h3&gt;FlexUnit4 Use case&amp;nbsp;: a Reverse Polish Notation Calculator&lt;/h3&gt;

	&lt;div  id=&quot;rpn0&quot;&gt;You need JavaScript enabled!&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		swfobject.embedSWF(&quot;http://flex.scoutant.org/assets/rpn.swf &quot;, &quot;rpn0&quot;, &quot;374&quot;, &quot;210&quot;, &quot;10.0.0&quot;,&quot;expressInstall.swf&quot;);
	&lt;/script&gt;



&lt;p&gt;A nice introduction is the Wikipedia page on Reverse Polish Notation &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/#pnote-14-1&quot; id=&quot;rev-pnote-14-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;&lt;q&gt;In Reverse Polish notation the operators follow their operands; for instance, to add three and four, one would write &quot;3 4 +&quot;&lt;/q&gt;.&lt;/p&gt;


&lt;p&gt;Let's play with the calculator above. It is a live Flash application.&lt;/p&gt;


&lt;p&gt;Type some digits and press ENTER so as to push a number to the stack. When you have two numbers in the stack you can hit a binary operator key like '+' or '*'. The 2 operands will be consumed and the result will be push to the stack.
As an option you can use keyboard shortcuts.&lt;/p&gt;


&lt;p&gt;The requirements are easy to express. And present use case is prone to a test-driven development approach. And in our simple case, it is realy close to feature-driven development.&lt;/p&gt;


&lt;h3&gt;Test-driven development&lt;/h3&gt;

&lt;p&gt;Googling, you'll find many references and even books on TDD.&lt;/p&gt;


&lt;p&gt;To make it short , the point is to write the test code &lt;strong&gt;before&lt;/strong&gt; the target code.&lt;/p&gt;


&lt;p&gt;So we have micro development cycle&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;adding a test method and do the least for the test to compile&lt;/li&gt;
&lt;li&gt;run the unit test and notice that it &lt;em&gt;fails&lt;/em&gt;&amp;nbsp;: RED state in the unit-test report panel&lt;/li&gt;
&lt;li&gt;implement the target logic&amp;nbsp;: you are not finised until the unit test succeed&amp;nbsp;: GREEN state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All the unit test are independent one from each other. So that they can be cumulated in unit-test campain that are to be run before any code is commited.&lt;/p&gt;


&lt;p&gt;With that test automation infrastucture, you can now feel confident to refactor often your code&amp;nbsp;: within some seconds you can have feedback in case of any regression.&lt;/p&gt;


&lt;p&gt;But what about TDD for AS3 and Flex developpement?&lt;/p&gt;


&lt;h3&gt;ActionScript and Flex TDD out there?&lt;/h3&gt;

&lt;p&gt;It's true, there are not that many reference on test-driven development when talking about GUI.&lt;/p&gt;


&lt;p&gt;Okay you will find the FlexUnit page @ Adobe Dev Net &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/#pnote-14-2&quot; id=&quot;rev-pnote-14-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;. And some other references.&lt;/p&gt;


&lt;p&gt;But FlexUnit is not integrated to Flex Builder, so that very few project have adopted a true TDD approach.&lt;/p&gt;



&lt;h3&gt;Next generation FlexUnit4 and Flash Builder 4 enabling true AS3/Flex TDD&lt;/h3&gt;

&lt;p&gt;Compared to Flex Builder 3, Flash Builder 4 comes with a major feature&amp;nbsp;: a true unit testing support.
With both&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;TestCase class generation wizards and&lt;/li&gt;
&lt;li&gt;the possibility to run a TestCase from the IDE without the bowler-plate of defining any test suite nor test app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;http://flex.scoutant.org/public/FB-wizard.png&quot;&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.FB-wizard_m.jpg&quot; alt=&quot;FB-wizard2&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;FB-wizard2, oct 2009&quot; /&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Moreover, after (too) many years of FlexUnit 0.90, Adobe has at least decided to put some effort in a next generation unit-test framework. We have a upcoming FlexUnit4 framework &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/#pnote-14-3&quot; id=&quot;rev-pnote-14-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;As you can see, it's an adaptation of JUnit4, the annotation-driven unit-test java support. Comprehensive illustration following at this post&amp;nbsp;: &lt;a href=&quot;http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html&quot;&gt;http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html &lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;A true development workflow sample will surely best describe the benefits of the soon to be released tdd support with Flex4 ecosystem.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://flex.scoutant.org/public/FB-flexunit4-wizard.png&quot;&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.FB-flexunit4-wizard_m.jpg&quot; alt=&quot;FB4-flexunit4&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;FB4-flexunit4, oct 2009&quot; /&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Today we will use the available releases&amp;nbsp;: Flash Builder 4 beta 2 and FlexUnit4 beta 2 turnkey distribution. I suppose FlexUnit4 will be fully integrated to the IDE, but with beta release, a last step is necessary o set up the environnement.&lt;/p&gt;


&lt;p&gt;FlexUnit4 Turnkey distribution is a Flex4 project you can import with Flash Builder 4 Import wizard.&lt;/p&gt;



&lt;h3&gt;A step by step true TDD sample&amp;nbsp;: writing the AS3 test cases before the target code&lt;/h3&gt;


&lt;p&gt;Let's write AS3/Flex code meeting the RPN Calculator requirements. Let's create a Flex projet, called rpn.
The TDD-style drives us to first write the TestCase. Let's do so using the 2 wizards mentionned above.&lt;/p&gt;


&lt;h4&gt;Create an  AS3 TestCase class using wizard&lt;/h4&gt;

&lt;p&gt;Let's instanciate a Calculator from the FlexUnit4-powered CalculatorTest class below&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;package&lt;/span&gt; org.&lt;span style=&quot;color: #006600;&quot;&gt;scoutant&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;rpn&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;class&lt;/span&gt; CalculatorTest &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;	
		&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;protected&lt;/span&gt; static &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; calculator:Calculator = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; Calculator&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
		&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Notice how our test case does not need to inherit any test case base class (as with FlexUnit 0.90).
Obviously, it won't compile&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://flex.scoutant.org/public/tdd-2.jpg&quot; alt=&quot;tdd-2&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;tdd-2, oct 2009&quot; /&gt;&lt;/p&gt;


&lt;p&gt;We need to define the Calculator class.&lt;/p&gt;


&lt;h4&gt;Create now the target class&lt;/h4&gt;

&lt;p&gt;JUnit4 integration within Eclipse is somewhat more powerfull&amp;nbsp;: the quick-fix feature suggest the Java developer the generation of corresponding class. With Flash Builder 4 beta2, we'll have to do it manually. But this is not a big deal.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;package&lt;/span&gt; org.&lt;span style=&quot;color: #006600;&quot;&gt;scoutant&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;rpn&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;class&lt;/span&gt; Calculator &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; Calculator&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Okay, now it compiles. We can begin the the iterative tdd workflow at method level.&lt;/p&gt;


&lt;h4&gt;Create a FlexUnit4 test method&lt;/h4&gt;


&lt;h5&gt;Writing unit-test method code&lt;/h5&gt;

&lt;p&gt;Let's consider the single following feature&amp;nbsp;: pressing the &lt;em&gt;digits&lt;/em&gt; composing a number and when done&amp;nbsp;: validating with an &lt;strong&gt;enter&lt;/strong&gt; action. And notice how the number is now on top of the stack. An AS3 represnetation of that could be&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; enteringAnOperand&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  Assert.&lt;span style=&quot;color: #006600;&quot;&gt;assertEquals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;3&lt;/span&gt;, calculator.&lt;span style=&quot;color: #006600;&quot;&gt;peak&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The test method name does not matter. With FlexUnit4 it does not need to be prefixed by test. What matter is the &lt;strong&gt;&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/Test&quot; title=&quot;Test&quot;&gt;Test&lt;/a&gt;&lt;/strong&gt; metadata. Just like JUnit 4 is based on Java annotations.&lt;/p&gt;


&lt;p&gt;Now we have the unit test. It does not compile&amp;nbsp;:&lt;/p&gt;


&lt;h5&gt;If needed adding the API code for the test to compile&lt;/h5&gt;

&lt;p&gt;Let's just define the mentionned enter(.) and peak() method.&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; enter&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;operand : Number&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; peak&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;index:int = &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : Number &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; NaN;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now it compile. We can run the test. To do so with beta2 release, we need to select the test case in the explorer view&amp;nbsp;: the contextual menu, with right click, shows &lt;strong&gt;Executes FlexUnit Tests&lt;/strong&gt;.
Of course the test fails. But we have bow the test infrastucture up and we can focus on implementing the target logic.&lt;/p&gt;


&lt;h4&gt;Implement the logic meeting that small piece of requirment.&lt;/h4&gt;

&lt;p&gt;A little bit of design&amp;nbsp;: the Calculator requirement are somewhat similar to a Last-in first-out stack:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;pushing items,&lt;/li&gt;
&lt;li&gt;popping the two top-most items so as to operate them&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hence, our Calculator class may be based on an AS Array. Yes, the Array API comes with push(.) and pop() methods.&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; stack : Array = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; enter&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;operand : Number&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	stack.&lt;span style=&quot;color: #006600;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; operand&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; peak&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;index:int = &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : Number &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; stack&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; index &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now we run the test and it turns to GREEN.&lt;/p&gt;


&lt;p&gt;We are done with the feature. BUT a unique test  for a feature may not be enough a validation.&lt;/p&gt;


&lt;h4&gt;a second unit-test method for same feature&lt;/h4&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; enteringTwoOperandsAndReadin&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	Assert.&lt;span style=&quot;color: #006600;&quot;&gt;assertEquals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;6&lt;/span&gt;, calculator.&lt;span style=&quot;color: #006600;&quot;&gt;peak&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The test above test that the number that is pushed last, is actually retrieved by peak() method.
The test compiles, let's run it to verify that the test passes.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://flex.scoutant.org/public/tdd-4.png&quot; alt=&quot;tdd-4&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;tdd-4, oct 2009&quot; /&gt;&lt;/p&gt;


&lt;h4&gt;Fixing the bug&lt;/h4&gt;

&lt;p&gt;It is not expected, the test fails! we have the RED bar. We must fix that before considering any other feature.&lt;/p&gt;


&lt;p&gt;Notice the advantage of our tdd approach and it's micro cycles. The bug introduced by the implementation above is discovered with a minute of time!&lt;/p&gt;


&lt;p&gt;We know that the cost of a bug is exponential to the time elapsed since it was intoduced. Here our tdd approach will minimize that cost.&lt;/p&gt;


&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; peak&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;index:int = &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : Number &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; stack&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; stack.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;-1&lt;/span&gt; - index &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Yes the AS3 Array has a stack API&amp;nbsp;: push(.) and pop(). But no peaking feature. Our first implementation was not LIFO-consistent.&lt;/p&gt;


&lt;p&gt;After refactoring the index as above. We can run the test-case. We can see how the last test turns GREEN.&lt;/p&gt;


&lt;p&gt;We can now consider next feature, for instance &lt;em&gt;adding two operands&lt;/em&gt;.&lt;/p&gt;


&lt;h4&gt;TDD of next feature&amp;nbsp;: adding two operands&lt;/h4&gt;

&lt;h5&gt;implementing a test method&lt;/h5&gt;

&lt;p&gt;Let's enter 2 operands and hit the &quot;+&quot; operator. We want the 2 last operands to be consumed and the sum to be push into the stack. A test may be&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; addingTwoOperands&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:
	Assert.&lt;span style=&quot;color: #006600;&quot;&gt;assertEquals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;9&lt;/span&gt;, calculate.&lt;span style=&quot;color: #006600;&quot;&gt;peak&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;For the test to compile we need to define the methode add() .We can begin with an empty method body. The test compiles.&lt;/p&gt;


&lt;p&gt;We run it and we have the RED state.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt; implementing the logic 
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; add&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	stack.&lt;span style=&quot;color: #006600;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; + stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;With the above implementation our test turns to GREEN.
&lt;img src=&quot;http://flex.scoutant.org/public/tdd-5.png&quot; alt=&quot;tdd-5&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;tdd-5, oct 2009&quot; /&gt;&lt;/p&gt;

&lt;h5&gt;Expressing an espected Error with FlexUnit4&lt;/h5&gt;

&lt;p&gt;As in previous cycle we'll add more test to validate the target add() method.&lt;/p&gt;


&lt;p&gt;The &quot;+&quot; operator is assuming to find two operands in the stack. If none or only one is available &lt;em&gt;we want the calculator to raise an error&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;The GUI shall give an error feedback the the user.&lt;/p&gt;


&lt;p&gt;Compared to FlexUnit 0.90, FlexUnit4 provides an interesting feature. The possibility to express that a test is supposed to raise an error.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;expects=&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; addingButNoOperand&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
We are mentionning that we expect an error: &lt;em&gt;the test case will be green if we actually have the error&lt;/em&gt;.
Let's run the test.
&lt;img src=&quot;http://flex.scoutant.org/public/tdd-6.png&quot; alt=&quot;tdd-6&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;tdd-6, oct 2009&quot; /&gt;&lt;/p&gt;


&lt;h5&gt;Fixing the bug&lt;/h5&gt;

&lt;p&gt;We expect our add() method to raise an error. But corresponding assertion (expects=&quot;Error&quot;) is not validated.&lt;/p&gt;


&lt;p&gt;We need to refactor our add() implementation. Looking att the AS3 Array reference documentation, we discover that popping an empty array does raise an Error but silently returns &lt;em&gt;null&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;We are not happy with that so let's add an applicative precondition and raise an ArgumentError if the stack has less that 2 operands.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; add&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;stack.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ArgumentError&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; 
	stack.&lt;span style=&quot;color: #006600;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; + stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now , running the test, yes it is GREEN.
Let's add a second test, just to be sure that if we none operand, we do have an error too:&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;expects=&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; addingButNoOperand&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The test case is still GREEN.&lt;/p&gt;

&lt;h5&gt;More tests for same feature&lt;/h5&gt;

&lt;p&gt;Lets add a test case with negative number and mixing integrer and Numbers...&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; addingNegativeOperand&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;-3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;-6&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
	Assert.&lt;span style=&quot;color: #006600;&quot;&gt;assertEquals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;-9&lt;/span&gt;, calculator.&lt;span style=&quot;color: #006600;&quot;&gt;peak&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; addingIntegerAndNumberOperand&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;6.1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
	Assert.&lt;span style=&quot;color: #006600;&quot;&gt;assertEquals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;9.1&lt;/span&gt;, calculator.&lt;span style=&quot;color: #006600;&quot;&gt;peak&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Still GREEN. we can can confidently consider implementing next feature.&lt;/p&gt;

&lt;h4&gt;TDD of similar feature (multiply operand)&amp;nbsp;: copy and paste both the test fixture and the business logic&lt;/h4&gt;

&lt;p&gt;We can feel that the &quot;*&quot; operator is very much similar to the &quot;+&quot;. Both are binary and symetrical. The code can be very similar.
We can copy and paste both the test methods and the target logic.&lt;/p&gt;


&lt;p&gt;But to prevent any mismatch, best is to abide to the &lt;strong&gt;RED before GREEN&lt;/strong&gt; principle.
So we can copy and adapt the test fixture. And verify the no compilation or the RED state.&lt;/p&gt;

&lt;h4&gt;TDD of next feature (substract operand)&lt;/h4&gt;

&lt;p&gt;Operating as above, we first provide the test fixture mentionning a substract(). Compile error.
And by similarity we provide following implementation&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; substract&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;stack.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ArgumentError&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; 
	stack.&lt;span style=&quot;color: #006600;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; - stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;We just replaced &quot;+&quot; by &quot;-&quot; in the implementation. We can run the test.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://flex.scoutant.org/public/tdd-7.png&quot; alt=&quot;tdd-7&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;tdd-7, oct 2009&quot; /&gt;&lt;/p&gt;


&lt;h5&gt;Fixing the bug&lt;/h5&gt;

&lt;p&gt;It's NOT green.
We must correct the implementation!
The Substract operator is not symetrical&amp;nbsp;; and obviously the add template has to be adapted&amp;nbsp;:
Let's replace with&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; substract&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;stack.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ArgumentError&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; 
	stack.&lt;span style=&quot;color: #006600;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; - stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; + stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now it turn to green. Thanks to our TDD approach we corrected the bug no later that 30 seconds after the bug was introduced.&lt;/p&gt;


&lt;p&gt;Let's go on with division operator.&lt;/p&gt;



&lt;h4&gt;Next feature ( division operator)&lt;/h4&gt;

&lt;p&gt;The operator is not symetrical and we'll take care.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; divideTwoOperands&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;divide&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	Assert.&lt;span style=&quot;color: #006600;&quot;&gt;assertEquals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;4&lt;/span&gt;, calculator.&lt;span style=&quot;color: #006600;&quot;&gt;peak&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Let's implement the missing divide() method. It is a binary and orientated operator like the substract one. Let's take it as template&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; divide&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;stack.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ArgumentError&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; 
	&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; dividend:Number = stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; 
	stack.&lt;span style=&quot;color: #006600;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt; dividend &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Here no surprise, it's GREEN.&lt;/p&gt;


&lt;h4&gt;Next feature ( unary square root operator)&lt;/h4&gt;

&lt;h5&gt;unit-test fixture and target implementation&lt;/h5&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; squarreAnOperand&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;1024&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	Assert.&lt;span style=&quot;color: #006600;&quot;&gt;assertEquals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;32&lt;/span&gt;, calculator.&lt;span style=&quot;color: #006600;&quot;&gt;peak&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;			
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Not compiling. We add en empty sqrt() implementation. RED state.&lt;/p&gt;


&lt;p&gt;We may consolidate with following implementation.&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; sqrt&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;stack.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ArgumentError&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; 
	stack.&lt;span style=&quot;color: #006600;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; Math.&lt;span style=&quot;color: #006600;&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now it turns GREEN.&lt;/p&gt;


&lt;h5&gt;Additional fixture for square root of negative number&lt;/h5&gt;

&lt;p&gt;Let's add an additional test fixture. For a negative number we want an error (we are not onsidering complex number).&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Test &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;expects=&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; squareRootNegativeNumber&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;enter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;-1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	calculator.&lt;span style=&quot;color: #006600;&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Result.
&lt;img src=&quot;http://flex.scoutant.org/public/tdd-8.png&quot; alt=&quot;tdd-8&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;tdd-8, oct 2009&quot; /&gt;&lt;/p&gt;



&lt;h5&gt;Fixing the expectation&lt;/h5&gt;

&lt;p&gt;It is NOT green. We expected an Error.&lt;/p&gt;


&lt;p&gt;But diving into the AS3 doc, we can see that Math.sqrt() calculation actually does not raise an error for negative nymbers&amp;nbsp;: it just returns NaN...&lt;/p&gt;


&lt;p&gt;Let's manually raise the expected Error.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; sqrt&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;stack.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ArgumentError&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;peak&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ArgumentError&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
	stack.&lt;span style=&quot;color: #006600;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; Math.&lt;span style=&quot;color: #006600;&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; stack.&lt;span style=&quot;color: #006600;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now it's GREEN.&lt;/p&gt;


&lt;p&gt;Now our Calculation logic seems to be finished.&lt;/p&gt;


&lt;p&gt;Next step is to wrap it with the GUI components.&lt;/p&gt;


&lt;h3&gt;GUI wrapping&lt;/h3&gt;

&lt;p&gt;We can now develop the GUI against our unit-test Calculator class.
Not only the Calculator class is tested but moreover the feature are clear.
We have a somewhat a feature-driven approach.&lt;/p&gt;


&lt;p&gt;Now we can take advantage of one of Flex4 main feature&amp;nbsp;: the FXG skinning architecture. We can first develop a squetch GUI based on simple buttons.&lt;/p&gt;

&lt;h4&gt;Micro architecture&lt;/h4&gt;

&lt;p&gt;We have the Calculator.as logic.&lt;/p&gt;


&lt;p&gt;We'll implement a rpn.mxml application. Our RPN Calculator mostly has a &lt;strong&gt;sreen&lt;/strong&gt; representing the stack and buttons&amp;nbsp;: digits and operator.&lt;/p&gt;


&lt;p&gt;Bas practice is to consider all the GUI stuff in a single .mxml file. Even more when targetting Flex4 FXG skinning feature.&lt;/p&gt;


&lt;p&gt;We'll at least consider Digit.mxml an Operator.mxml files.&lt;/p&gt;


&lt;h4&gt;Component layout&lt;/h4&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Application&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;xmlns:fx&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://ns.adobe.com/mxml/2009&amp;quot;&lt;/span&gt; 
  &lt;span style=&quot;color: #000066;&quot;&gt;xmlns:s&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;library://ns.adobe.com/flex/spark&amp;quot;&lt;/span&gt; 
  &lt;span style=&quot;color: #000066;&quot;&gt;xmlns:rpn&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;org.scoutant.rpn.*&amp;quot;&lt;/span&gt;
  &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:layout&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:VerticalLayout&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/s:layout&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;fx:Script&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;![CDATA[&lt;/span&gt;
&lt;span style=&quot;color: #339933;&quot;&gt;  [Bindable] public var calculator:org.scoutant.rpn.Calculator = new org.scoutant.rpn.Calculator();&lt;/span&gt;
&lt;span style=&quot;color: #339933;&quot;&gt;  [Bindable] public var line:String = &amp;quot;&amp;quot;;&lt;/span&gt;
&lt;span style=&quot;color: #339933;&quot;&gt;  ]]&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/fx:Script&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
. . .
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:SkinnableContainer&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:layout&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:HorizontalLayout&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/s:layout&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;rpn:Digit&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;_7&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;7&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;rpn:Digit&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;_8&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;8&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;rpn:Digit&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;_9&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;9&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;rpn:Operator&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;DIVIDE&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;operator&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{calculator.divide}&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Button&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1/x&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/s:SkinnableContainer&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
. . .&lt;/pre&gt;


&lt;h4&gt;Connecting the logic to the GUI&amp;nbsp;: with method inection&lt;/h4&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;rpn:Operator&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;DIVIDE&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;operator&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{calculator.divide}&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The line above is instanciating a component (named Operator.mxml here). And we are injecting an AS3 method&amp;nbsp;: &lt;em&gt;{calculator.divide}&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;The operator.mxml component is a normal Flex Button&amp;nbsp;: the click handler will execute the operator.&lt;/p&gt;


&lt;p&gt;The operator may be defined as a AS 3 variable of type Function. So that the function maybe injected as seen above.&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Button&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;xmlns:fx&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://ns.adobe.com/mxml/2009&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000066;&quot;&gt;xmlns:s&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;library://ns.adobe.com/flex/spark&amp;quot;&lt;/span&gt; 
  &lt;span style=&quot;color: #000066;&quot;&gt;click&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;execute()&amp;quot;&lt;/span&gt;
  &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;fx:Script&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;![CDATA[&lt;/span&gt;
&lt;span style=&quot;color: #339933;&quot;&gt;      [Bindable] public var operator:Function;&lt;/span&gt;
&lt;span style=&quot;color: #339933;&quot;&gt;      public function execute():void{&lt;/span&gt;
&lt;span style=&quot;color: #339933;&quot;&gt;        operator();&lt;/span&gt;
&lt;span style=&quot;color: #339933;&quot;&gt;      }&lt;/span&gt;
&lt;span style=&quot;color: #339933;&quot;&gt;    ]]&amp;gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/fx:Script&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/s:Button&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Above we could he logic  beeing invoqued with a user gesture&amp;nbsp;: hiting the &quot;DIVIDE&quot; button invoques the Calculator divide() method.&lt;/p&gt;


&lt;p&gt;As a feedback we expects now the &quot;sreen&quot; to be updated with the new stack content. Flex data-binding is the best friend for that!&lt;/p&gt;


&lt;h4&gt;Connecting the GUI to the logic&amp;nbsp;: with data-bindig&lt;/h4&gt;

&lt;p&gt;We cannot use the peak() method for the data-binding. We need to bind to a specfic property or accessor. It could be&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Label&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;textAlign&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;right&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000066;&quot;&gt;text&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{''+calculator.stack[calculator.stack.length-1]}&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Here the compiler warns us.
&lt;img src=&quot;http://flex.scoutant.org/public/tdd-9.png&quot; alt=&quot;tdd-9&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;tdd-9, oct 2009&quot; /&gt;&lt;/p&gt;


&lt;p&gt;I would say an other way&amp;nbsp;: the Array class is not an EventDispatcher.&lt;/p&gt;


&lt;p&gt;Hence we may refactor the Calculator class. We can wrap the Array with an ArrayCollection that is an EventDispatcher.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;class&lt;/span&gt; Calculator &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;		
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;Bindable&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; lifo:ArrayCollection = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ArrayCollection&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; stack : Array = lifo.&lt;span style=&quot;color: #006600;&quot;&gt;source&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Now we can express the data-binding with getItemAt(.) expression. Just like the compilatior Quick Fix suggested.&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Label&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;textAlign&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;right&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;text&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{''+calculator.lifo.getItemAt( calculator.lifo.length-1)}&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now the user has the desired feedback. HP 28 S Calculator &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/#pnote-14-4&quot; id=&quot;rev-pnote-14-4&quot;&gt;4&lt;/a&gt;]&lt;/sup&gt; has a 4-line screen, in a bottom up fashion. Could be&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Label&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;textAlign&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;right&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;text&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{''+calculator.lifo.getItemAt( calculator.lifo.length-4)}&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Label&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;textAlign&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;right&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;text&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{''+calculator.lifo.getItemAt( calculator.lifo.length-3)}&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Label&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;textAlign&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;right&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;text&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{''+calculator.lifo.getItemAt( calculator.lifo.length-2)}&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;s:Label&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;textAlign&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;right&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;text&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{''+calculator.lifo.getItemAt( calculator.lifo.length-1)}&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now we have a functionnal RPN Calculator.&lt;/p&gt;
	&lt;div  id=&quot;rpn&quot;&gt;You need JavaScript enabled!&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		swfobject.embedSWF(&quot;http://flex.scoutant.org/assets/rpn.swf &quot;, &quot;rpn&quot;, &quot;374&quot;, &quot;210&quot;, &quot;10.0.0&quot;,&quot;expressInstall.swf&quot;);
	&lt;/script&gt;



&lt;p&gt;It was not the point in present post, but all the components used here inherits from Flex 4 Spark &lt;strong&gt;SkinnableComponent&lt;/strong&gt;.
In next post, we'll see how to write &lt;em&gt;Skin&lt;/em&gt; mxml components. That can be referenced to as to have a nice RPN Calculator. With very few changes to our application, only specifying the skinClass property for our Skinnable Compoents...&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/#rev-pnote-14-1&quot; id=&quot;pnote-14-1&quot;&gt;1&lt;/a&gt;] Reverse Polish Notation : &lt;a href=&quot;http://en.wikipedia.org/wiki/Reverse_Polish_notation&quot;&gt; http://en.wikipedia.org/wiki/Reverse_Polish_notation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/#rev-pnote-14-2&quot; id=&quot;pnote-14-2&quot;&gt;2&lt;/a&gt;]  FlexUnit : &lt;a href=&quot;http://www.adobe.com/devnet/flex/articles/unit_testing.html&quot;&gt;Unit testing and Test Driven Development (TDD) for Flex and ActionScript 3.0 &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/#rev-pnote-14-3&quot; id=&quot;pnote-14-3&quot;&gt;3&lt;/a&gt;]  FlexUnit4 : &lt;a href=&quot;http://opensource.adobe.com/wiki/display/flexunit/FlexUnit+4+feature+overview&quot;&gt; Major New Features of FlexUnit 4 &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/10/#rev-pnote-14-4&quot; id=&quot;pnote-14-4&quot;&gt;4&lt;/a&gt;] HP 28 S Calculator : &lt;a href=&quot;http://mycalcdb.free.fr/galerie/HP/HP-28S.1.jpg&quot;&gt; photos &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
  <item>
    <title>Hosting a PHP proxy and enabling Flash app to talk cross-domain</title>
    <link>http://flex.scoutant.org/post/2009/04/Hosting-a-PHP-proxy-and-enabling-Flash-app-to-talk-cross-domain</link>
    <guid isPermaLink="false">urn:md5:e3eb109e6f78030accf3d61d0b34b5ee</guid>
    <pubDate>Mon, 27 Apr 2009 21:46:00 +0200</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>blazeds</category><category>crossdomain</category><category>googleappengine</category><category>googlemaps</category><category>php</category><category>proxy</category><category>velib</category>    
    <description>    &lt;p&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.velov-proxy_m.jpg&quot; alt=&quot;velov-proxy&quot; title=&quot;velov-proxy, avr 2009&quot; /&gt;&lt;/p&gt;


&lt;h3&gt;FlashPlayer and cross-domain policy file&lt;/h3&gt;

&lt;p&gt;FlashPlayer offre une politique de sécurité rassurante&amp;nbsp;: une application Flash chargée depuis un domaine A ne pourra consommer des services web depuis un autre domaine B.&lt;/p&gt;


&lt;p&gt;Il est possible de configurer cette politique de sécurité. Considérons que le domaine cible B juge qu'il est opportun de servir les requêtes issue d'une appli Flash téléchargée depuis le domaine A. Alors il suffit que B expose, à la racine, un fichier crossdomain.xml qui alloue les droits correspondants.&lt;/p&gt;


&lt;p&gt;Pour exemple, Delicious expose un fichier qui donne accès à toutes les appli Flash téléchargées depuis n'importe où&amp;nbsp;: &lt;a href=&quot;http://feeds.delicious.com/crossdomain.xml&quot;&gt; http://feeds.delicious.com/crossdomain.xml&lt;/a&gt;. Si vous suivez le lien, il faut éventuellement &lt;em&gt;Afficher le code source&lt;/em&gt;.&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;cross-domain-policy&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;allow-access-from&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;domain&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; 
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/cross-domain-policy&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;C'est ce qui a permis de faire l'animation Flash d'un nuage de tags Delicious,  &lt;a href=&quot;http://flex.scoutant.org/post/2008/11/DeliSphere-a-Flash-3D-animation-tagcloud-for-your-Delicious-bookmarks&quot;&gt; DeliSphere, a Flash 3D-animation tagcloud for your Delicious bookmarks &lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Google, Youtube, Fickr et d'autres exposent également une politique Flash-friendly&amp;nbsp;: par exemple&amp;nbsp;: &lt;a href=&quot;http://api.flickr.com/crossdomain.xml&quot;&gt; http://api.flickr.com/crossdomain.xml &lt;/a&gt;.&lt;/p&gt;


&lt;h3&gt;Un Proxy&amp;nbsp;!&lt;/h3&gt;

&lt;p&gt;Maintenant, si le provider de service n'est pas aussi accueillant pour les application Flash, on a la possibilité d'implanter un service de proxy qui prendra en charge de relayer les requêtes avec une autre technologie de client.  On implante un tel service dans le même domaine qui sert l'application Flash&amp;nbsp;: vis-à-vis de la VM FlashPlayer, on n'est plus dans une situation de cross-domain.&lt;/p&gt;


&lt;h4&gt;Proxy en Java avec BlazeDS&lt;/h4&gt;

&lt;p&gt;Adobe propose pour cela une solution toute prête. BlazeDS &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/04/#pnote-13-1&quot; id=&quot;rev-pnote-13-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;, la solution open-source de remoting AMF3, intègre un service de proxy.&lt;/p&gt;


&lt;p&gt;Coté développement Flex, il suffit alors tout simplement de positionner sur les divers objets de communication la propriété &lt;em&gt;useProxy&lt;/em&gt; en conséquence.&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:HTTPService&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;url&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;useProxy&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;BlazeDS est la meilleure solution que l'on retiendra dans tous les cas industriels. Techniquement, il s'agit d'une librairie Java, ce qui suppose donc un hébergeur en Java...&lt;/p&gt;


&lt;h4&gt;Proxy en PHP pour les hébergements restreint au PHP&lt;/h4&gt;

&lt;p&gt;Ce présent blog est hébergé chez OVH et comme c'est souvent le cas l'hébergeur propose du Php mais pas du Java. Une solution, consiste alors à écrire un service de proxy en PHP.&lt;/p&gt;


&lt;p&gt;C'est ce qui est mis en oeuvre par le démonstrateur &lt;a href=&quot;http://flex.scoutant.org/post/2009/02/Velib-en-Google-Maps-API-For-Flash-avec-MakerManager&quot;&gt;Velib en Flash &lt;/a&gt;&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:HTTPService&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;phpProxiedService&amp;quot;&lt;/span&gt; 
  &lt;span style=&quot;color: #000066;&quot;&gt;url&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://flex.scoutant.org/php/proxy.php&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;method&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;
  &lt;span style=&quot;color: #000066;&quot;&gt;resultFormat&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;e4x&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;useProxy&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;false&amp;quot;&lt;/span&gt; 
  &lt;span style=&quot;color: #000066;&quot;&gt;result&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;doLoad(event)&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;fault&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;faultHandler(event)&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; start&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; marker:StationMarker&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    phpProxiedService.&lt;span style=&quot;color: #006600;&quot;&gt;request&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;url&lt;/span&gt; = &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;url&lt;/span&gt; + marker.&lt;span style=&quot;color: #006600;&quot;&gt;station&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;num&lt;/span&gt;;
    &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; token:AsyncToken = phpProxiedService.&lt;span style=&quot;color: #006600;&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    token.&lt;span style=&quot;color: #006600;&quot;&gt;marker&lt;/span&gt; = marker;
 &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Ici l'objet de communication, le HTTPService, pointe vers le service de proxy, en l'occurrence&amp;nbsp;: http://flex.scoutant.org/php/proxy.php. Ce service fait maison propose l'API simpliste suivante&amp;nbsp;: la requête doit présenter un paramètre &lt;em&gt;url&lt;/em&gt; indiquant l'url cible.&lt;/p&gt;


&lt;p&gt;Voici ci-dessous le code du service proxy, avec utilisation d'un client &lt;em&gt;curl&lt;/em&gt;, pour lequel on positionne l'url cible via le paramètre de requête $_REQUEST['url'].&lt;/p&gt;
&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; curl_init&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;$timeout&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;$userAgent&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'HTTP_USER_AGENT'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
curl_setopt&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; CURLOPT_URL&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_REQUEST&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'url'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
curl_setopt&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; CURLOPT_RETURNTRANSFER&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
curl_setopt&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; CURLOPT_CONNECTTIMEOUT&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$timeout&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
curl_setopt&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; CURLOPT_USERAGENT&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$userAgent&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #ff0000&quot;&gt;$response&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; curl_exec&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;     
&amp;nbsp;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;curl_errno&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt; curl_error&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    curl_close&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$response&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;On pourra se référer au billet &lt;a href=&quot;http://www.switchonthecode.com/tutorials/using-a-php-proxy-with-flex-to-talk-cross-domain&quot;&gt;Using a PHP Proxy with Flex to talk Cross Domain &lt;/a&gt;, pour un peu plus de détails.&lt;/p&gt;


&lt;h4&gt;Proxy en BlazeDS sur hébergement GoogleAppEngine?&lt;/h4&gt;

&lt;p&gt;Le service d'hébergement GoogleAppEngine a été étendu à la technologie Java &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/04/#pnote-13-2&quot; id=&quot;rev-pnote-13-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;Du coup, on peut utiliser BlazeDS? Je n'ai pas fait le test, mais le billet suivant fait un constat négatif&amp;nbsp;: &lt;a href=&quot;http://thunderheadxpler.blogspot.com/2009/04/googleappengine-and-blazeds.html&quot;&gt; GoogleAppEngine and BlazeDS &lt;/a&gt;&amp;nbsp;: la package java.lang.management n'est pas autorisé...&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/04/#rev-pnote-13-1&quot; id=&quot;pnote-13-1&quot;&gt;1&lt;/a&gt;]  Adobe open Source :  &lt;a href=&quot;http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/&quot;&gt;  BlazeDS &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2009/04/#rev-pnote-13-2&quot; id=&quot;pnote-13-2&quot;&gt;2&lt;/a&gt;]  Google App Engine : &lt;a href=&quot;http://googleappengine.blogspot.com/2009/04/seriously-this-time-new-language-on-app.html&quot;&gt;The new language on App Engine &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
  <item>
    <title>Velib en Google Maps API For Flash - un MakerManager pour des performances!</title>
    <link>http://flex.scoutant.org/post/2009/02/Velib-en-Google-Maps-API-For-Flash-avec-MakerManager</link>
    <guid isPermaLink="false">urn:md5:5f1d8013231dc931a9357d25985c28d2</guid>
    <pubDate>Thu, 05 Feb 2009 21:38:00 +0100</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>cross-domain</category><category>google</category><category>maps</category><category>marker</category><category>velib</category>    
    <description>    &lt;p&gt;Vous cherchez un vélo en libre service? &lt;a href=&quot;http://www.velib.paris.fr/trouver_une_station&quot; hreflang=&quot;fr&quot;&gt;velib.paris.fr&lt;/a&gt; vous présente les stations avec la disponibilité des vélos et la disponibilité des emplacement libre pour le retour. C'est une appli JavaScript qui utilise l'Api historique de Google Maps.&lt;/p&gt;


&lt;p&gt;On peut faire l'équivalent en Flex en utilisant &lt;a href=&quot;http://code.google.com/intl/fr-FR/apis/maps/documentation/flash/&quot;&gt;Google Maps API For Flash&lt;/a&gt;.&lt;/p&gt;

    &lt;div  id=&quot;velib&quot;&gt;You need JavaScript enabled!&lt;/div&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      var flashvars = {
        key: &quot;ABQIAAAAajOKRtU0s5-AgMEc-2Ak3xSkphoE05t3ezOixQrkarOEFz6roxSGVN_Whx3vT2QYD-iWwvuFRrzT9Q&quot;,
        city:&quot;paris&quot;
        };
      swfobject.embedSWF(&quot;http://flex.scoutant.org/assets/FlashVelov.swf &quot;, &quot;velib&quot;, &quot;700&quot;, &quot;400&quot;, &quot;9.0.0&quot;,&quot;expressInstall.swf&quot;, flashvars, {wmode:&quot;transparent&quot;}  );
    &lt;/script&gt;




&lt;p&gt;On peut aussi en faire une version &lt;em&gt;full screen&lt;/em&gt;, voir la &lt;a href=&quot;http://flex.scoutant.org/assets/velib.html&quot;&gt;démo&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Dans ce cas, il faut faire attention aux performances&amp;nbsp;: on n'ap as envie d'avoir d'à-coups quand on déplace la carte. Mais a Paris il y a plus de 1000 stations Velib&amp;nbsp;; et une grande Google Maps avec 1000 markers c'est saccadé!&lt;/p&gt;


&lt;p&gt;Pour ca, la solution est l'utilisation d'un &lt;strong&gt;MarkerManager&lt;/strong&gt; disponible dans une librairie complémentaire à la Google Map API. Il s'agit de la Google Maps Utility Library également disponible en version AS3&amp;nbsp;: &lt;a href=&quot;http://code.google.com/p/gmaps-utility-library-flash/&quot;&gt;gmaps-utility-library-flash&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Ce gestionnaire accroit fortement les performances, car seuls les markers qui sont dans la viewport sont réellement gérés.&lt;/p&gt;


&lt;p&gt;L'utilisation est très facile, on instancie un Manager attaché à la map et ensuite les markers on les ajoute au gestionnaire plutôt que directement à la Google map.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;mgr = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; MarkerManager&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;map, &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Quand on dé-zoom, on a naturellement plus de marker dans la zone visible. Le MarkerManager permet de se protéger de ceci&amp;nbsp;: quand on ajoute un marker à la map, on précise à partir de quel zoom il devient visible.&lt;/p&gt;


&lt;p&gt;L'&lt;a href=&quot;http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/release/examples/weather_map.html&quot;&gt;exemple suivant&lt;/a&gt; parle de lui-même&amp;nbsp;: pour une carte météo nationale, une seule icone soleil suffit pour une région et c'est seulement quand on zoom dans une région qu'i lest intéressant d'afficher les marqueurs relatifs à une météo plus locale. L'idée d'un nombre constant d'informations quel que soit le niveau de zoom est intéressante.&lt;/p&gt;


&lt;p&gt;Justement quand on ajoute un marker, on est amené à préciser l'intervale de zoom pour lequel le marker est visible, parexemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;mgr.&lt;span style=&quot;color: #006600;&quot;&gt;addMarker&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;marker, &lt;span style=&quot;color: #CC0000;&quot;&gt;16&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;17&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Vois avez sans doute cliqué sur l'un des markers&amp;nbsp;: ca vous affiche la disponibilité de la station. Dans un prochain billet, un focus portera sur l'invocation du service web qui permet d'optenir les infos de disponibilité.&lt;/p&gt;


&lt;p&gt;Ouai, mais on voit déja poindre les intérrogations sur comment est alors traité la politique de &lt;strong&gt;cross-domain&lt;/strong&gt;. Vous pouvez déja lancer un sniffer réseau sur la démo ou aussi attendre le prochain billet.&lt;/p&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>SharedObject to persist your Flash app state - A Design canvas sample</title>
    <link>http://flex.scoutant.org/post/2008/12/SharedObject-to-persist-your-Flash-app-state</link>
    <guid isPermaLink="false">urn:md5:2c0dd92085fc56aa2f9f4ebc4689f0c9</guid>
    <pubDate>Tue, 30 Dec 2008 16:02:00 +0100</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>AMF3</category><category>as3</category><category>closure</category><category>DnD</category><category>drag</category><category>persistence</category><category>serialization</category><category>SharedObject</category>    
    <description>    	&lt;div  id=&quot;obj&quot;&gt;You need JavaScript enabled!&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		swfobject.embedSWF(&quot;http://flex.scoutant.org/assets/MoveAPIArraySharedObject.swf &quot;, &quot;obj&quot;, &quot;500&quot;, &quot;350&quot;, &quot;9.0.0&quot;,&quot;expressInstall.swf&quot;);
	&lt;/script&gt;



&lt;p&gt;&lt;em&gt;Move some figures arround, press Save, Close app, Re-open and notice how figure location is persisted... View source code&lt;/em&gt; &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-11-1&quot; id=&quot;rev-pnote-11-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;&lt;/p&gt;


&lt;h3&gt;Shared Object&lt;/h3&gt;

&lt;p&gt;Une application Flash a accès au file-system de façon très restreinte, via la technique des &lt;strong&gt;SharedObjet&lt;/strong&gt;. A l'image des Cookies pour les applications web.&lt;/p&gt;


&lt;p&gt;Dans le cas de l'application Flash, on dispose d'un espace de stockage, in fine, orienté objet&amp;nbsp;: tout objet (ou grappe d'objet) AS3 peut être sérialisé en AMF3 pour être stocké sous forme de SharedObject. Pour que la dé-sérialisation opère correctement il convient d'enregistrer les classes, typiquement avec le meta-tag &lt;strong&gt;RemoteClass&lt;/strong&gt;.&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;package&lt;/span&gt; model &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;RemoteClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; alias=&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;model.ImageVO&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
	&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;class&lt;/span&gt; ImageVO &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; source:String;
		&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; x:Number;
		&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; y:Number;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Write&lt;/h4&gt;

&lt;p&gt;Ensuite, comme le monte la doc &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-11-2&quot; id=&quot;rev-pnote-11-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;, il convient d'obtenir un SharedObject pour une nom donné, de lui adjoindre des données, et de réaliser l'écriture avec la méthode &lt;strong&gt;flush()&lt;/strong&gt;.&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; mySO:SharedObject = SharedObject.&lt;span style=&quot;color: #006600;&quot;&gt;getLocal&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;chessboard&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
mySO.&lt;span style=&quot;color: #006600;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'figure'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ImageVO&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'King.gif'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
mySO.&lt;span style=&quot;color: #006600;&quot;&gt;flush&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;h4&gt;Read&lt;/h4&gt;

&lt;p&gt;Pour la lecture, c'est tout a fait similaire, sauf que l'on opèrere un down-cast pour promouvoir le typage fort.&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; mySO:SharedObject = SharedObject.&lt;span style=&quot;color: #006600;&quot;&gt;getLocal&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;chessboard&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; figure:ImageVO = mySO.&lt;span style=&quot;color: #006600;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'figure'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;as&lt;/span&gt; ImageVO;&lt;/pre&gt;


&lt;h4&gt;Serializing UIComponents?&lt;/h4&gt;

&lt;p&gt;Notre exemple d'échiquier, est un simple Canvas qui contient des Images. L'exemple illustre également le déplacement d'image via Drag &amp;amp; Drop, explicité dans le post &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-11-3&quot; id=&quot;rev-pnote-11-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;L'approche naïve, consiste dans un premier temps à tenter de sérialiser le Canvas ou les images. Cela ne fonctionnera pas. Un UIComponent comporte des centaines de propriétés et en générale on veut juste stocker quelques propriétés&amp;nbsp;: dans notre exemple le positionnement x et y et la source pour une Image...&lt;/p&gt;


&lt;p&gt;D'où la classe ImageVO, vue ci-dessus. C'est cette classe qui sera persistée. Il s'agit alors de prévoir l'instantiation d'une mx.controls.Image à partir de notre ImageVO. Plusieurs approches sont possibles&amp;nbsp;; on peut prévoir une sous-classe de Image qui ajoute simplement les accesseurs à la &lt;strong&gt;ValueObject&lt;/strong&gt; correspondante&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;class&lt;/span&gt; ImageUI &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;extends&lt;/span&gt; Image &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; get vo&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : ImageVO &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
			&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ImageVO&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; source, x, y, width, height&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
		&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
		&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; set vo&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;ref:ImageVO&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
			source = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;ref&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;=&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt; ? ref.&lt;span style=&quot;color: #006600;&quot;&gt;source&lt;/span&gt; : &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
			width = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; ref&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;=&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt; ? ref.&lt;span style=&quot;color: #006600;&quot;&gt;width&lt;/span&gt; : &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
			height = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; ref&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;=&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt; ? ref.&lt;span style=&quot;color: #006600;&quot;&gt;height&lt;/span&gt; : &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
			x = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; ref&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;= &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt; ? ref.&lt;span style=&quot;color: #006600;&quot;&gt;x&lt;/span&gt; : &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
			y = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; ref&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;= &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt; ? ref.&lt;span style=&quot;color: #006600;&quot;&gt;y&lt;/span&gt; : &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
		&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
       &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Pour bien faire, on aimerait bien ajouter un constructeur d'Image sur la base de son VO correspondant. Mais l'AS3 ne permet pas d'avoir plusieurs constructeurs, on peut en alternative opter pour une méthode statique de fabrication. Par exemple&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;public&lt;/span&gt; static &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; newImage&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; vo:ImageVO, mouseDownCallback:&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;Function&lt;/span&gt;=&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : ImageUI &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
			&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; ref:ImageUI = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ImageUI&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
			ref.&lt;span style=&quot;color: #006600;&quot;&gt;vo&lt;/span&gt; = vo;
			&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; ref;
		&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Muni de cette classe l'instantiation d'un UIComponent à partir du SharedObjet correspondant est très simple.
Reste simplement à voir comment se présente la persistance pour une collection d'instance.&lt;/p&gt;

&lt;h4&gt;Array of data&lt;/h4&gt;

&lt;p&gt;Comme on a affaire à une vrai sérialisation AMF3, on peut aussi sérialiser directement un tableau d'objets.
Par exemple&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; doSave&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            	mySO.&lt;span style=&quot;color: #006600;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'figures'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; = board.&lt;span style=&quot;color: #006600;&quot;&gt;getChildren&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;item&lt;/span&gt;:ImageUI, index:int, arr:Array&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:ImageVO &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; 
                     &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;item&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;so&lt;/span&gt;
                 &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
            	mySO.&lt;span style=&quot;color: #006600;&quot;&gt;flush&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-11-1&quot; id=&quot;pnote-11-1&quot;&gt;1&lt;/a&gt;]  &lt;a href=&quot;http://flex.scoutant.org/download/sharedobject/MoveAPIArraySharedObject.mxml&quot; title=&quot;http://flex.scoutant.org/download/sharedobject/MoveAPIArraySharedObject.mxml&quot;&gt;http://flex.scoutant.org/download/s...&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-11-2&quot; id=&quot;pnote-11-2&quot;&gt;2&lt;/a&gt;]  SharedObject : &lt;a href=&quot;http://livedocs.adobe.com/flex/3/langref/flash/net/SharedObject.html&quot;&gt;http://livedocs.adobe.com/flex/3/langref/flash/net/SharedObject.html &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-11-3&quot; id=&quot;pnote-11-3&quot;&gt;3&lt;/a&gt;]  &lt;a href=&quot;http://flex.scoutant.org/post/2008/12/flex.scoutant.org/post/2008/10/No-Move-API-for-Flex-Falling-back-Drag-Drop-API&quot;&gt; flex.scoutant.org/post/2008/10/No-Move-API-for-Flex-Falling-back-Drag-Drop-API &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
  <item>
    <title>Adobe MAX 2008 Milan - FlexBuilder 4 Early Access</title>
    <link>http://flex.scoutant.org/post/2008/12/Adobe-MAX-2008-Milan-FlexBuilder-4-Early-Access</link>
    <guid isPermaLink="false">urn:md5:f05431414d4d2e9c7b3c32d243c30a88</guid>
    <pubDate>Sat, 13 Dec 2008 17:56:00 +0100</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>FlashCatalyst</category><category>FlashPlayer10</category><category>Flex4</category><category>FlexBuilder</category><category>Gumbo</category><category>MAX</category>    
    <description>    &lt;p&gt;&lt;img src=&quot;http://flex.scoutant.org/public/AdobeMax2008.jpg&quot; alt=&quot;Adobe Max 2008&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;Adobe Max 2008, dec 2008&quot; /&gt;&lt;/p&gt;


&lt;p&gt;L'&lt;strong&gt;Adobe MAX Europe 2008&lt;/strong&gt;, à Milan, à été l'occasion de nombre d'annonces et de démonstrations.&lt;/p&gt;


&lt;p&gt;Ci-dessous quelques-unes d'entre-elles. Avec, à la fin, un focus sur les nombreuses nouveautés de l'environnement de développement FlexBuilder 4.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.flash_catalyst_t.jpg&quot; alt=&quot;flash_catalyst&quot; style=&quot;float:left; margin: 0 1em 1em 0;&quot; title=&quot;flash_catalyst, dec 2008&quot; /&gt;
&lt;strong&gt;Flash Catalyst&lt;/strong&gt; est un outil de design RIA anciennement connu sous le nom de projet &lt;em&gt;Thermo&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;Flash Catalyst est pour l'instant uniquement disponible sur Mac avec une version pour Windows à venir prochainement . Le but de Flash Catalyst est de de faire le pont entre les  designers (Creative Suite, PhotoShop) et les développeurs (FlexBuilder).&lt;/p&gt;


&lt;p&gt;Flash Catalyst va de paire avec la nouvelle version du Sdk Flex. Flex 4, avec sa nouvelle architecture Gumbo, introduit une nouvelle approche pour skinner les composants Flex, via un fichier xml&amp;nbsp;: c'est le format FXG.&lt;/p&gt;


&lt;p&gt;Ce design spécifié en FXG peut ainsi être intégré au projet Flex. Et est consolidé en parallèle au traitements plus métier de l'application RIA&lt;/p&gt;



&lt;p&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.adobe_flash_logo_t.jpg&quot; alt=&quot;adobe_flash_logo.gif&quot; style=&quot;float:left; margin: 0 1em 1em 0;&quot; title=&quot;adobe_flash_logo.gif, dec 2008&quot; /&gt;
&lt;strong&gt;FlashPlayer 10&lt;/strong&gt;. La nouvelle version du runtime est sortie en octobre. Avec son lots d'améliorations &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-10-1&quot; id=&quot;rev-pnote-10-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;Je ne mentionnerai ici que l'ajout qu'est le nouveau protocole&amp;nbsp;: &lt;strong&gt;RTMFP&lt;/strong&gt; &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-10-2&quot; id=&quot;rev-pnote-10-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;. Ce protocole permet de faire des communications pear-to-pear directement entre deux instances de FleshPlayer10, sans passage par le moindre serveur. Notamment du streaming video avec une grande qualité video comme audio (son HD) et une faible latence.&lt;/p&gt;


&lt;p&gt;Pour mémoire, le protocole mis en avant jusqu'ici pour le streaming video (depuis un serveur) est le RTMP, basé sur un transport TCP. Le RTMFP, lui est basé sur un transport UDP, très adapté pour le p2p.&lt;/p&gt;


&lt;p&gt;Plus d'informations, à travers les annonces &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-10-3&quot; id=&quot;rev-pnote-10-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt;, &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-10-4&quot; id=&quot;rev-pnote-10-4&quot;&gt;4&lt;/a&gt;]&lt;/sup&gt;&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Open Screen Project&lt;/strong&gt; &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-10-5&quot; id=&quot;rev-pnote-10-5&quot;&gt;5&lt;/a&gt;]&lt;/sup&gt;
L'OpenScreenProject est une initiative visant l'implémentation de FlashPlayer10 sur les petits petits terminaux tels les téléphones mobiles. Malheureusement, il n'y a pas eu de grande annonce lors de cet Adobe MAX à ce sujet. C'est encore une phase  &lt;strong&gt;projet&lt;/strong&gt; et il faudra attendre 2010 pour avoir un nombre conséquent de terminaux équiper de FlashPlayer10.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.fx_appicon_t.jpg&quot; alt=&quot;Fx&quot; style=&quot;float:left; margin: 0 1em 1em 0;&quot; title=&quot;Fx, dec 2008&quot; /&gt;
&lt;strong&gt;FlexBuilder 4&lt;/strong&gt; Early Access apporte de très nombreuses améliorations.&lt;/p&gt;


&lt;p&gt;Il est vrai que la version 3 présente beaucoup de manques au vu de ce qu'offre Eclipse pour le dévelopement en langage Java. Ainsi FlexBuilder 4 comble ce décallage.&lt;/p&gt;



&lt;p&gt;Heidi williams, &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-10-6&quot; id=&quot;rev-pnote-10-6&quot;&gt;6&lt;/a&gt;]&lt;/sup&gt; et
Tim Buntel &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#pnote-10-7&quot; id=&quot;rev-pnote-10-7&quot;&gt;7&lt;/a&gt;]&lt;/sup&gt;
nous ont présenté les principaux ajouts.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://flex.scoutant.org/public/image001.png&quot;&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.image001_s.jpg&quot; alt=&quot;FB-1&quot; style=&quot;float:left; margin: 0 1em 1em 0;&quot; title=&quot;FB-1, dec 2008&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://flex.scoutant.org/public/image003.png&quot;&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.image003_s.jpg&quot; alt=&quot;FB-3&quot; title=&quot;FB-3, dec 2008&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Package explorer&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On a maintenant un vrai explorateur de package. Avec la possibilité de n'afficher que les packages présentant des fichiers. Pour chaque classe, on peut voir les propriétés et les méthodes la composants. On peut cliquer sur une méthode pour y positionner le curseur dans l'éditeur de texte...&lt;/p&gt;


&lt;p&gt;Comme pour l'explorateur en Java, on une croix rouge qui apparait si un fichier contient une erreur de compilation&amp;nbsp;; cette croix est également présente dans l'intégralité de la chaîne de packages conteneur.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reference librairies&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Pour chaque librairie référencée par le projet, on peut &quot;ouvrir&quot; la librairie et faire apparaître les classes la composants et ensuite ouvrir celles-ci pour faire apparaître les propriétés et les méthodes. Si on a pris soin d'associer à la librairie le chemin d'accès au code source, alors un clic amène au code source...
navigation dans les .swc
et si source attaché &quot;vie source&quot;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;File templates&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Avec FlexBuilder 4 on peut customiser des modèles pour la création de nouveaux fichiers. Des modèles différent en fonction du type ciblé&amp;nbsp;: Css, .mxml, interface .as, classe .as...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Getter and Setter generation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;http://flex.scoutant.org/public/image006.jpg&quot;&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.image006_m.jpg&quot; alt=&quot;FB-6&quot; style=&quot;float:left; margin: 0 1em 1em 0;&quot; title=&quot;FB-6, dec 2008&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;http://flex.scoutant.org/public/image008.jpg&quot;&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.image008_s.jpg&quot; alt=&quot;FB-8&quot; title=&quot;FB-8, dec 2008&quot; /&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Très pratique, la possibilité, enfin, de pouvoir générer les accesseurs à partir des propriétés. Le comportement par défaut est de rendre privée une propriété publique et de générer les deux accesseurs correspondants.  En mettant en oeuvre les mots clés get et set du langage AS3.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rename refactoring&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;La fonctionnalité implémentée dans FlexBuilder 3 est plus que minimaliste. Enfin avec la version 4, quand on change de nom ou quand on déplace de package une classe, toutes les références sont correctement mise à jour. C'était le minimum, on aura quand le même attendu longtemps!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debbuging enhencements&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;- Conditional breakpoint&amp;nbsp;: quand on a un point d'arrêt dans une boucle et on veut voir ce qui se passe à la cinquantième boucle seulement...&lt;/p&gt;


&lt;p&gt;- Run to line&lt;/p&gt;


&lt;p&gt;- Expression valiation enhanced&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FlexUnit integration&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;http://flex.scoutant.org/public/image010.jpg&quot;&gt;&lt;img src=&quot;http://flex.scoutant.org/public/./.image010_s.jpg&quot; alt=&quot;FB-10&quot; style=&quot;float:left; margin: 0 1em 1em 0;&quot; title=&quot;FB-10, dec 2008&quot; /&gt;&lt;/a&gt;
La aussi, vous me direz, c'était pas trop tôt. L'intégration, enfin dans l'IDE, du principal framework de tests unitaires&amp;nbsp;: FlexUnit. Ouvrant la voie au &lt;em&gt;test-driven development&lt;/em&gt; application Flex.&lt;/p&gt;


&lt;p&gt;On a ainsi, dans un premier temp, un wizard New &amp;gt; FlexUnit &amp;gt; TestCase, qui permet de préciser quelle est la classe ciblée par le test. Ensuite on peut invoquer unitairement de test. Sans avoir à produire explicitement une application Flash mettant en eouvre un TestRunner et une TestSuite...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Network Monitor&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Si votre application consomme des services web SOAP, Xml/Http, ou AMF3/Http, c'est toujours intéressant de pouvoir consulter de près les requêtes et les réponses.&lt;/p&gt;


&lt;p&gt;Avec FlexBuilder 4, plus besoin d'utiliser un Sniffer de requête -tel Charles-, Il suffit d'ouvrir le &lt;em&gt;Network Monitor&lt;/em&gt;. Ce dernier sait afficher dans le détail les réponses, y compris pour les réponse en AMF3...&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-10-1&quot; id=&quot;pnote-10-1&quot;&gt;1&lt;/a&gt;]  &lt;a href=&quot;http://labs.adobe.com/technologies/flashplayer10&quot;&gt; http://labs.adobe.com/technologies/flashplayer10 &lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-10-2&quot; id=&quot;pnote-10-2&quot;&gt;2&lt;/a&gt;]  Real Time Media Flow Protocol &lt;a href=&quot;http://en.wikipedia.org/wiki/Real_Time_Media_Flow_Protocol&quot;&gt; http://en.wikipedia.org/wiki/Real_Time_Media_Flow_Protocol &lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-10-3&quot; id=&quot;pnote-10-3&quot;&gt;3&lt;/a&gt;]  Adobe Makes P2P Flash Video Available to Developers &lt;a href=&quot;http://newteevee.com/2008/12/04/adobe-makes-p2p-flash-video-available-to-developers/&quot;&gt; http://newteevee.com/2008/12/04/adobe-makes-p2p-flash-video-available-to-developers/ &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-10-4&quot; id=&quot;pnote-10-4&quot;&gt;4&lt;/a&gt;]  Try RTMFP and Client-to-Client Direct Streaming, With FP10 and Cocomo, Today! &lt;a href=&quot;http://blogs.adobe.com/collabmethods/2008/12/try_rtmfp_and_clienttoclient_d.html&quot;&gt; http://blogs.adobe.com/collabmethods/2008/12/try_rtmfp_and_clienttoclient_d.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-10-5&quot; id=&quot;pnote-10-5&quot;&gt;5&lt;/a&gt;]  Open Screen Project &lt;a href=&quot;http://www.openscreenproject.org/&quot;&gt; http://www.openscreenproject.org/ &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-10-6&quot; id=&quot;pnote-10-6&quot;&gt;6&lt;/a&gt;]  Heidi williams,  Flex Builder, project Manager &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/12/#rev-pnote-10-7&quot; id=&quot;pnote-10-7&quot;&gt;7&lt;/a&gt;]  Tim Buntel , Senior Product Manager &lt;a href=&quot;http://www.buntel.com/blog/index.cfm/2008/11/21/Max-wrapup-not-really&quot;&gt; http://www.buntel.com/blog/index.cfm/2008/11/21/Max-wrapup-not-really &lt;/a&gt; &lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
  <item>
    <title>Closures AS3 a la Groovy with Array.forEach() and Array.map() support</title>
    <link>http://flex.scoutant.org/post/2008/11/Closures-AS3-a-la-Groovy-with-ArrayforEach-and-Arraymap-support</link>
    <guid isPermaLink="false">urn:md5:85e83aa927bee64c2a53de9d214b81af</guid>
    <pubDate>Sat, 22 Nov 2008 16:26:00 +0100</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>as3</category><category>closure</category><category>groovy</category>    
    <description>    &lt;p&gt;Dans nombre de langage de programmation fonctionnel, il est courant de manipuler des collections et d'appliquer des &lt;em&gt;&lt;strong&gt;closures&lt;/strong&gt;&lt;/em&gt; aux membres de la collection.&lt;/p&gt;


&lt;p&gt;Un exemple avec Groovy &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-9-1&quot; id=&quot;rev-pnote-9-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt; , un langage ciblant la JVM Java&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;groovy&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #663399;&quot;&gt;each&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; x -&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #993399;&quot;&gt;println&lt;/span&gt; x&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;x &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #663399;&quot;&gt;collect&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; x -&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt; x&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;x &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;La dernière ligne produit très naturellement la collection&amp;nbsp;:&lt;/p&gt;
&lt;pre&gt;
[1, 4, 9, 16, 25].
&lt;/pre&gt;


&lt;p&gt;En AS3 on a un support équivalent. Quoi qu'un peut moins elliptique.&lt;/p&gt;


&lt;h3&gt;Array.forEach() &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-9-2&quot; id=&quot;rev-pnote-9-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;&lt;/h3&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;forEach&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; traceSquare&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; traceSquare&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; x:&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;, index:int, arr:Array&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  trace&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt; + x&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;x&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Ceci produit vient la même sortie que la ligne groovy avec &lt;strong&gt;each{}&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;Array.map() &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-9-3&quot; id=&quot;rev-pnote-9-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt;&lt;/h3&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; square&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; square&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; x:&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;, index:int, arr:Array&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; x&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;x;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;



&lt;p&gt;Quand le traitement est court comme ci-dessus, on peut aussi opter pour une définition inline, comme suit&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; x:&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;, index:int, arr:Array&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; x&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;x &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h3&gt;Solution de un-marshalling JSON avec closure Array.map()&lt;/h3&gt;

&lt;p&gt;Nombre de web services offrent un format Json. Le service de feeds de delicious en est un exemple&amp;nbsp;: &lt;a href=&quot;http://feeds.delicious.com/v2/json/tags/coutant&quot;&gt; http://feeds.delicious.com/v2/json/tags/coutant &lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;flex&amp;quot;&lt;/span&gt;: &lt;span style=&quot;color: #CC0000;&quot;&gt;120&lt;/span&gt;, &lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;blazeds&amp;quot;&lt;/span&gt;: &lt;span style=&quot;color: #CC0000;&quot;&gt;8&lt;/span&gt;, . . .&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Il peut être intéressant de convertir cette réponse Json directement en un array d'objets AS3 représentant un tag (avec son nombre d'occurrence comme propriété).  Ceci peut être fait simplement&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;javascript&quot;&gt;tagsAsJson.&lt;span style=&quot;color: #006600;&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;,&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;item&lt;/span&gt;:&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;, index:int, arr:Array&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:Tag &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; Tag&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-9-1&quot; id=&quot;pnote-9-1&quot;&gt;1&lt;/a&gt;]  &lt;a href=&quot;http://groovy.codehaus.org/Quick+Start&quot; title=&quot;http://groovy.codehaus.org/Quick+Start&quot;&gt;http://groovy.codehaus.org/Quick+St...&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-9-2&quot; id=&quot;pnote-9-2&quot;&gt;2&lt;/a&gt;]  AS Doc Array.forEach(.) : &lt;a href=&quot;http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#forEach()&quot;&gt; http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#forEach() &lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-9-3&quot; id=&quot;pnote-9-3&quot;&gt;3&lt;/a&gt;]  AS Doc Array.map(.) : &lt;a href=&quot;http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#map()&quot;&gt; http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#map() &lt;/a&gt; &lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
  <item>
    <title>DeliSphere, a Flash 3D-animation tagcloud for your Delicious bookmarks</title>
    <link>http://flex.scoutant.org/post/2008/11/DeliSphere-a-Flash-3D-animation-tagcloud-for-your-Delicious-bookmarks</link>
    <guid isPermaLink="false">urn:md5:16eb614281d78b03633ff537c8590841</guid>
    <pubDate>Sat, 08 Nov 2008 22:40:00 +0100</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>as3</category><category>crossdomain</category><category>delicious</category><category>delisphere</category><category>demo</category><category>tagcloud</category>    
    <description>    &lt;div  id=&quot;sphere&quot;&gt;&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		var flashvars = {
			account:&quot;coutant&quot;,
  			tspeed: &quot;100&quot;,
  			threshold:&quot;5&quot;,
  			timer:&quot;120&quot;
		};
		swfobject.embedSWF(&quot;/demo/delisphere/DeliSphere.swf&quot;, &quot;sphere&quot;, &quot;400&quot;, &quot;400&quot;, &quot;9.0.0&quot;,&quot;expressInstall.swf&quot;, flashvars,  {wmode:&quot;transparent&quot;});
	&lt;/script&gt;



&lt;p&gt;Visit the &lt;a href=&quot;http://flex.scoutant.org/demo/delisphere/demo.html&quot;&gt;demo&lt;/a&gt; page to see  the animated tagcloud for &lt;strong&gt;&lt;em&gt;your&lt;/em&gt;&lt;/strong&gt; delicious.com &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-7-1&quot; id=&quot;rev-pnote-7-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt; account.&lt;/p&gt;


&lt;p&gt;You can &lt;a href=&quot;http://flex.scoutant.org/demo/delisphere/srcview/index.html&quot;&gt;view&lt;/a&gt; the source and if you want to insert the DeliSphere tagcloud in your site, you can &lt;a href=&quot;http://flex.scoutant.org/download/delisphere/&quot;&gt;download&lt;/a&gt; the delisphere distribution.&lt;/p&gt;


&lt;p&gt;The Delesphere tagcloud is an adaptation of the famous WordPress &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-7-2&quot; id=&quot;rev-pnote-7-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt; Cumulus plugin.&lt;/p&gt;



&lt;h5&gt;The WordPress Cumulus plugin&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;WP-Cumulus&lt;/em&gt;&lt;/strong&gt; &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-7-3&quot; id=&quot;rev-pnote-7-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt; is a WordPress plugin providing a Flash 3D animation displaying the tags related to the WordPress-powered blog. You can visit Roy Tanck's site at &lt;a href=&quot;http://www.roytanck.com&quot; title=&quot;http://www.roytanck.com&quot;&gt;http://www.roytanck.com&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;If you are using DotClear-powered blog, you can use the &lt;em&gt;TagFlash&lt;/em&gt; &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-7-4&quot; id=&quot;rev-pnote-7-4&quot;&gt;4&lt;/a&gt;]&lt;/sup&gt; adaptation.&lt;/p&gt;


&lt;p&gt;WP-Cumulus is a WordPress plugin, hence a PHP script that will request the MySql database for tags hosted by the blog. A click on a tag will then open up the posts related to the tag.&lt;/p&gt;


&lt;h5&gt;Delisphere architecture - Delicious API&lt;/h5&gt;

&lt;p&gt;DeliSphere Flash animation uses Delicious web services to get the tag cloud.
Consider for example the bookmarks for delicious account&amp;nbsp;: &lt;a href=&quot;http://delicious.com/coutant&quot; title=&quot;http://delicious.com/coutant&quot;&gt;http://delicious.com/coutant&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Delicious provides an API &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-7-5&quot; id=&quot;rev-pnote-7-5&quot;&gt;5&lt;/a&gt;]&lt;/sup&gt;. But to use those web services you need to be authenticated with targeted delicous account.&lt;/p&gt;


&lt;p&gt;When you are just reeding public data like bookmarks or tags, the smartest approach is to use the &lt;strong&gt;feeds&lt;/strong&gt; &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-7-6&quot; id=&quot;rev-pnote-7-6&quot;&gt;6&lt;/a&gt;]&lt;/sup&gt; services. Choosing RSS ot Json format. Json is just fine, for example the tag feed for above account is &lt;a href=&quot;http://feeds.delicious.com/v2/json/tags/coutant&quot;&gt; http://feeds.delicious.com/v2/json/tags/coutant &lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;
{ &amp;quot;flex&amp;quot;:135, &amp;quot;blazeds&amp;quot;:7, &amp;quot;dnd&amp;quot;: 8, &amp;quot;jee5&amp;quot;:23 ... }
&lt;/pre&gt;



&lt;h5&gt;Delisphere architecture - cross-domain policy&lt;/h5&gt;

&lt;p&gt;FlashPlayer cross domain policy will not enable a Flash application downloaded from domain A to be requesting  services from an another domain B. Unless domain B is actually exposing a cross-domain friendly policy file.&lt;/p&gt;


&lt;p&gt;Delicious.com is not exposing such a friendly policy file. But since V2, the feeds service does! Here is the file&amp;nbsp;: &lt;a href=&quot;http://feeds.delicious.com/crossdomain.xml&quot;&gt; http://feeds.delicious.com/crossdomain.xml &lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;cross-domain-policy&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;allow-access-from&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;domain&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/cross-domain-policy&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;See post  &lt;em&gt;crossdomain.xml now on feeds.delicious.com&lt;/em&gt;  &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-7-7&quot; id=&quot;rev-pnote-7-7&quot;&gt;7&lt;/a&gt;]&lt;/sup&gt;&lt;/p&gt;


&lt;p&gt;That way the delisphere app can be downloaded from anywhere onto a brower and from that location be connecting to Delicious feeds web service.&lt;/p&gt;


&lt;p&gt;Last step is the randomizing of spherical coordinates
&lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-7-8&quot; id=&quot;rev-pnote-7-8&quot;&gt;8&lt;/a&gt;]&lt;/sup&gt;&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-7-1&quot; id=&quot;pnote-7-1&quot;&gt;1&lt;/a&gt;]  Social bookmarking &lt;a href=&quot;http://flex.scoutant.org/post/2008/11/delicious.com&quot; title=&quot;delicious.com&quot;&gt;delicious.com&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-7-2&quot; id=&quot;pnote-7-2&quot;&gt;2&lt;/a&gt;]  WordPress &lt;a href=&quot;http://wordpress.org&quot;&gt; http://wordpress.org &lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-7-3&quot; id=&quot;pnote-7-3&quot;&gt;3&lt;/a&gt;]  WP-Cumulus : a WordPress plugin to display your site's tags in a flash movie, &lt;a href=&quot;http://wordpress.org/extend/plugins/wp-cumulus/&quot;&gt; http://wordpress.org/extend/plugins/wp-cumulus/ &lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-7-4&quot; id=&quot;pnote-7-4&quot;&gt;4&lt;/a&gt;]  tagflash, Dotclear plugin, an adaptation to Dotclear of WP-Cumulus &lt;a href=&quot;http://plugins.dotaddict.org/dc2/details/tagflash&quot;&gt;http://plugins.dotaddict.org/dc2/details/tagflash &lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-7-5&quot; id=&quot;pnote-7-5&quot;&gt;5&lt;/a&gt;]  Delicious API V2 : &lt;a href=&quot;http://delicious.com/help/api&quot; title=&quot;http://delicious.com/help/api&quot;&gt;http://delicious.com/help/api&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-7-6&quot; id=&quot;pnote-7-6&quot;&gt;6&lt;/a&gt;]  Delicious data feeds &lt;a href=&quot;http://delicious.com/help/feeds&quot; title=&quot;http://delicious.com/help/feeds&quot;&gt;http://delicious.com/help/feeds&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-7-7&quot; id=&quot;pnote-7-7&quot;&gt;7&lt;/a&gt;]  crossdomain.xml now onf feeds.delicious.com &lt;a href=&quot;http://tech.groups.yahoo.com/group/ydn-delicious/message/1999&quot;&gt; http://tech.groups.yahoo.com/group/ydn-delicious/message/1999 &lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-7-8&quot; id=&quot;pnote-7-8&quot;&gt;8&lt;/a&gt;]  Distribution points on a sphere, in ActionScript3, randomizing sperical coordinates : &lt;a href=&quot;http://blog.massivecube.com/?p=9&quot;&gt;http://blog.massivecube.com/?p=9 &lt;/a&gt; &lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
  <item>
    <title>Using BlazeDS proxy service behind a firewall proxy</title>
    <link>http://flex.scoutant.org/post/2008/11/Using-BlazeDS-proxy-service-behind-a-firewall-proxy</link>
    <guid isPermaLink="false">urn:md5:03a89cf60dd69f0829306c66644d201b</guid>
    <pubDate>Sat, 08 Nov 2008 20:48:00 +0100</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>blazeds</category><category>crossdomain</category><category>firewall</category><category>flash</category>    
    <description>    &lt;p&gt;&lt;a href=&quot;http://flex.scoutant.org/public/blazeds-proxy-400.png&quot;&gt;&lt;img src=&quot;http://flex.scoutant.org/public/blazeds-proxy-400.png&quot; alt=&quot;blazeds-proxy-400.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;blazeds-proxy-400.png, nov 2008&quot; /&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;FlashPlayer cross domain policy will not enable a Flash application downloaded from domain A to be requesting  services from an another domain B. Unless domain B is actually exposing a cross-domain friendly policy file. For example Google does&amp;nbsp;: &lt;a href=&quot;http://www.google.com/crossdomain.xml&quot;&gt;http://www.google.com/crossdomain.xml&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;In general, such a friendly crossdomain.xml file is not exposed by targeted service provider. In such case we can use BlazeDS proxy service.&lt;/p&gt;


&lt;p&gt;We first need to configure the HTTPService to be using a proxy&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:HTTPService&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;useProxy&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;url&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;. .&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Second, we need to install and launch BlazeDS. With &lt;em&gt;trunkey&lt;/em&gt; BlazeDS&lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#pnote-8-1&quot; id=&quot;rev-pnote-8-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt; distribution it's straitforward. Obviously you need a Java-powered server&amp;nbsp;: a sole Php-server will not help.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Consider you install the BlazeDS server in an intranet and a firewall has to be used to access the service provider B&lt;/strong&gt;. You will need to configure BlazeDS so as to use the firewall proxy. If you just unzipped the turnkey distribution and launch BlazeDS, i guess you did not read corresponding 1000-page doc.&lt;/p&gt;


&lt;p&gt;But it's just Java, you will try the general JVM-based approach, and you will be lauching BlazeDS with JMV args&amp;nbsp;:&lt;/p&gt;
&lt;pre&gt;
-DhttpProxyHost=&amp;lt;you-fire-wall&amp;gt; -DhttpProxyPort=3128
&lt;/pre&gt;


&lt;p&gt;&lt;ins&gt;you will still fall in connection timeout&lt;/ins&gt;. It's a pity. Even more when you know that BlazeDS &lt;strong&gt;is&lt;/strong&gt; using Jakarta HttpClient support&amp;nbsp;; which actually honor above-mentionned configuration...&lt;/p&gt;


&lt;p&gt;&lt;ins&gt;BlazeDS overrides that feature&lt;/ins&gt;. The only way is to refer to documentation and to find out where firewall proxy can be configured. Not so easy, keyword &lt;em&gt;proxy&lt;/em&gt; hardly allways refer to the proxy service...&lt;/p&gt;


&lt;p&gt;Config file &lt;strong&gt;&lt;em&gt;proxy-config.xml&lt;/em&gt;&lt;/strong&gt; has to be customized&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;service&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;proxy-service&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;class&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;flex.messaging.services.HTTPProxyService&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;properties&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
        . . .
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;allow-lax-ssl&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;true&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/allow-lax-ssl&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;external-proxy&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
                &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;server&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;your-firewall&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/server&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
                &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;port&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;3128&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/port&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/external-proxy&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/11/#rev-pnote-8-1&quot; id=&quot;pnote-8-1&quot;&gt;1&lt;/a&gt;] BlazeDS : &lt;a href=&quot;http://opensource.adobe.com/wiki/display/blazeds/Release+Builds&quot;&gt;http://opensource.adobe.com/wiki/display/blazeds/Release+Builds&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
  <item>
    <title>No Move API for Flex : falling back to Drag &amp; Drop API</title>
    <link>http://flex.scoutant.org/post/2008/10/No-Move-API-for-Flex-Falling-back-Drag-Drop-API</link>
    <guid isPermaLink="false">urn:md5:f5ab64253193d9d1947a2b64fcfb8ac4</guid>
    <pubDate>Sat, 25 Oct 2008 18:44:00 +0200</pubDate>
    <dc:creator>scoutant</dc:creator>
        <category>DnD</category><category>DragManager</category><category>Flex</category>    
    <description>    &lt;p&gt;&lt;em&gt;Yes, i just want to let the user move an image arround its container canvas. Flex does not provide you a direct API for that. You need to fall back to Drag &amp;amp; Drop API. Right-clic below to see source code&lt;/em&gt;&lt;/p&gt;
	&lt;div  align=&quot;center&quot;  id=&quot;obj&quot;&gt;You need JavaScript enabled!&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		swfobject.embedSWF(&quot;/assets/MoveAPI.swf &quot;, &quot;obj&quot;, &quot;300&quot;, &quot;300&quot;, &quot;9.0.0&quot;,&quot;expressInstall.swf&quot;);
	&lt;/script&gt;


&lt;p&gt;Ci-dessus, vous pouvez déplacer les images qui réprésentent les pièces d'échecs&amp;nbsp;: un échec et mat évident en un coup... Pour ce qui est du code Flex, commençons par le début du Drag &amp;amp; Drop.&lt;/p&gt;

&lt;h4&gt;Drag &amp;amp; Drop with Flex DnD-enabled controls&lt;/h4&gt;

&lt;p&gt;Ok, prenons les choses depuis le départ. Flex offre un bon support de Drag &amp;amp; Drop, ce qui permet une mise en oeuvre simple pour les composants tels &lt;em&gt;List&lt;/em&gt;, &lt;em&gt;DataGrid&lt;/em&gt; et &lt;em&gt;Tree&lt;/em&gt;.&lt;/p&gt;
	&lt;div  align=&quot;center&quot;  id=&quot;ListDnDSample&quot;&gt;You need JavaScript enabled!&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		swfobject.embedSWF(&quot;/assets/ListDnDSample.swf &quot;, &quot;ListDnDSample&quot;, &quot;480&quot;, &quot;220&quot;, &quot;9.0.0&quot;,&quot;expressInstall.swf&quot;);
	&lt;/script&gt;


&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:Application&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;xmlns:mx&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://www.adobe.com/2006/mxml&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;layout&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;horizontal&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; 
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:Array&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fruits&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;['Orange', 'Apple', 'Blackberry', 'Cranberry', 'Banana']&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx:Array&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:Panel&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;title&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Available&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;50%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;height&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:List&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;dragEnabled&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;dataProvider&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{fruits}&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;height&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx:Panel&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:Panel&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;title&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;My selection&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;50%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;height&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:List&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;dropEnabled&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;height&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx:Panel&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx:Application&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Bref il suffit d'activer les propriétés &lt;strong&gt;dragEnabled&lt;/strong&gt; et &lt;strong&gt;dropEnabled&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;Moving an image&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Flex DnD API is straitforward for those DnD-enabled controls. But in order to move arround an image, a DragManager will need to be used.&lt;/em&gt;&lt;/p&gt;


&lt;h5&gt;Dragging an image&lt;/h5&gt;

&lt;p&gt;Nous allons voir comment, dès qu'on sort du cadre des composants Dnd-enabled, il faut utiliser explicitement le DragManager &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/10/#pnote-6-1&quot; id=&quot;rev-pnote-6-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;. Pour qu'une image soit éligible au Drag, on a typiquement, ceci.&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:Image&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;mouseDown&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;dragging(event);&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; dragging&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;event:MouseEvent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;                
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; dragInitiator:Image = event.&lt;span style=&quot;color: #006600;&quot;&gt;currentTarget&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;as&lt;/span&gt; Image;
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; ds:DragSource = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; DragSource&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  ds.&lt;span style=&quot;color: #006600;&quot;&gt;addData&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;dragInitiator, &lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;img&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  DragManager.&lt;span style=&quot;color: #006600;&quot;&gt;doDrag&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;dragInitiator, ds, event&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;A partir de là, on peut effectivement déplacer l'image en maintenant le bouton gauche de la souris. Mais le rendu n'est pas terrible, car au moment du déplacement, notre image cible est alors simplement matérialisé par un rectangle. On peut vérifier avec l'extrait suivant&amp;nbsp;:&lt;/p&gt;

	&lt;div  align=&quot;center&quot;  id=&quot;DraggingWithNoDragImage&quot;&gt;&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		swfobject.embedSWF(&quot;/assets/DraggingWithNoDragImage.swf&quot;, &quot;DraggingWithNoDragImage&quot;, &quot;110&quot;, &quot;110&quot;, &quot;9.0.0&quot;,&quot;expressInstall.swf&quot;);
	&lt;/script&gt;



&lt;h5&gt;Dragging with custom feedback proxy&lt;/h5&gt;

&lt;p&gt;Mais on peut préciser au DragManager une image à utiliser pendant le déplacement et qui sera affichée comme feedback pendant le drag. On peut valoriser le 4-ième paramètres (optionnel) de la méthode &lt;em&gt;doDrag()&lt;/em&gt;.&lt;/p&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; dragging&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;event:MouseEvent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;                
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; dragInitiator:Image = event.&lt;span style=&quot;color: #006600;&quot;&gt;currentTarget&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;as&lt;/span&gt; Image;
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; ds:DragSource = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; DragSource&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  ds.&lt;span style=&quot;color: #006600;&quot;&gt;addData&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;dragInitiator, &lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;img&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; imageProxy:Image = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; Image&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  imageProxy.&lt;span style=&quot;color: #006600;&quot;&gt;source&lt;/span&gt; = event.&lt;span style=&quot;color: #006600;&quot;&gt;currentTarget&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;source&lt;/span&gt;;
  imageProxy.&lt;span style=&quot;color: #006600;&quot;&gt;width&lt;/span&gt;= dragInitiator.&lt;span style=&quot;color: #006600;&quot;&gt;width&lt;/span&gt;;
  imageProxy.&lt;span style=&quot;color: #006600;&quot;&gt;height&lt;/span&gt;= dragInitiator.&lt;span style=&quot;color: #006600;&quot;&gt;height&lt;/span&gt;;
  DragManager.&lt;span style=&quot;color: #006600;&quot;&gt;doDrag&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;dragInitiator, ds, event, imageProxy&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Et là, autant prendre l'image sur laquelle on veut précisément agir: oui, enfin..., on prendra une copie pour que ca marche.&lt;/p&gt;

	&lt;div  align=&quot;center&quot;  id=&quot;DroppingButWithPositionOffset&quot;&gt;&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		swfobject.embedSWF(&quot;/assets/DroppingButWithPositionOffset.swf&quot;, &quot;DroppingButWithPositionOffset&quot;, &quot;110&quot;, &quot;110&quot;, &quot;9.0.0&quot;,&quot;expressInstall.swf&quot;);
	&lt;/script&gt;



&lt;h5&gt;Dropping&lt;/h5&gt;

&lt;p&gt;Reste à finaliser le déplacement de notre image, pour cela il faut que notre conteneur, ici un Canvas, accepte le Drop. Pour cela, on peut se contenter de ceci&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:Canvas&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;dragEnter&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;DragManager.acceptDragDrop( event.currentTarget as Canvas);&amp;quot;&lt;/span&gt;
  &lt;span style=&quot;color: #000066;&quot;&gt;dragDrop&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;dragDropHandler(event);&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; dragDropHandler&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;event:DragEvent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; image:Image = event.&lt;span style=&quot;color: #006600;&quot;&gt;dragInitiator&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;as&lt;/span&gt; Image;
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; container:Canvas = event.&lt;span style=&quot;color: #006600;&quot;&gt;currentTarget&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;as&lt;/span&gt; Canvas;
  image.&lt;span style=&quot;color: #006600;&quot;&gt;x&lt;/span&gt; = container.&lt;span style=&quot;color: #006600;&quot;&gt;mouseX&lt;/span&gt;; 
  image.&lt;span style=&quot;color: #006600;&quot;&gt;y&lt;/span&gt; = container.&lt;span style=&quot;color: #006600;&quot;&gt;mouseY&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;



&lt;p&gt;Là, on y est presque. Sauf que vous l'avez vu quand on lâche l'image, elle ne se pose pas à l'endroit naturelle. En fait c'est un peu se qui se passe aussi dans l'exemple de DnD d'image à la fin du billet de Xebia &lt;sup&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/10/#pnote-6-2&quot; id=&quot;rev-pnote-6-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;.
Le problème le voici&amp;nbsp;: quand on initialise le Drag, on clique n'importe où dans l'image et quand on relâche la souris, le coin supérieur gauche de l'image prend la position de la souris. Mais pour compenser, il suffit de compléter comme suit&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx:Canvas&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;dragEnter&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;DragManager.acceptDragDrop( event.currentTarget as Canvas);&amp;quot;&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;mouseDown&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;recordPosition(event)&amp;quot;&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;dragDrop&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;dragDropHandler(event);&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class=&quot;javascript&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; recordPosition&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;event:MouseEvent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  fromX = event.&lt;span style=&quot;color: #006600;&quot;&gt;localX&lt;/span&gt;;
  fromY = event.&lt;span style=&quot;color: #006600;&quot;&gt;localY&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; dragDropHandler&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;event:DragEvent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; image:Image = event.&lt;span style=&quot;color: #006600;&quot;&gt;dragInitiator&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;as&lt;/span&gt; Image;
  &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; container:Canvas = event.&lt;span style=&quot;color: #006600;&quot;&gt;currentTarget&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;as&lt;/span&gt; Canvas;
  image.&lt;span style=&quot;color: #006600;&quot;&gt;x&lt;/span&gt; = container.&lt;span style=&quot;color: #006600;&quot;&gt;mouseX&lt;/span&gt; - fromX; 
  image.&lt;span style=&quot;color: #006600;&quot;&gt;y&lt;/span&gt; = container.&lt;span style=&quot;color: #006600;&quot;&gt;mouseY&lt;/span&gt; - fromY;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

	&lt;div  align=&quot;center&quot;  id=&quot;MovingImage&quot;&gt;&lt;/div&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		swfobject.embedSWF(&quot;/assets/MovingImage.swf&quot;, &quot;MovingImage&quot;, &quot;110&quot;, &quot;110&quot;, &quot;9.0.0&quot;,&quot;expressInstall.swf&quot;);
	&lt;/script&gt;



&lt;p&gt;Ouf, là on y est!&lt;/p&gt;


&lt;p&gt;Comme quoi le Drag&amp;amp;Drop est immédiat en Flex pour les composants List, DataGrid, Tree&amp;nbsp;: activer les propriétés dragEnable et dropEnabled.&lt;/p&gt;


&lt;p&gt;Par contre pour déplacer une image, il n'y a pas d'API direct et il faut mettre en oeuvre un Drag &amp;amp; Drop avec DragManager et là ce présent tutorial peut guider pour les quelques 15 lignes de code nécessaires.&lt;/p&gt;


&lt;p&gt;Pour le code source&amp;nbsp;: un simple clic droit sur l'échiquier en début de billet.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/10/#rev-pnote-6-1&quot; id=&quot;pnote-6-1&quot;&gt;1&lt;/a&gt;]  &lt;a href=&quot;http://livedocs.adobe.com/flex/3/langref/mx/managers/DragManager.html&quot;&gt; Flex 3 DragManager : http://livedocs.adobe.com/flex/3/langref/mx/managers/DragManager.html  &lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://flex.scoutant.org/post/2008/10/#rev-pnote-6-2&quot; id=&quot;pnote-6-2&quot;&gt;2&lt;/a&gt;]  &lt;a href=&quot;http://blog.xebia.fr/2008/06/19/drag-and-drop-flex&quot;&gt; Xebia, billet Drag &amp;amp; Drop : http://blog.xebia.fr/2008/06/19/drag-and-drop-flex &lt;/a&gt; &lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
</channel>
</rss>
