<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>fx&#039;Dev Blog</title>
	<atom:link href="http://www.fxbt.info/devblog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fxbt.info/devblog</link>
	<description>Blog Dev Java, Flex,JavaScript...</description>
	<lastBuildDate>Tue, 03 Apr 2012 20:06:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Comment corriger l&#8217;erreur &#171;&#160;Error generating final archive: Debug certificate expired&#160;&#187;</title>
		<link>http://www.fxbt.info/devblog/2012/04/03/comment-corriger-lerreur-error-generating-final-archive-debug-certificate-expired/</link>
		<comments>http://www.fxbt.info/devblog/2012/04/03/comment-corriger-lerreur-error-generating-final-archive-debug-certificate-expired/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 20:06:50 +0000</pubDate>
		<dc:creator>fx</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[certificat]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[expiration]]></category>

		<guid isPermaLink="false">http://www.fxbt.info/devblog/?p=95</guid>
		<description><![CDATA[Bon, chose ennuyeuse, ça fait plus d&#8217;un an que mon Eclipse et mon sdk Android est installé, et ce soir, plus moyen de compiler mon projet : &#171;&#160;Error generating final archive : Debug certificate expired&#160;&#187;. Alors chose super logique, il semblerait que le SDK Android ne soit capable de signer le certificat de débug que ]]></description>
			<content:encoded><![CDATA[<p>Bon, chose ennuyeuse, ça fait plus d&#8217;un an que mon Eclipse et mon sdk Android est installé, et ce soir, plus moyen de compiler mon projet : &laquo;&nbsp;Error generating final archive : Debug certificate expired&nbsp;&raquo;.<br />
Alors chose super logique, il semblerait que le SDK Android ne soit capable de signer le certificat de débug que pour une durée d&#8217;un an. C&#8217;est assez stupide&#8230; Et surtout le vieux réflexe qu&#8217;on a face à ça : doit-on réinstaller le SDK ? Et bien non, il y a une solution plus rapide (largement).</p>
<p>&nbsp;</p>
<ol>
<li>Avant tout, ouvrez votre explorateur de fichier, et allez dans le répertoire de la configuration d&#8217;Android &laquo;&nbsp;%HOMEPATH%\.android&nbsp;&raquo; (suivant votre système d&#8217;exploitation, c&#8217;est dans /home/&lt;vous&gt;/.android ou bien c:/User/&lt;vous&gt;/.android);</li>
<li>Trouves &laquo;&nbsp;debug.keystore&nbsp;&raquo; et supprimez-le;</li>
<li>Retournez dans Eclipse et nettoyez votre projet (Project &gt; Clean)</li>
<li>Tout est revenu dans l&#8217;ordre.</li>
</ol>
<p>&nbsp;</p>
<p>Il y a ensuite des solutions pour faire son propre certificat, mais cette explication sera pour plus tard (quand je l&#8217;aurais testé moi même).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fxbt.info/devblog/2012/04/03/comment-corriger-lerreur-error-generating-final-archive-debug-certificate-expired/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Utiliser la touche &#171;&#160;Back&#160;&#187; dans une application mobile en Flex</title>
		<link>http://www.fxbt.info/devblog/2011/07/12/utiliser-la-touche-back-dans-une-application-mobile-en-flex/</link>
		<comments>http://www.fxbt.info/devblog/2011/07/12/utiliser-la-touche-back-dans-une-application-mobile-en-flex/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 21:01:18 +0000</pubDate>
		<dc:creator>fx</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[back]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[prevent]]></category>

		<guid isPermaLink="false">http://www.fxbt.info/devblog/?p=89</guid>
		<description><![CDATA[Depuis Flex 4.5, j&#8217;ai commencé à m&#8217;amuser avec la création d&#8217;application Androïd en AIR, franchement c&#8217;est pas mal, on garde un certain nombre de nos automatismes, et on va assez vite pour faire quelque chose, bon après il faut le dire on se rend compte que certaines choses ne sont pas pareil sur un mobile ]]></description>
			<content:encoded><![CDATA[<p>Depuis Flex 4.5, j&#8217;ai commencé à m&#8217;amuser avec la création d&#8217;application Androïd en AIR, franchement c&#8217;est pas mal, on garde un certain nombre de nos automatismes, et on va assez vite pour faire quelque chose, bon après il faut le dire on se rend compte que certaines choses ne sont pas pareil sur un mobile que sur une application AIR de bureau, mais on gagne quand même du temps par rapport à une application Androïd faite de manière classique. De plus avec la 4.5.1, pas grand chose à changer pour être compatible pour iPhone ou BlackBerry Tablet. Que du bonheur donc.</p>
<p>Mais bien sur, un bonheur n&#8217;arrive jamais seul. Il y a donc quelques soucis parfois, des choses expliquées d&#8217;une façon dans la documentation officielle d&#8217;Adobe et qui finalement ne s&#8217;avèrent pas être comme ça.</p>
<p>Par exemple avec l&#8217;utilisation des touches &laquo;&nbsp;physiques&nbsp;&raquo; des mobiles (je mets des guillemets car sur mon Archos IT, elles sont totalement virtuelles, et sur mon GSii, ce n&#8217;est guère mieux&#8230;). En effet la touche menu, il n&#8217;y a pas de problème, on peut tout à fait l&#8217;activer sans effet secondaire. Mais la touche back, c&#8217;est une autre paire de manches, celle-ci s&#8217;active, malgré le <code class="codecolorer text twitlight"><span class="text">preventDefault</span></code> sauf si on déclare l’événement comme il faut&#8230;</p>
<p>Petit exemple, je veux appeler l&#8217;eventListener associé à la touche Back :</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);</div></td></tr></tbody></table></div>
<p>Et je défini ma fonction onKeyDown</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">protected function onKeyDown(event:KeyboardEvent):void<br />
{<br />
&nbsp; &nbsp; if (event.keyCode == Keyboard.BACK)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; event.preventDefault();<br />
&nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;Back Pressed&quot;);<br />
&nbsp; &nbsp; } <br />
}</div></td></tr></tbody></table></div>
<p>Et voilà me direz vous, mais vous vous doutez bien que s&#8217;il y a article, ce n&#8217;est pas le cas&#8230; En effet, dans ce cas, la trace s&#8217;affiche bien, mais la touche BACK s&#8217;exécute (l&#8217;application se ferme si c&#8217;est sur l&#8217;écran principale ou on retourne à la vue précédente sinon). Ce n&#8217;est pas le cas prévu étant donné que l&#8217;on a utilisé la fonction <code class="codecolorer text twitlight"><span class="text">preventDefault</span></code></p>
<p>Comment faire ?</p>
<p>Et bien tout simplement au lieu de définir en &laquo;&nbsp;ligne&nbsp;&raquo; l&#8217;ajout de l&#8217;eventlistener, on le met dans l&#8217;entête du fichier MXML</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">keyDown=&quot;onKeyDown(event)&quot;</div></td></tr></tbody></table></div>
<p>On ne change pas la fonction bien entendu.</p>
<p>Alors, heureux ?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fxbt.info/devblog/2011/07/12/utiliser-la-touche-back-dans-une-application-mobile-en-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convertir un tableau de bytes en String en C# .NET</title>
		<link>http://www.fxbt.info/devblog/2011/01/13/convertir-un-tableau-de-bytes-en-string-en-c-net/</link>
		<comments>http://www.fxbt.info/devblog/2011/01/13/convertir-un-tableau-de-bytes-en-string-en-c-net/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 14:42:09 +0000</pubDate>
		<dc:creator>fx</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.fxbt.info/devblog/?p=82</guid>
		<description><![CDATA[Aujourd&#8217;hui, alors que j&#8217;essayais de lire des GeoTIFF en .NET, je me suis retrouvé face au problème suivant, comment convertir un tableau de bytes (byte[]) en String en C# ? Autant en Java c&#8217;est assez simple, autant en C#, la technique du new String&#40;byte&#91;&#93;&#41; ne fonctionne pas&#8230; Pour autant, ce n&#8217;est pas vraiment plus dur, ]]></description>
			<content:encoded><![CDATA[<p>Aujourd&#8217;hui, alors que j&#8217;essayais de lire des GeoTIFF en .NET, je me suis retrouvé face au problème suivant, comment convertir un tableau de bytes (byte[]) en String en C# ?</p>
<p>Autant en Java c&#8217;est assez simple, autant en C#, la technique du <code class="codecolorer java twitlight"><span class="java"><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span></span></code> ne fonctionne pas&#8230;</p>
<p>Pour autant, ce n&#8217;est pas vraiment plus dur, il suffit d&#8217;avoir les bonnes librairies.</p>
<p>On importe nos dépendances :</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>Et on traite notre tableau de bytes :</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> b <span style="color: #008000;">=</span> <span style="color: #008080; font-style: italic;">/* votre tableau de bytes */</span><br />
Encoding enc <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">ASCII</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">string</span> maChaine <span style="color: #008000;">=</span> enc<span style="color: #008000;">.</span><span style="color: #0000FF;">GetString</span><span style="color: #008000;">&#40;</span>b<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>Et ce n&#8217;est pas plus compliqué, on peut bien entendu changer l&#8217;ASCII par autre chose, UTF32, UTF8, Unicode&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fxbt.info/devblog/2011/01/13/convertir-un-tableau-de-bytes-en-string-en-c-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SuperImage, ou comment éviter le désagréable clignotement</title>
		<link>http://www.fxbt.info/devblog/2010/08/18/superimage-ou-comment-eviter-le-desagreable-clignotement/</link>
		<comments>http://www.fxbt.info/devblog/2010/08/18/superimage-ou-comment-eviter-le-desagreable-clignotement/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 20:12:18 +0000</pubDate>
		<dc:creator>fx</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Bordure]]></category>
		<category><![CDATA[Clignotement]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Liste]]></category>
		<category><![CDATA[SuperImage]]></category>

		<guid isPermaLink="false">http://www.fxbt.info/devblog/?p=76</guid>
		<description><![CDATA[Qui n&#8217;a jamais eu le désagréable clignotement des images dans une liste en Flex ? Vous savez, ce clignotement qui vous donne l&#8217;impression que vos images sont rechargées à chaque fois que vous scrollez dans une liste d&#8217;image&#8230; D&#8217;autant plus qu&#8217;elles sont vraiment rechargées à chaque fois. Si vous avez essayé comme moi de faire ]]></description>
			<content:encoded><![CDATA[<p>Qui n&#8217;a jamais eu le désagréable clignotement des images dans une liste en Flex ? Vous savez, ce clignotement qui vous donne l&#8217;impression que vos images sont rechargées à chaque fois que vous scrollez dans une liste d&#8217;image&#8230; D&#8217;autant plus qu&#8217;elles sont vraiment rechargées à chaque fois.</p>
<p>Si vous avez essayé comme moi de faire un visualiseur pour Flickr (rien à voir le clignotement là), vous avez du le remarquer, et vous avez du vous arracher les cheveux sur le composant List (ou autre) et sur les composants Image pour trouver pourquoi il voulait absolument recharger les images à chaque fois.</p>
<p>Et bien vous savez, vous n&#8217;êtes pas les seuls à avoir eu ce problème (la preuve, je l&#8217;ai eu sinon je n&#8217;en parlerais pas), mais certains en plus de l&#8217;avoir eu, l&#8217;on résolu !</p>
<p>En cherchant comment le résoudre pour une énième fois, j&#8217;ai fini par trouver le blog de Quietly Scheming. Outre le fait qu&#8217;il explique des choses intéressantes pour Flex, il donne aussi du code clef en main (à un bémol pour Flex 4 et les composants Spark), pour corriger ce problème de clignotement. Je vous laisse découvrir la suite sur l&#8217;article du blog en question (en anglais) <a href="http://www.quietlyscheming.com/blog/2007/01/23/some-thoughts-on-doubt-on-flex-as-the-best-option-orhow-i-made-my-flex-images-stop-dancing/" target="_blank">”how I made my Flex List Images stop flickering.”</a>.</p>
<p>Comment s&#8217;en servir ? Récupérez les classes qui vont bien, mettez les dans votre projet, et ensuite, au lieu de prendre du <mx:Image>, prenez du <ns:SuperImage>, pas bien compliqué. Il y a quelques limitations par rapport aux images Flex natives, mais il faut se limiter à utiliser ces SuperImages dans des listes, et ne pas en mettre là où les images natives sont déjà suffisantes.</p>
<p>Il y avait un bémol avec Flex 4 ? En fait oui, mais pas grand chose de bien dramatique. L&#8217;auteur a poussé le vice de ces images à rajouter un effet de bordure, sauf que avec l&#8217;arrivée de Spark, la façon dont il défini les bordures pose problème, en effet il recherche la classe du style &laquo;&nbsp;BorderSkin&nbsp;&raquo; via la fonction getStyle, or cette fonction renvoie depuis l&#8217;arrivée de Spark, une classe Spark, là où une classe mx était demandée, Résultat, crash à l&#8217;instanciation. J&#8217;avoue ne pas avoir pris le temps de le corriger pour m&#8217;en servir, d&#8217;autant que les cadres autour des images, je m&#8217;en moque un peu, j&#8217;ai donc juste retiré la fonctionnalité de la manière suivante :</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>127<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> borderClass:<span style="color: #000000; font-weight: bold;">Class</span>;<span style="color: #808080; font-style: italic;">// = getStyle(&quot;borderSkin&quot;);</span></div></td></tr></tbody></table></div>
<p>Pas très élégant, mais suffisant. Promis, bientôt je regarderais comment corriger et remettre les bordures.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fxbt.info/devblog/2010/08/18/superimage-ou-comment-eviter-le-desagreable-clignotement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Créer un événement personnalisé et l’attacher à un composant (Partie 3 fin)</title>
		<link>http://www.fxbt.info/devblog/2010/05/31/creer-un-evenement-personnalise-et-l%e2%80%99attacher-a-un-composant-partie-3-fin/</link>
		<comments>http://www.fxbt.info/devblog/2010/05/31/creer-un-evenement-personnalise-et-l%e2%80%99attacher-a-un-composant-partie-3-fin/#comments</comments>
		<pubDate>Mon, 31 May 2010 08:56:24 +0000</pubDate>
		<dc:creator>fx</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Evénement]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[MXLM]]></category>

		<guid isPermaLink="false">http://www.fxbt.info/devblog/?p=62</guid>
		<description><![CDATA[Et voici venir la dernière partie de cette petite explication sur les événements personnalisés en Flex. Dans cette partie, nous allons voir comment ajouter le composant à notre application et comment utiliser les événements qui lui sont attachés. Commençons par revenir dans le composant principal de notre projet qui pour l&#8217;instant se présente comme ceci ]]></description>
			<content:encoded><![CDATA[<p>Et voici venir la dernière partie de cette petite explication sur les événements personnalisés en Flex. Dans cette partie, nous allons voir comment ajouter le composant à notre application et comment utiliser les événements qui lui sont attachés.</p>
<p>Commençons par revenir dans le composant principal de notre projet qui pour l&#8217;instant se présente comme ceci :</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span><br />
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:WindowedApplication</span></span><br />
<span style="color: #000000;">&nbsp; &nbsp; xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span><br />
<span style="color: #000000;">&nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #7400FF;">&gt;</span></span><br />
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:WindowedApplication</span><span style="color: #7400FF;">&gt;</span></span></div></td></tr></tbody></table></div>
<p>Nous allons d&#8217;abord ajouter un label, il servira à garder le calcul que nous réalisons, en effet notre application permet de rentrer un chiffre et en cliquant sur plus ou moins, de ajouter/soustraire à notre valeur en cours.</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Calcul : {calcul}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></div></td></tr></tbody></table></div>
<p>Comme vous le voyez, nous faisons appel à une variable calcul, il faut donc que nous la déclarions quelque part. Et quoi de mieux que le bloc des déclarations pour ça ?</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Number</span> id=<span style="color: #ff0000;">&quot;calcul&quot;</span> <span style="color: #7400FF;">&gt;</span></span>0<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Number</span><span style="color: #7400FF;">&gt;</span></span><br />
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span></div></td></tr></tbody></table></div>
<p>Nous allons ajouter le composant directement à partir de la vue Source. FlexBuilder permet de le faire rapidement, juste en tapant le début du nom de notre composant et en se servant de l&#8217;auto-complétion. Si vous n&#8217;utilisez pas FlexBuilder, il suffit de rajouter le namespace de notre composant <code class="codecolorer text twitlight"><span class="text">xmlns:renderers=&quot;info.fxbt.devblog.renderers.*&quot;</span></code> et de rajouter le composant <code class="codecolorer text twitlight"><span class="text">&lt;renderers:ButtonsCompo id=&quot;bc&quot; /&gt;</span></code></p>
<p>On s&#8217;aperçoit ensuite que ce composant a deux événements qui nous sont connus <code class="codecolorer text twitlight"><span class="text">plusClick</span></code> et <code class="codecolorer text twitlight"><span class="text">minusClick</span></code> on va leur attribuer un event Handler (notez qu&#8217;il est possible d&#8217;attribuer un event Handler différent à chaque événement, ce que propose par défaut FlexBuilder par exemple, mais ici, les événements ont été fait de tel façon qu&#8217;on peut traiter les deux dans le même event Handler).</p>
<p>On se retrouve avec notre composant qui est défini de la façon suivante :</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;"><span style="color: #7400FF;">&lt;renderers:ButtonsCompo</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; id=<span style="color: #ff0000;">&quot;bc&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; plusClick=<span style="color: #ff0000;">&quot;bc_plusminusClickHandler(event)&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; minusClick=<span style="color: #ff0000;">&quot;bc_plusminusClickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></div></td></tr></tbody></table></div>
<p>Il faut donc maintenant définir la fonction <code class="codecolorer text twitlight"><span class="text">bc_plusminusClickHandler</span></code>. Cette fonction va, en fonction du type de l&#8217;événement qu&#8217;elle prend en paramètre, ajouter ou soustraire le chiffre contenu dans la zone de texte à notre total.</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> bc_plusminusClickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>TestEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> == TestEvent<span style="color: #000066; font-weight: bold;">.</span>PLUS_CLICKED <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; calcul <span style="color: #000066; font-weight: bold;">+</span>= event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; calcul <span style="color: #000066; font-weight: bold;">-</span>= event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Et voici, notre programme est capable de calculer des additions et des soustractions (comment ça il ne va pas servir à grand chose ? :-p )</p>
<p>Vous avez remarqué qu&#8217;il y a des erreurs possibles, en effet, on peut mettre des lettres dans la zone de texte et tenter de les additionner à notre total&#8230; Ce qui ne manquera pas de lever une erreur.</p>
<p>Voici le code total de notre application :</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span><br />
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:WindowedApplication</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; xmlns:renderers=<span style="color: #ff0000;">&quot;info.fxbt.devblog.renderers.*&quot;</span> <span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; import info.fxbt.devblog.events.TestEvent;</span><br />
<br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected function bc_plusminusClickHandler<span style="color: #66cc66;">&#40;</span>event:TestEvent<span style="color: #66cc66;">&#41;</span>:void</span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if<span style="color: #66cc66;">&#40;</span> event.type == TestEvent.PLUS_CLICKED <span style="color: #66cc66;">&#41;</span></span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calcul += event.value;</span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else</span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calcul -= event.value;</span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></span><br />
<br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Number</span> id=<span style="color: #ff0000;">&quot;calcul&quot;</span> <span style="color: #7400FF;">&gt;</span></span>0<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Number</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span><span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Calcul : {calcul}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;renderers:ButtonsCompo</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; id=<span style="color: #ff0000;">&quot;bc&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; plusClick=<span style="color: #ff0000;">&quot;bc_plusminusClickHandler(event)&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; minusClick=<span style="color: #ff0000;">&quot;bc_plusminusClickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:WindowedApplication</span><span style="color: #7400FF;">&gt;</span></span></div></td></tr></tbody></table></div>
<p>Et si on veut utiliser plusieurs fois notre composant ? Et bien ce n&#8217;est pas plus compliqué qu&#8217;avec un bouton ou tout autre composant classique.</p>
<p>Voici rapidement le code à rajouter.</p>
<p>Pour la partie définition du composant :</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;renderers:ButtonsCompo</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; id=<span style="color: #ff0000;">&quot;bc10&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; plusClick=<span style="color: #ff0000;">&quot;bc10_plusminusClickHandler(event)&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; minusClick=<span style="color: #ff0000;">&quot;bc10_plusminusClickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></div></td></tr></tbody></table></div>
<p>Pour la partie définition de l&#8217;event Handler :</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> bc10_plusminusClickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>TestEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> == TestEvent<span style="color: #000066; font-weight: bold;">.</span>PLUS_CLICKED <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; calcul <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000066; font-weight: bold;">*</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; calcul <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000066; font-weight: bold;">*</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Et ainsi, notre application est capable de soustraire/additionner les facteurs de 10 (de plus en plus fort :-p)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fxbt.info/devblog/2010/05/31/creer-un-evenement-personnalise-et-l%e2%80%99attacher-a-un-composant-partie-3-fin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Créer un événement personnalisé et l’attacher à un composant (Partie 2)</title>
		<link>http://www.fxbt.info/devblog/2010/05/27/creer-un-evenement-personnalise-et-l%e2%80%99attacher-a-un-composant-partie-2/</link>
		<comments>http://www.fxbt.info/devblog/2010/05/27/creer-un-evenement-personnalise-et-l%e2%80%99attacher-a-un-composant-partie-2/#comments</comments>
		<pubDate>Thu, 27 May 2010 15:32:29 +0000</pubDate>
		<dc:creator>fx</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Event]]></category>

		<guid isPermaLink="false">http://www.fxbt.info/devblog/?p=48</guid>
		<description><![CDATA[Voici la suite du précédent article concernant les événements personnalisés et leur rattachement aux composants. Dans cette partie, nous allons voir comment attacher un événement à un composant, comment le dispatcher. Attacher un événement à un composant Repartons de notre composant précédent, de ses deux boutons et de son champ de texte. Nous allons d&#8217;abord ]]></description>
			<content:encoded><![CDATA[<p>Voici la suite du précédent article concernant les événements personnalisés et leur rattachement aux composants.</p>
<p>Dans cette partie, nous allons voir comment attacher un événement à un composant, comment le dispatcher.</p>
<h1><span style="color: #ff6600;">Attacher un événement à un composant</span></h1>
<p>Repartons de notre composant précédent, de ses deux boutons et de son champ de texte. Nous allons d&#8217;abord ajouter à ce composant un événement. Pour cela nous ajoutons le code suivant :</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; [Event(name=&quot;plusClick&quot;, type=&quot;info.fxbt.devblog.events.TestEvent&quot;)]<br />
&nbsp; &nbsp; &nbsp; &nbsp; [Event(name=&quot;minusClick&quot;, type=&quot;info.fxbt.devblog.events.TestEvent&quot;)]<br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span></div></td></tr></tbody></table></div>
<p>On utilise pour ça une balise Metadata, cette balise sert en fait à préciser au compilateur Flex comment sont utilisés vos composants. Vous pouvez trouver une plus grande information en anglais dans les pages suivantes : <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_2.html">About metadata tags</a> et <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_3.html">Metadata tags</a>.</p>
<p>Vous devez donc définir le nom de l&#8217;événement et son type. Là, j&#8217;avoue que les noms des attributs qu&#8217;ils ont choisis sont assez mauvais, en effet il y a confusion entre <code class="codecolorer text twitlight"><span class="text">name</span></code> et <code class="codecolorer text twitlight"><span class="text">type</span></code>. Car ici, le <code class="codecolorer text twitlight"><span class="text">type</span></code> correspond en fait à la classe de l&#8217;événement, et le <code class="codecolorer text twitlight"><span class="text">name</span></code> correspond lui au type tel qu&#8217;il est défini dans la classe de l&#8217;événement (le type que l&#8217;on doit définir lorsqu&#8217;on définie une nouvelle instance de cet événement.</p>
<p>Pourquoi je disais avant qu&#8217;il ne fallait pas que la valeur que vous donniez à votre type soit trop idiote ? Tout simplement car vous la retrouvez ici, cette valeur est celle que vous mettez dans <code class="codecolorer text twitlight"><span class="text">name</span></code>, c&#8217;est celle que vous retrouverez dans l&#8217;interface de votre composant (on va voir où juste après).</p>
<p>Vous avez donc ajouté deux événements déclenchables par votre composant. Maintenant, on va faire en sorte que ces événements se dispatchent.</p>
<h1><span style="color: #ff6600;">Dispatcher un événement</span></h1>
<p>On veut que les événements se dispatchent lorsque l&#8217;on clique sur l&#8217;un des deux boutons.</p>
<p>Pour cela, on peut utiliser plusieurs moyens, le plus rapide est d&#8217;utiliser l&#8217;IDE (si vous l&#8217;avez sinon il y aura le code marqué un peu plus loin <img src='http://www.fxbt.info/devblog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ) pour lui faire générer ce qu&#8217;il faut, c&#8217;est ce que l&#8217;on va faire ici. Retournez sur le composant préalablement créé et allez en mode Création, cliquez sur le bouton <strong>+</strong>, et repérez dans les propriétés le champ <em>Lors d&#8217;un clic</em>, il y a un éclair à côté, cliquez dessus et sélectionnez <em>Générer un gestionnaire d&#8217;événement</em> l&#8217;IDE vous a alors généré la fonction a appeler (et a associé à l&#8217;événement <cci>click</cci> le code généré. Vous n&#8217;avez plus qu&#8217;à remplacer le commentaire par votre code. Ce sera le suivant :</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>15<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> TestEvent<span style="color: #000000;">&#40;</span>TestEvent<span style="color: #000066; font-weight: bold;">.</span>PLUS_CLICKED<span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">parseFloat</span><span style="color: #000000;">&#40;</span>tiValue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Pour le second bouton, on va innover. Restez en mode Source, et trouvez le bouton <strong>-</strong>. Utilisez l&#8217;auto-complétion pour générer l&#8217;événement <cci>click</cci>. Le code de la fonction sera :</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>20<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> TestEvent<span style="color: #000000;">&#40;</span>TestEvent<span style="color: #000066; font-weight: bold;">.</span>MINUS_CLICKED<span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">parseFloat</span><span style="color: #000000;">&#40;</span>tiValue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>On a donc généré le code suivant pour la partie script (fonctions récupérant l&#8217;événement click des boutons) :</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>fxbt<span style="color: #000066; font-weight: bold;">.</span>devblog<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>TestEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> btnPlus_clickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> TestEvent<span style="color: #000000;">&#40;</span>TestEvent<span style="color: #000066; font-weight: bold;">.</span>PLUS_CLICKED<span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">parseFloat</span><span style="color: #000000;">&#40;</span>tiValue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> btnMoins_clickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> TestEvent<span style="color: #000000;">&#40;</span>TestEvent<span style="color: #000066; font-weight: bold;">.</span>MINUS_CLICKED<span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">parseFloat</span><span style="color: #000000;">&#40;</span>tiValue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>fx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Et pour les boutons :</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>30<br />31<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;btnPlus&quot;</span> label=<span style="color: #ff0000;">&quot;+&quot;</span> click=<span style="color: #ff0000;">&quot;btnPlus_clickHandler(event)&quot;</span><span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;btnMoins&quot;</span> label=<span style="color: #ff0000;">&quot;-&quot;</span> click=<span style="color: #ff0000;">&quot;btnMoins_clickHandler(event)&quot;</span><span style="color: #7400FF;">/&gt;</span></span></div></td></tr></tbody></table></div>
<p>Notez qu&#8217;il aurait été possible de ne pas passer par les fonctions intermédiaires, mais d&#8217;appeler directement le <code class="codecolorer text twitlight"><span class="text">dispatchEvent</span></code> dans les valeurs <code class="codecolorer text twitlight"><span class="text">click</span></code>.</p>
<p>Dans la prochaine et dernière partie, nous verrons comment se présente le composant ainsi créé et comment l&#8217;ajouter et utiliser ses événements dans notre application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fxbt.info/devblog/2010/05/27/creer-un-evenement-personnalise-et-l%e2%80%99attacher-a-un-composant-partie-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Créer un événement personnalisé et l&#8217;attacher à un composant (Partie 1)</title>
		<link>http://www.fxbt.info/devblog/2010/05/27/creer-un-evenement-personnalise-et-lattacher-a-un-composant-partie-1/</link>
		<comments>http://www.fxbt.info/devblog/2010/05/27/creer-un-evenement-personnalise-et-lattacher-a-un-composant-partie-1/#comments</comments>
		<pubDate>Thu, 27 May 2010 12:54:00 +0000</pubDate>
		<dc:creator>fx</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Création]]></category>
		<category><![CDATA[Evénement]]></category>
		<category><![CDATA[MXLM]]></category>

		<guid isPermaLink="false">http://www.fxbt.info/devblog/?p=11</guid>
		<description><![CDATA[Dans une application Flex complète, on a souvent besoin de faire communiquer des composants entre eux, de faire remonter l&#8217;information des composants fils vers les composants parents. Quoi de mieux alors que d&#8217;utiliser le mécanisme d&#8217;événement sur un événement pour que celui-ci alerte son parent ? Dans cette optique, nous allons voir comment créer un ]]></description>
			<content:encoded><![CDATA[<p>Dans une application Flex complète, on a souvent besoin de faire communiquer des composants entre eux, de faire remonter l&#8217;information des composants fils vers les composants parents. Quoi de mieux alors que d&#8217;utiliser le mécanisme d&#8217;événement sur un événement pour que celui-ci alerte son parent ?</p>
<p>Dans cette optique, nous allons voir comment créer un événement personnalisé, puis comment ajouter cet événement à un composant pour que celui-ci soit capable de présenter l&#8217;événement lors d&#8217;une utilisation via l&#8217;éditeur.</p>
<p>Pour toutes ces explications, nous allons faire une petite application (AIR pour ma part ça évite de lancer un navigateur web <img src='http://www.fxbt.info/devblog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  mais cela fonctionne de la même façon avec une application Flex classique). Cette application sera composée des choses suivantes : un composant possédant deux boutons et un emplacement pour entrer du texte; un composant principal qui contiendra le précédent composant ainsi qu&#8217;un label qui nous affichera des valeurs. Notre application sera capable seulement d&#8217;additionner ou de soustraire des chiffres entre eux.</p>
<h1><span style="color: #ff6600;">Créer notre composant avec boutons</span></h1>
<p>Je pars du principe que vous savez comment faire, utilisez soit la vue Source, soit la vue Création, ça va presque aussi vite dans un cas comme dans l&#8217;autre. Ce que l&#8217;on obtient au niveau visuel est la chose suivante :</p>
<p><a href="http://www.fxbt.info/devblog/wp-content/uploads/2010/05/events_01.png"><img src="http://www.fxbt.info/devblog/wp-content/uploads/2010/05/events_01.png" alt="" title="events_01" width="355" height="29" class="aligncenter size-full wp-image-34" /></a></p>
<p>Le code MXML quand à lui est le suivant :</p>
<div class="codecolorer-container mxml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span><br />
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; height=<span style="color: #ff0000;">&quot;23&quot;</span> width=<span style="color: #ff0000;">&quot;350&quot;</span><span style="color: #7400FF;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Spacer</span><span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Valeur :&quot;</span> fontWeight=<span style="color: #ff0000;">&quot;bold&quot;</span> </span><br />
<span style="color: #000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height=<span style="color: #ff0000;">&quot;100%&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> id=<span style="color: #ff0000;">&quot;tiValue&quot;</span> <span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Spacer</span><span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;btnPlus&quot;</span> label=<span style="color: #ff0000;">&quot;+&quot;</span><span style="color: #7400FF;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;btnMoins&quot;</span> label=<span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #7400FF;">/&gt;</span></span><br />
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span></div></td></tr></tbody></table></div>
<h1><span style="color: #ff6600;">Créer un événement</span></h1>
<p>Ensuite, nous créons l&#8217;événement. Pour cela, on créé une nouvelle <em>Classe ActionScript</em> nommé <span style="color: #c0c0c0;"><strong>TestEvent</strong></span><strong> </strong>qui va étendre la classe <span style="color: #c0c0c0;"><strong>flash.events.Event</strong></span>. Le code ainsi créé sera le suivant :</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>fxbt<span style="color: #000066; font-weight: bold;">.</span>devblog<span style="color: #000066; font-weight: bold;">.</span>events<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TestEvent <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Event</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TestEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>C&#8217;est un bon début, mais notre événement, nous voulons qu&#8217;il propose deux types, l&#8217;un pour le bouton <strong>+</strong>, l&#8217;autre pour le bouton <strong>-</strong>. Ce manière très simple, on rajoute ces deux types :</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>14<br />15<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const PLUS_CLICKED<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;plusClick&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const MINUS_CLICKED<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;minusClick&quot;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Notez qu&#8217;il ne faut pas donner des valeurs à ces constantes trop idiotes, vous allez voir après pourquoi.</p>
<p>On rajoute à ça la valeur qui sera transférée dans l&#8217;événement.</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>17<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>On va même rajouter un constructeur pour pouvoir créer l&#8217;événement en une seule fois avec la valeur en question directement définie.</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TestEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span> = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Vous remarquerez que je n&#8217;ai pas remis dans le constructeur les paramètres <code class="codecolorer text twitlight"><span class="text">bubbles:Boolean=false, cancelable:Boolean=false</span></code>, dans notre cas ils ne sont pas forcément utiles, et cela fera peut-être l&#8217;objet d&#8217;un billet plus tard (je supprimerais d&#8217;ailleurs le constructeur les contenant dans le récapitulatif du code).</p>
<p>On obtient donc le code suivant pour cette classe :</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>fxbt<span style="color: #000066; font-weight: bold;">.</span>devblog<span style="color: #000066; font-weight: bold;">.</span>events<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TestEvent <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Event</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TestEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span> = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const PLUS_CLICKED<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;plusClick&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const MINUS_CLICKED<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;minusClick&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Dans la prochaine partie, nous attacherons l&#8217;événement au composant préalablement réalisé.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fxbt.info/devblog/2010/05/27/creer-un-evenement-personnalise-et-lattacher-a-un-composant-partie-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ouverture du Blog</title>
		<link>http://www.fxbt.info/devblog/2010/05/24/ouverture-du-blog/</link>
		<comments>http://www.fxbt.info/devblog/2010/05/24/ouverture-du-blog/#comments</comments>
		<pubDate>Mon, 24 May 2010 12:29:32 +0000</pubDate>
		<dc:creator>fx</dc:creator>
				<category><![CDATA[Vie du Blog]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[ouverture]]></category>
		<category><![CDATA[triominos]]></category>

		<guid isPermaLink="false">http://www.fxbt.info/devblog/?p=9</guid>
		<description><![CDATA[Bon, finalement, bien que je ne sois pas fan des blogs, je me décide à en ouvrir (et non pas un, mais deux carrément, le second étant un blog photo où je tenterais &#8211; mais ça me parait pas gagné &#8211; de mettre une nouvelle photo par jour). J&#8217;ouvre donc ce blog ci dans le ]]></description>
			<content:encoded><![CDATA[<p>Bon, finalement, bien que je ne sois pas fan des blogs, je me décide à en ouvrir (et non pas un, mais deux carrément, le second étant un blog photo où je tenterais &#8211; mais ça me parait pas gagné &#8211; de mettre une nouvelle photo par jour).</p>
<p>J&#8217;ouvre donc ce blog ci dans le but de partager un peu (et surtout de garder une trace). Partager, car j&#8217;aime bien le concept même de partage (je suis un grand fan des blogs des Devs Adobe), et surtout quand il s&#8217;agit de points des fois assez techniques qui nous tiennent tête pendant plusieurs heures/jours.</p>
<p>J&#8217;avoue qu&#8217;une autre raison de l&#8217;ouverture de ce blog est que j&#8217;ai quelques projets sur le feu, et que j&#8217;ai bien l&#8217;intention de les diffuser en libre (probablement sur sourceforge), et donc que je discuterais surement là dessus.</p>
<p>Parmis ces projets, l&#8217;un est un petit programme fait pendant mes vacances, en bon informaticien, plutôt que  d&#8217;utiliser le couple papier/crayon pour compter les points du Triominos (pour ceux qui ne connaissent pas, regardez l&#8217;article de <a href="http://en.wikipedia.org/wiki/Triominoes" target="_blank">Wikipedia</a> &#8211; en anglais, désolé), j&#8217;ai préféré faire un petit programme en Flex, maintenant je pense sérieusement à le finir (oui, il y a des variables en dur actuellement), et à pourquoi pas, rajouter un mécanisme pour jouer en ligne avec (et quelques graphismes aussi, actuellement ça pique les yeux). Un autre projet est un viewer FlickR permettant de récupérer les photos, naviguer dans ses contacts, favoris, les contacts et favoris de notre navigation, tout un programme, et déjà certains composants me semblent intéressant en eux même.</p>
<p>J&#8217;ouvre donc ce blog pour continuer à discuter là dessus et pourquoi pas, pour avoir des visiteurs (je sais, je rève un peu).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fxbt.info/devblog/2010/05/24/ouverture-du-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

