<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Me, Myself And I</title>
	
	<link>http://www.palleas.com</link>
	<description />
	<lastBuildDate>Fri, 03 Jul 2009 21:38:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /><meta xmlns="http://pipes.yahoo.com" name="pipes" content="noprocess" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/palleas" type="application/rss+xml" /><item>
		<title>FlashMediaServer 3.5 et onBWdone : QuickFix</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/p1B5BJmaPjM/</link>
		<comments>http://www.palleas.com/fr/2009/07/03/flashmediaserver-3-5-et-onbwdone-quickfix/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 21:34:36 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.palleas.com/fr/?p=900</guid>
		<description><![CDATA[
Pour quelques tests, j&#8217;ai installé Flash Media Server (la version gratuite, quand même) sur ma machine. Seulement voilà, j&#8217;ai réussi à avoir un soucis dès le lancement de mon application, avec un code d&#8217;à peine quelques lignes.



protected function connect&#40;&#41;:void &#123;
	var connexion:NetConnection = new NetConnection&#40;&#41;;
	connexion.connect&#40;&#34;rtmp://localhost/vod&#34;&#41;;
&#125;


Au lancement de mon application, j&#8217;avais l&#8217;erreur suivante :
Error #2044: AsyncErrorEvent non [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.palleas.com/wp-content/uploads/2009/07/flash_media_server_3.jpg"><img src="http://www.palleas.com/wp-content/uploads/2009/07/flash_media_server_3.jpg" alt="flash_media_server_3" title="flash_media_server_3" width="175" height="171" class="aligncenter size-full wp-image-901" /></a></p>
<p>Pour quelques tests, j&#8217;ai installé Flash Media Server (la version gratuite, quand même) sur ma machine. Seulement voilà, j&#8217;ai réussi à avoir un soucis dès le lancement de mon application, avec un code d&#8217;à peine quelques lignes.</p>
<p><span id="more-900"></span><br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> connexion:<span style="color: #0066CC;">NetConnection</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	connexion.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;rtmp://localhost/vod&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Au lancement de mon application, j&#8217;avais l&#8217;erreur suivante :</p>
<blockquote><p>Error #2044: AsyncErrorEvent non pris en charge : text=Error #2095: flash.net.NetConnection n’a pas été en mesure d’appeler l’élément de rappel onBWDone. error=ReferenceError: Error #1069: La propriété onBWDone est introuvable sur flash.net.NetConnection et il n&#8217;existe pas de valeur par défaut.<br />
	at Main/connect()[C:\Documents and Settings\palleas\Mes documents\flash\FlashMediaServerTest\src\Main.as:18]<br />
	at Main()[C:\Documents and Settings\palleas\Mes documents\flash\FlashMediaServerTest\src\Main.as:12]</p></blockquote>
<p>J&#8217;ai pas mal cherché sur le net et j&#8217;ai finalement trouvé la solution en fouillant la documentation sur <a href="http://www.adobe.com/support/documentation/en/flashmediaserver/documentation.html">le site d&#8217;Adobe</a>, elle est vraiment toute bête. On commence par spécifier la propriété &#8220;client&#8221; de l&#8217;objet NetConnexion, en lui mettant la valeur &#8220;this&#8221; :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> connexion:<span style="color: #0066CC;">NetConnection</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	connexion.<span style="color: #006600;">client</span> = <span style="color: #0066CC;">this</span>;
	connexion:<span style="color: #0066CC;">NetConnection</span> .<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;rtmp://localhost/vod&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>On déclare ensuite une méthode vide nommée &#8220;onBWDone&#8221;, vu que c&#8217;est ce que cherche Flash finalement :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onBWDone<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onBWDone !&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Et voilà! Je démarre juste avec Flash Media Server, je poste cette astuce ici parce qu&#8217;elle m&#8217;a empêché de démarrer, je ne le ferais pas pour chaque bug que je corrige, mais plus probablement un billet plus conséquent par la suite.</p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/p1B5BJmaPjM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/07/03/flashmediaserver-3-5-et-onbwdone-quickfix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/07/03/flashmediaserver-3-5-et-onbwdone-quickfix/</feedburner:origLink></item>
		<item>
		<title>Fermer une fenêtre pop-up en cliquant sur le modal</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/p4a27uRwLLg/</link>
		<comments>http://www.palleas.com/fr/2009/06/24/fermer-une-fenetre-pop-up-en-cliquant-sur-le-modal/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 07:24:40 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.palleas.com/fr/?p=890</guid>
		<description><![CDATA[Le titre est un peu moins classe en français qu&#8217;en anglais, mais tant pis. Le modal (j&#8217;ai supposé que c&#8217;était &#8220;un&#8221; modal, vu qu&#8217;en anglais on ne se pose pas la question) est la zone noire semi transparente qui s&#8217;affiche sous une fenêtre créée par le PopupManager de Flex. Il est possible de fermer cette [...]]]></description>
			<content:encoded><![CDATA[<p>Le titre est un peu moins classe en français qu&#8217;en anglais, mais tant pis. Le modal (j&#8217;ai supposé que c&#8217;était &#8220;un&#8221; modal, vu qu&#8217;en anglais on ne se pose pas la question) est la zone noire semi transparente qui s&#8217;affiche sous une fenêtre créée par le PopupManager de Flex. Il est possible de fermer cette popup en cliquant sur cette zone, et voici une manière de procéder.</p>
<p><span id="more-890"></span></p>
<p>Pour commencer, la &#8220;popup&#8221; affichée sera un simple composant Group, affichant une image (via le composant BitmapImage) :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><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>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> 	xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">			xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">			xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/halo&quot;</span> </span>
<span style="color: #000000;">			width=<span style="color: #ff0000;">&quot;253&quot;</span> height=<span style="color: #ff0000;">&quot;300&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #7400FF;">/&gt;</span><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:BitmapImage</span> source=<span style="color: #ff0000;">&quot;@Embed('assets/lolcat.jpg')&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Group</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p></code></p>
<p>L&#8217;application accueillant cette popup ne comprendra qu&#8217;un bouton déclenchant l&#8217;ouverture de ladite popup :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><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>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/halo&quot;</span> minWidth=<span style="color: #ff0000;">&quot;1024&quot;</span> minHeight=<span style="color: #ff0000;">&quot;768&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;init(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span> source=<span style="color: #ff0000;">&quot;global.as&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;openButton&quot;</span> label=<span style="color: #ff0000;">&quot;Open window&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p></code></p>
<p>Cette popup sera donc affichée lors d&#8217;un clique sur le bouton prévu. Ce fonctionnement étant mis en place en écoutant l&#8217;évènement qui va bien, et en utilisant ensuite la classe PopupManager :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">CustomPopup</span>;
&nbsp;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">containers</span>.<span style="color: #006600;">TitleWindow</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">managers</span>.<span style="color: #006600;">PopUpManager</span>;
&nbsp;
<span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">primitives</span>.<span style="color: #006600;">SimpleText</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	openButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>,onOpenClick<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onOpenClick<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> window:CustomPopup = PopUpManager.<span style="color: #006600;">createPopUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>,CustomPopup,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> as CustomPopup;
	PopUpManager.<span style="color: #006600;">centerPopUp</span><span style="color: #66cc66;">&#40;</span>window<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Voici donc ce qui s&#8217;affichera : </p>
<p><a href="http://www.palleas.com/wp-content/uploads/2009/06/popup.jpg"><img src="http://www.palleas.com/wp-content/uploads/2009/06/popup.jpg" alt="popup" title="popup" width="509" height="429" class="aligncenter size-full wp-image-891" /></a></p>
<p>Maintenant, pour que la popup se ferme lorsque l&#8217;on clique sur le modal, il suffit en réalité d&#8217;écouter le click <strong>en dehors</strong> de la popup. Sachant que le modal permet de désactiver le reste de l&#8217;interface, un clique en dehors de la popup est forcément un clique sur cette modal. Pour ce faire, il suffit d&#8217;utiliser l&#8217;évènement FlexMouseEvent (toujours dans la méthode créant la popup) :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onOpenClick<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> window:CustomPopup = PopUpManager.<span style="color: #006600;">createPopUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>,CustomPopup,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> as CustomPopup;
	PopUpManager.<span style="color: #006600;">centerPopUp</span><span style="color: #66cc66;">&#40;</span>window<span style="color: #66cc66;">&#41;</span>;
	window.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FlexMouseEvent.<span style="color: #006600;">MOUSE_DOWN_OUTSIDE</span>,onModalClick<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onModalClick<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FlexMouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	PopUpManager.<span style="color: #006600;">removePopUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">currentTarget</span> as CustomPopup<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Et voilà !</p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/p4a27uRwLLg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/06/24/fermer-une-fenetre-pop-up-en-cliquant-sur-le-modal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/06/24/fermer-une-fenetre-pop-up-en-cliquant-sur-le-modal/</feedburner:origLink></item>
		<item>
		<title>URL Preview dans une application AIR</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/CvCP0K1CIvk/</link>
		<comments>http://www.palleas.com/fr/2009/06/23/url-preview-dans-une-application-air/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 11:37:48 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.palleas.com/fr/?p=876</guid>
		<description><![CDATA[
DestroyTwitter est pour moi le client Twitter le plus réussi. Il propose une fonctionnalité très intérressante qui est de pouvoir prévisualiser une URL. En cliquant sur une URL dans un tweet en ayant la touche &#8220;alt&#8221; pressée, il est possible d&#8217;avoir le titre de la page pointée ainsi que l&#8217;url finale, ce qui est très [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.palleas.com/wp-content/uploads/2009/06/urlpreview.jpg" alt="urlpreview" title="urlpreview" width="320" height="118" class="aligncenter size-full wp-image-877" /></p>
<p>DestroyTwitter est pour moi le client Twitter le plus réussi. Il propose une fonctionnalité très intérressante qui est de pouvoir prévisualiser une URL. En cliquant sur une URL dans un tweet en ayant la touche &#8220;alt&#8221; pressée, il est possible d&#8217;avoir le titre de la page pointée ainsi que l&#8217;url <strong>finale</strong>, ce qui est très pratique dans le cas d&#8217;url réduites.</p>
<p><span id="more-876"></span></p>
<p>Ce genre de fonctionnalité est très simple à implémenter dans une application AIR, grâce au composant URLLoader et aux évènements disponibles s&#8217;il est utilisé dans AIR, notamment HTTPStatusEvent. Pour commencer, nous allons créer une interface simpliste : </p>
<p><img src="http://www.palleas.com/wp-content/uploads/2009/06/URLPreviewAPP.jpg" alt="URLPreviewAPP" title="URLPreviewAPP" width="511" height="146" class="aligncenter size-full wp-image-878" /></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><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>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:WindowedApplication</span> 	xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">						xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">						xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/halo&quot;</span></span>
<span style="color: #000000;">						creationComplete=<span style="color: #ff0000;">&quot;init(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span> source=<span style="color: #ff0000;">&quot;global.as&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;5&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;5&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> id=<span style="color: #ff0000;">&quot;urlToPreview&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;previewButton&quot;</span> label=<span style="color: #ff0000;">&quot;Preview&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleText</span> id=<span style="color: #ff0000;">&quot;urlFinal&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:WindowedApplication</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p></code></p>
<p>Ensuite, il suffit de faire en sorte d&#8217;envoyer une requête vers l&#8217;URL spécifiée dans le champs de texte, d&#8217;écouter l&#8217;évènement &#8220;httpResponseStatus&#8221; diffusé par notre URLLoader, et de récupérer l&#8217;url finale accessible depuis la propriété &#8220;responseURL&#8221; du dit évènement :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	previewButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>,onPreviewClick<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onPreviewClick<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>urlToPreview.<span style="color: #0066CC;">text</span>==<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;URL invalide !&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> loader:URLLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>HTTPStatusEvent.<span style="color: #006600;">HTTP_RESPONSE_STATUS</span>,onHTTPResponse<span style="color: #66cc66;">&#41;</span>;
		loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>urlToPreview.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onHTTPResponse<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:HTTPStatusEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> finalURL:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">responseURL</span>;
	urlFinal.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;URL finale = &quot;</span>+finalURL;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Et voila le résultat :</p>
<p><img src="http://www.palleas.com/wp-content/uploads/2009/06/urlpreviewfinal.jpg" alt="urlpreviewfinal" title="urlpreviewfinal" width="625" height="84" class="aligncenter size-full wp-image-880" /></p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/CvCP0K1CIvk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/06/23/url-preview-dans-une-application-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/06/23/url-preview-dans-une-application-air/</feedburner:origLink></item>
		<item>
		<title>JDBC : connaître la valeur d’un champ auto-incrémenté</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/dbALULYRhmw/</link>
		<comments>http://www.palleas.com/fr/2009/06/21/jdbc-connaitre-la-valeur-dun-champ-auto-incremente/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 18:00:54 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.palleas.com/fr/?p=868</guid>
		<description><![CDATA[Dans ma base de données, j&#8217;ai une table contenant la liste de mes personnages dont la structure est la suivante (je n&#8217;affiche que les premiers champs) :

Ma méthode d&#8217;une classe Java doit faire une insertion dans cette table, et me retourner l&#8217;id (déclaré en clé primaire auto incrémentée), du coup voilà une manière de procéder [...]]]></description>
			<content:encoded><![CDATA[<p>Dans ma base de données, j&#8217;ai une table contenant la liste de mes personnages dont la structure est la suivante (je n&#8217;affiche que les premiers champs) :</p>
<p><img src="http://www.palleas.com/wp-content/uploads/2009/06/toshentablecharacter.jpg" alt="toshentablecharacter" title="toshentablecharacter" width="599" height="92" class="aligncenter size-full wp-image-869" /></p>
<p>Ma méthode d&#8217;une classe Java doit faire une insertion dans cette table, et me retourner l&#8217;id (déclaré en clé primaire auto incrémentée), du coup voilà une manière de procéder :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> doInsert<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> query<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">Connection</span> handle <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jdbc:mysql://localhost/toshen?user=root&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Statement</span> stmt <span style="color: #339933;">=</span> handle.<span style="color: #006633;">createStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			stmt.<span style="color: #006633;">executeUpdate</span><span style="color: #009900;">&#40;</span>query,<span style="color: #003399;">Statement</span>.<span style="color: #006633;">RETURN_GENERATED_KEYS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">ResultSet</span> keys <span style="color: #339933;">=</span> stmt.<span style="color: #006633;">getGeneratedKeys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>keys.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">int</span> id <span style="color: #339933;">=</span> keys.<span style="color: #006633;">getInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ID inseré = &quot;</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Something went wrong : &quot;</span><span style="color: #339933;">+</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p></code></p>
<p>J&#8217;utilise cette méthode ainsi :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// ...</span>
doInsert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO characters(charact_name,gender,alignment) VALUES('Palleas','m','Loyal')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// ...</span></pre></div></div>

<p></code></p>
<p>Il ne vous manquera que les imports qui vont bien (sachant que Connection, Statement et ResultSet viennent du package <a href="http://java.sun.com/j2se/1.3/docs/api/java/sql/package-summary.html">java.sql</a>), tout devrait fonctionner. Le executeUpdate prend en deuxième paramètre un flag. Il est obligatoire et permet de demander explicitement à Java de retourner les clés générées en retour. Sans ce flag, utiliser la méthode getGeneratedKeys() lèvera une exception de type <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/SQLException.html">SQLException</a>. Le test sur la méthode &#8220;next&#8221; du <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html">ResultSet</a> est important, il décale en effet le pointeur sur le tuple suivant (donc ici le premier) et vérifie que celui-ci existe, sans ça vous n&#8217;aurez pas accès aux clés.</p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/dbALULYRhmw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/06/21/jdbc-connaitre-la-valeur-dun-champ-auto-incremente/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/06/21/jdbc-connaitre-la-valeur-dun-champ-auto-incremente/</feedburner:origLink></item>
		<item>
		<title>Help making a great playlist every friday !</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/nOJq3dEkwKM/</link>
		<comments>http://www.palleas.com/fr/2009/06/02/help-making-a-great-playlist-every-friday/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 07:17:43 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[Divers]]></category>

		<guid isPermaLink="false">http://www.palleas.com/fr/?p=865</guid>
		<description><![CDATA[Un petit projet lancé avec Damien (dont il parle ici). Le site est repose sur un wordpress, et le principe est vraiment très simple :

Le lundi, un billet est déposé sur le site façon &#8220;c&#8217;est parti pour la playlist de cette semaine !&#8221;, vous invitant donc à déposer vos liens Spotify uniquement.
Le jeudi soir, un [...]]]></description>
			<content:encoded><![CDATA[<p>Un petit projet lancé avec <a href="http://www.dmathieu.com">Damien</a> (dont il parle <a href="http://www.dmathieu.com/2009/06/02/friday-playlist-la-liste-de-lecture-collaborative/">ici</a>). Le site est repose sur un wordpress, et le principe est vraiment très simple :</p>
<ul>
<li>Le lundi, un billet est déposé sur le site façon &#8220;c&#8217;est parti pour la playlist de cette semaine !&#8221;, vous invitant donc à déposer vos liens <strong>Spotify uniquement</strong>.</li>
<li>Le jeudi soir, un billet est posté, avec le lien vers la playlist ainsi créée, prête à être écoutée le vendredi.</li>
</ul>
<p><a href="http://www.friday-playlist.com">Ça se passe ici</a>, enjoy !</p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/nOJq3dEkwKM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/06/02/help-making-a-great-playlist-every-friday/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/06/02/help-making-a-great-playlist-every-friday/</feedburner:origLink></item>
		<item>
		<title>Mieux développer en PHP avec Symfony 1.2 et Doctrine</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/CZWHzRdYcrw/</link>
		<comments>http://www.palleas.com/fr/2009/05/26/mieux-developper-en-php-avec-symfony-12-et-doctrine/#comments</comments>
		<pubDate>Tue, 26 May 2009 09:25:59 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.palleas.com/?p=852</guid>
		<description><![CDATA[J&#8217;en avais déjà un peu parlé sur Twitter, mais comme je l&#8217;ai fait pour le livre programmation Flex 3, j&#8217;ai participé à la réalisation du premier ouvrage français de référence sur le framework Symfony (rien que ça). Le livre est sorti le 15 mai dernier, et c&#8217;est un peu la honte pour moi de n&#8217;en [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;en avais déjà un peu parlé sur <a href="http://www.twitter.com/palleas">Twitter</a>, mais comme je l&#8217;ai fait pour le livre programmation Flex 3, j&#8217;ai participé à la réalisation du <a href="http://www.editions-eyrolles.com/Livre/9782212124941/symfony">premier ouvrage français de référence sur le framework Symfony</a> (rien que ça). Le livre est sorti le 15 mai dernier, et c&#8217;est un peu la honte pour moi de n&#8217;en parler que maintenant!</p>
<p><img src="http://www.palleas.com/wp-content/uploads/2009/05/9782212124941.jpg" alt="9782212124941" title="9782212124941" width="374" height="430" class="aligncenter size-full wp-image-856" /></p>
<p>Le livre est la version française du tutoriel Jobeet, traduite et adaptée par <a href="http://www.apprendre-php.com">Hugo</a> dont j&#8217;ai pu suivre l&#8217;évolution du taux de fatigue au fur et à mesure que la traduction avançait. J&#8217;ai pour ma part assuré la relecture technique mais également le travail d&#8217;indexation du contenu (même que dans les remerciements, ils disent que j&#8217;ai fourni un travail remarquable, et ouais!).</p>
<p>C&#8217;est un peu drôle de me retrouver à faire ça, quand on sait que l&#8217;année dernière j&#8217;étais encore <a href="http://www.palleas.com/2008/02/07/framework-php-oui-mais/">anti-framework PHP</a>. Cette année d&#8217;alternance dans une boite avec 5 développeurs m&#8217;aura au moins enseigné les difficultés liées au développement en équipe, et ainsi révélé les avantages d&#8217;un framework.</p>
<p>Du coup <a href="http://www.editions-eyrolles.com/Livre/9782212124941/symfony">courrez acheter le livre</a>, il vaut vraiment le coup (on retiendra mon objectivité sur ce coup). Petit bémol pour la couverture et l&#8217;illustration absolument improbable que l&#8217;on retrouve systématiquement sur <a href="http://www.editions-eyrolles.com/Collection/1291/les-cahiers-du-programmeur?xd=10d5d7dc42b948c0b4095bcad85fed96">la collection des cahiers du programmeur</a>, au moins on a évité les palmes du livre sur le Zend Framework ou le bébé de l&#8217;enfer sur le livre Java EE&#8230;</p>
<p>Merci à Eyrolles (et plus particulièrement à <a href="http://blog.muriel-shanseifan.org/">Muriel (Shan Sei Fan)</a>), à <a href="http://fabien.potencier.org/">Fabien (Potencier)</a> et à <a href="http://www.apprendre-php.com">Hugo (Hamon)</a>. L&#8217;expérience était vraiment enrichissante!</p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/CZWHzRdYcrw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/05/26/mieux-developper-en-php-avec-symfony-12-et-doctrine/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/05/26/mieux-developper-en-php-avec-symfony-12-et-doctrine/</feedburner:origLink></item>
		<item>
		<title>Appréhender l’approche “Code-behind” en Flex</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/FLVN4U4M5uY/</link>
		<comments>http://www.palleas.com/fr/2009/05/25/apprehender-lapproche-code-behind-en-flex/#comments</comments>
		<pubDate>Mon, 25 May 2009 16:12:10 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.palleas.com/?p=836</guid>
		<description><![CDATA[J&#8217;ai toujours eu un peu de mal à trouver &#8220;beau&#8221; ce que je pouvais faire en Flex. Je n&#8217;ai pas un niveau d&#8217;expert, et j&#8217;ai une autocritique super rude. Ce qui me bloque véritablement en fait, c&#8217;est de ne pas considérer le MXML uniquement pour la conception de &#8220;vues&#8221; et donc se limiter aux composants [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai toujours eu un peu de mal à trouver &#8220;beau&#8221; ce que je pouvais faire en Flex. Je n&#8217;ai pas un niveau d&#8217;expert, et j&#8217;ai une autocritique super rude. Ce qui me bloque véritablement en fait, c&#8217;est de ne pas considérer le MXML uniquement pour la conception de &#8220;vues&#8221; et donc se limiter aux composants graphiques, mais également la gestion des évènements, la possibilité de faire du &#8220;presque objet&#8221;, etc.</p>
<p><span id="more-836"></span></p>
<p>Un exemple typique étant un peu tout ça :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Click Me !&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;handleClick(event)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p></code><br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Application</span> <span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;handleCreationComplete(event)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p></code></p>
<p>Pour moi la seule manière élégante de gérer les évènements reste le bon vieux addEventListener. Aussi, on pourra trouver des choses comme ça pour &#8220;limiter la casse&#8221; :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Application</span> 	<span style="color: #000066;">xmlns:s</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">xmlns:fx</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;init(event)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	protected var app:MyUberApplication;
	public function init(e:FlexEvent):void {
		app = new MyUberApplication(this);
	}
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></code></p>
<p>De cette manière, on peut gérer les évènements proprement dans notre classe &#8220;MyUberApplication&#8221;, et limiter l&#8217;ajout d&#8217;Actionscript dans le MXML. Seulement voilà, pour moi cette manière de faire n&#8217;est pas complètement satisfaisante. L&#8217;ajout de code Actionscript dans le MXML me rappelle le vieil HTML 4.0 entrecoupé de javascript (exagération volontaire).</p>
<p>Je ne vais pas donner dans la critique gratuite sans proposer une solution, ceux qui suivent ce blog depuis longtemps savent que c&#8217;est un peu le genre de chose qui m&#8217;énerve. Voici donc la solution : le <strong>&#8220;code-behind&#8221; !</strong>. J&#8217;ai découvert ça récemment, et depuis je ne développe plus que comme ça!</p>
<p>Désormais, développer un composant se compose de plusieurs classes :</p>
<ul>
<li>Une classe Actionscript héritant d&#8217;un composant graphique (ex: Panel)</li>
<li>Un composant MXML héritant de cette classe Actionscript</li>
<li>Une classe Actionscript servant de &#8220;Value-Object&#8221;</li>
<li>Une classe Actionscript héritant de la classe Event</li>
</ul>
<p>Pour illustrer ce principe de fonctionnement, voici un composant permettant l&#8217;ajout d&#8217;un contact à un carnet d&#8217;adresse.</p>
<p>Développement de la première classe Actionscript :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">components</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">containers</span>.<span style="color: #006600;">Panel</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #0066CC;">Button</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">TextInput</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AddContactBoxClass <span style="color: #0066CC;">extends</span> Panel <span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> _contactNameField:TextInput;
		protected <span style="color: #000000; font-weight: bold;">var</span> _contactEmailField:TextInput;
		protected <span style="color: #000000; font-weight: bold;">var</span> _addContactButton:<span style="color: #0066CC;">Button</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AddContactBoxClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span>FlexEvent.<span style="color: #006600;">CREATION_COMPLETE</span>,creationCompleteHandle<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> creationCompleteHandle<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			removeEventListener<span style="color: #66cc66;">&#40;</span>FlexEvent.<span style="color: #006600;">CREATION_COMPLETE</span>,creationCompleteHandle<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> nameField<span style="color: #66cc66;">&#40;</span>field:TextInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_contactNameField = field;	
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> nameField<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:TextInput <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _contactNameField;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> emailField<span style="color: #66cc66;">&#40;</span>field:TextInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_contactEmailField = field;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> emailField<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:TextInput <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _contactEmailField;	
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> addButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Button</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _addContactButton;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> addButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">button</span>:<span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_addContactButton = <span style="color: #0066CC;">button</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Et voici le composant MXML qui en hérite :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><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>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;components:AddContactBoxClass</span> 	xmlns:components=<span style="color: #ff0000;">&quot;com.palleas.contact.components.*&quot;</span> </span>
<span style="color: #000000;">						xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span style="color: #000000;">						layout=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #000000;">						title=<span style="color: #ff0000;">&quot;Ajouter un contact&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Nom&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> id=<span style="color: #ff0000;">&quot;nameField&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Email&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> id=<span style="color: #ff0000;">&quot;emailField&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;addButton&quot;</span> label=<span style="color: #ff0000;">&quot;Ajouter&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/components:AddContactBoxClass</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p></code></p>
<p>Voici le &#8220;value-object&#8221; qui sera utiliser pour faire transiter les données :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">vo</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Contact <span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_name</span>:<span style="color: #0066CC;">String</span>;
		protected <span style="color: #000000; font-weight: bold;">var</span> _email:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#40;</span>n:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">_name</span> = n;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">_name</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> email<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_email = <span style="color: #0066CC;">e</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> email<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _email;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Et enfin, voici l&#8217;évènement qui sera diffusé lorsque la personne voudra ajouter un contact :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">events</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">vo</span>.<span style="color: #006600;">Contact</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ContactEvent <span style="color: #0066CC;">extends</span> Event <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> const CONTACT_ADDED:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;ContactAdded&quot;</span>;
		protected <span style="color: #000000; font-weight: bold;">var</span> _contact:Contact;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ContactEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, contactVO:Contact=<span style="color: #000000; font-weight: bold;">null</span>,bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">!</span>=contactVO<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">contact</span> = contactVO;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> contact<span style="color: #66cc66;">&#40;</span>c:Contact<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_contact = c;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> contact<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Contact <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _contact;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Maintenant qu&#8217;on a tous les acteurs, on va pouvoir implémenter plus facilement l&#8217;aspect fonctionnel de notre composant, c&#8217;est à dire que l&#8217;on va &#8220;faire quelque chose&#8221; lorsque la personne voudra ajouter son contact. Pour ce faire, commençons par modifier la méthode creationCompleteHandle de la classe AddContactBoxClass, pour réagir au clique sur le bouton :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">components</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ContactEvent</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">vo</span>.<span style="color: #006600;">Contact</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">containers</span>.<span style="color: #006600;">Panel</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #0066CC;">Button</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">TextInput</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AddContactBoxClass <span style="color: #0066CC;">extends</span> Panel <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// ...</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> creationCompleteHandle<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			removeEventListener<span style="color: #66cc66;">&#40;</span>FlexEvent.<span style="color: #006600;">CREATION_COMPLETE</span>,creationCompleteHandle<span style="color: #66cc66;">&#41;</span>;
			addButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>,buttonClickHandle<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> buttonClickHandle<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> createdContact:Contact = <span style="color: #000000; font-weight: bold;">new</span> Contact<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			createdContact.<span style="color: #0066CC;">name</span> = nameField.<span style="color: #0066CC;">text</span>;
			createdContact.<span style="color: #006600;">email</span> = emailField.<span style="color: #0066CC;">text</span>;
			<span style="color: #000000; font-weight: bold;">var</span> addContactEvent:ContactEvent = <span style="color: #000000; font-weight: bold;">new</span> ContactEvent<span style="color: #66cc66;">&#40;</span>ContactEvent.<span style="color: #006600;">CONTACT_ADDED</span>,createdContact<span style="color: #66cc66;">&#41;</span>;
			dispatchEvent<span style="color: #66cc66;">&#40;</span>addContactEvent<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #808080; font-style: italic;">// ..</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>On a ajouté un écouteur sur le bouton. Lors du clique, on recréé un &#8220;value-object&#8221; Contact contenant les valeurs spécifiées par l&#8217;utilisateur (le nom, et l&#8217;adresse E-mail). On créé ensuite un évènement qui diffusera ce &#8220;value-object&#8221;.</p>
<p>Enfin, pour utiliser proprement ce composant dans mon application Flex, je vais implémenter de nouveau ce principe du &#8220;code-behind&#8221; pour mon application. Je créé donc ma classe MainApplicationClass, qui hérite du composant Flex &#8220;Application&#8221; :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">components</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ContactEvent</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">palleas</span>.<span style="color: #006600;">contact</span>.<span style="color: #006600;">vo</span>.<span style="color: #006600;">Contact</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">Application</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MainApplicationClass <span style="color: #0066CC;">extends</span> Application <span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> _addContactBox:AddContactBox;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MainApplicationClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span>FlexEvent.<span style="color: #006600;">CREATION_COMPLETE</span>,creationCompleteHandle<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> creationCompleteHandle<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			removeEventListener<span style="color: #66cc66;">&#40;</span>FlexEvent.<span style="color: #006600;">CREATION_COMPLETE</span>,creationCompleteHandle<span style="color: #66cc66;">&#41;</span>;
			addContactBox.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ContactEvent.<span style="color: #006600;">CONTACT_ADDED</span>,onContactAdded<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> onContactAdded<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:ContactEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> contactAdded:Contact = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">contact</span>;
			Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Un contact a été ajouté :<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>+contactAdded.<span style="color: #0066CC;">name</span>+<span style="color: #ff0000;">&quot; // &quot;</span>+contactAdded.<span style="color: #006600;">email</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> addContactBox<span style="color: #66cc66;">&#40;</span>box:AddContactBox<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_addContactBox = box;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> addContactBox<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:AddContactBox <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _addContactBox;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p></code></p>
<p>Ce qui donne pour mon fichier MXML principal :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;components:MainApplicationClass</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #000066;">xmlns:components</span>=<span style="color: #ff0000;">&quot;com.palleas.contact.components.*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;components:AddContactBox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;addContactBox&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/components:MainApplicationClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></code></p>
<p>Ainsi, lorsque je clique sur mon bouton, un évènement est diffusé. Cet évènement est récupéré par mon application principale, qui ainsi affiche une alerte affichant les informations du contact ajouté :</p>
<p><img src="http://www.palleas.com/wp-content/uploads/2009/05/codebehind.jpg" alt="codebehind" title="codebehind" width="499" height="371" class="aligncenter size-full wp-image-847" /></p>
<p><strong>En conclusion</strong>, c&#8217;est sans doute pour moi la manière la plus propre de procéder pour développer avec Flex. De cette manière, tout est bien décomposé, et c&#8217;est ainsi que l&#8217;on pourra facilement implémenter un <strong>vrai</strong> MVC beau et propre. Comme je le disais je ne code plus que comme ça, mais pas depuis vraiment longtemps, si vous avez des remarques ou des questions, les commentaires sont la pour ça!</p>
<p><em>(Petit bémol cependant, je n&#8217;ai volontairement pas parlé de vérification ou de stockage des valeurs saisies, ce n&#8217;était pas le but du tutoriel, et il était suffisamment long comme cela.)</em></p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/FLVN4U4M5uY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/05/25/apprehender-lapproche-code-behind-en-flex/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/05/25/apprehender-lapproche-code-behind-en-flex/</feedburner:origLink></item>
		<item>
		<title>Flex 4 : Support MXML de la classe Vector</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/iEvG0Hd55wo/</link>
		<comments>http://www.palleas.com/fr/2009/05/18/flex-4-support-mxml-de-la-classe-vector/#comments</comments>
		<pubDate>Mon, 18 May 2009 16:47:22 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.palleas.com/?p=827</guid>
		<description><![CDATA[J&#8217;ai déjà fait un précédent billet sur l&#8217;apparition de la classe de collection Vector dans flash 10. Il se trouve que cette classe sera également directement utilisable en MXML. Il est important de prendre en compte que ce composant reste un composant non-graphique, aussi par défaut il devra être déclaré dans le tag &#8220;Declarations&#8221;, conformément [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai déjà fait un précédent billet sur l&#8217;apparition de la classe de collection Vector dans flash 10. Il se trouve que cette classe sera également directement utilisable en MXML. Il est important de prendre en compte que ce composant reste un composant non-graphique, aussi par défaut il devra être déclaré dans le tag &#8220;Declarations&#8221;, conformément aux spécificités du MXML 2009.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><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>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> 	xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">				xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #000000;">				xmlns:com=<span style="color: #ff0000;">&quot;com.palleas.*&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Declaration du Vector --&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Vector</span> id=<span style="color: #ff0000;">&quot;myVectorList&quot;</span> type=<span style="color: #ff0000;">&quot;com.palleas.Touriste&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;com:Touriste</span> lastname=<span style="color: #ff0000;">&quot;Brian&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;com:Touriste</span> lastname=<span style="color: #ff0000;">&quot;Stewart&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;com:Touriste</span> lastname=<span style="color: #ff0000;">&quot;Martin&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Vector</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Affichage de la taille de ce vector : le nombre d'éléments contenus --&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> text=<span style="color: #ff0000;">&quot;{myVectorList.length}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p></code></p>
<p>Rien de très compliqué ici, j&#8217;ai limité le Vector à ne contenir que des éléments de type &#8220;Touriste&#8221; (cette classe venant du tutoriel précédent). Le fonctionnement basique ne change pas, si vous essayez de mettre un élément de type autre celui spécifié dans l&#8217;attribut type (genre un String), vous aurez une erreur à la compilation. Personnelement, je n&#8217;utilise que très peu (sinon pas) ne composant non-graphiques dans mon MXML, mais bon c&#8217;est à vous de voir!</p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/iEvG0Hd55wo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/05/18/flex-4-support-mxml-de-la-classe-vector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/05/18/flex-4-support-mxml-de-la-classe-vector/</feedburner:origLink></item>
		<item>
		<title>Flex 4 : Say hi to Two-way Data Binding !</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/a3rCNC2YOSs/</link>
		<comments>http://www.palleas.com/fr/2009/05/07/flex-4-say-hi-to-two-way-data-binding/#comments</comments>
		<pubDate>Thu, 07 May 2009 06:00:17 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.palleas.com/?p=699</guid>
		<description><![CDATA[Une des fonctionnalités vraiment pratique de Flex est le &#8220;data-binding&#8221; ou, littéralement, la &#8220;liaison de données&#8221;. C&#8217;est à dire que l&#8217;on peut déclarer une variable, créer par exemple un composant de texte et faire en sorte que le texte contenu soit systématiquement la valeur de la variable que l&#8217;on vient de créer. Flex 4 apporte [...]]]></description>
			<content:encoded><![CDATA[<p>Une des fonctionnalités vraiment pratique de Flex est le &#8220;data-binding&#8221; ou, littéralement, la &#8220;liaison de données&#8221;. C&#8217;est à dire que l&#8217;on peut déclarer une variable, créer par exemple un composant de texte et faire en sorte que le texte contenu soit systématiquement la valeur de la variable que l&#8217;on vient de créer. Flex 4 apporte une petite nouveauté à ce sujet.</p>
<p><span id="more-699"></span></p>
<p>Avec Flex 3, l&#8217;implémentation du DataBinding donnait quelque chose comme ça (l&#8217;étiquette Bindable permettant de dire explicitement au compilateur &#8220;d&#8217;écouter&#8221; les modifications effectuées sur cette variable) :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">		[Bindable]</span>
<span style="color: #339933;">		protected var myVar:String;</span>
<span style="color: #339933;">		]]&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{myVar}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></code></p>
<p>Ce qu&#8217;il manquait finalement, c&#8217;était que cette modification puisse se faire dans les deux sens, c&#8217;est à dire que lors de la modification de la variable, le contenu du champs de texte se mette à jour, mais que lors de la modification du contenu du champs de texte, la variable se mette à jour également. Notez bien l&#8217;utilisation du passé car avec Flex 4, c&#8217;est possible !</p>
<h3>Two-Way Binding : MXML style</h3>
<p>La première manière de déclarer ce data-binding étant d&#8217;utiliser le tag &#8220;Binding&#8221; de MXML :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fx:Binding</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;textField1.text&quot;</span> <span style="color: #000066;">destination</span>=<span style="color: #ff0000;">&quot;textField2.text&quot;</span> <span style="color: #000066;">twoWay</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;textField1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;textField2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></pre></div></div>

<p></code></p>
<p>De cette manière, le contenu de mes deux champs de texte est systématiquement la même car leurs propriétés &#8220;text&#8221; sont liées. Notez l&#8217;utilisation de l&#8217;attribut twoWay=&#8221;true&#8221;, c&#8217;est la seule véritable différence avec Flex 3. Si cet attribut est omis, la liaison ne se fera que dans un sens (la valeur de la propriété déclarée dans &#8220;destination&#8221; prenant la valeur de celle déclarée dans &#8220;source&#8221;).</p>
<h3>Two-way Binding : inline style</h3>
<p>Il existe une autre manière de faire, directement dans le contenu des balises MXML, via une syntaxe très légèrement différente de ce qu&#8217;on faisait avec Flex 3, &#8220;@{propriété bindable}&#8221;. Pour reprendre l&#8217;exemple précédent, cela donnerait quelque chose comme ça :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;textField1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;textField2&quot;</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;@{textField1.text}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></pre></div></div>

<p></code></p>
<p>Ce fonctionnement reste le même dans le cas de propriété bindable déclarée en Actionscript :</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--  ... --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- Propriété bindable --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">		[Bindable]</span>
<span style="color: #339933;">		protected var myVar:String;</span>
<span style="color: #339933;">	]]&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- Champ de texte mettant à jour cette propriété --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;textField2&quot;</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;@{myVar}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- One-way DataBinding, pour montrer que la valeur de la</span>
<span style="color: #808080; font-style: italic;">propriété &quot;myVar&quot; évolue bien --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:TextInput</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{myVar}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--  ... --&gt;</span></pre></div></div>

<p></code></p>
<p>Voila pour la présentation de cette nouvelle fonctionnalité, qui devrait simplifier vos développement. Personnellement c&#8217;est quelque chose qui m&#8217;avait vraiment manqué, c&#8217;est donc plutôt une bonne nouvelle de le voir implémenté dans cette nouvelle version de Flex, sans que ça bouleverse trop les habitudes de développement (un &#8220;@&#8221; à rajouter dans le html, ou un attribut &#8220;twoWays&#8221; à préciser, on devrait pouvoir s&#8217;en sortir). A bientôt pour de nouvelles aventures et désolé, je crois que j&#8217;ai un peu tripé sur les titres en anglais.</p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/a3rCNC2YOSs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/05/07/flex-4-say-hi-to-two-way-data-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/05/07/flex-4-say-hi-to-two-way-data-binding/</feedburner:origLink></item>
		<item>
		<title>Flex 4 : amélioration de la gestion des states</title>
		<link>http://feedproxy.google.com/~r/palleas/~3/_yQtv4-YaT8/</link>
		<comments>http://www.palleas.com/fr/2009/05/02/flex-4-amelioration-de-la-gestion-des-states/#comments</comments>
		<pubDate>Sat, 02 May 2009 19:22:16 +0000</pubDate>
		<dc:creator>Palleas</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.palleas.com/?p=688</guid>
		<description><![CDATA[Pour rappel, les états (states) sont une liste de changement effectués sur un composant. Dans ces changements, on trouvera l&#8217;ajout ou la suppression d&#8217;un composant enfant, la modification d&#8217;une propriété, l&#8217;ajout ou la modification d&#8217;un écouteur, etc. Cette gestion a été grandement améliorée, pour la rendre encore plus intuitive.

currentState = null, currentState = &#8220;&#8221;
Désormais, dans [...]]]></description>
			<content:encoded><![CDATA[<p>Pour rappel, les états (states) sont une liste de changement effectués sur un composant. Dans ces changements, on trouvera l&#8217;ajout ou la suppression d&#8217;un composant enfant, la modification d&#8217;une propriété, l&#8217;ajout ou la modification d&#8217;un écouteur, etc. Cette gestion a été grandement améliorée, pour la rendre encore plus intuitive.</p>
<p><span id="more-688"></span></p>
<h3>currentState = null, currentState = &#8220;&#8221;</h3>
<p>Désormais, dans le cas ou un composant aurait des spécification de changement d&#8217;états, l&#8217;état par défaut du composant serait le premier de la liste. Il vous faut donc déclarer l&#8217;état &#8220;par défaut&#8221;.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Application</span> 	<span style="color: #000066;">xmlns:s</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">xmlns:fx</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- States --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;default&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;state1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;state2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Hi, I'm a button !&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></code></p>
<p>De cette manière, pour revenir à l&#8217;état par défaut, il faudra revenir à l&#8217;état ici nommé &#8220;default&#8221; <em>(j&#8217;aurais pu le nommer comme je le veux, mais &#8220;default&#8221; semblait être le choix le plus pertinent.)</em>.</p>
<h3>addChild, removeChild</h3>
<p>L&#8217;ajout et la suppression de composant a également été repensée, pour la rendre bien plus pratique à utiliser. Fini les target=&#8221;{myComponent}&#8221; position=&#8221;after&#8221;, il faudra désormais passer par les attributs <strong>excludeFrom </strong>et <strong>IncludeIn</strong>. Ces attributs prenant comme valeur la liste des états auxquels insérer ou supprimer ledit composant. Si ces attribut sont omis, le composant sera affiché dans l&#8217;état par défaut.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Application</span> 	<span style="color: #000066;">xmlns:s</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">xmlns:fx</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:VerticalLayout</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- States --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;default&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;state1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;state2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- Button : visible everywhere --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Button #1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- Button : only visible in state1 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Button #2&quot;</span> <span style="color: #000066;">includeIn</span>=<span style="color: #ff0000;">&quot;state1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- Button : visible everywhere but in state2 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Button #3&quot;</span> <span style="color: #000066;">excludeFrom</span>=<span style="color: #ff0000;">&quot;state2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- switch states --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;default State&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;currentState='default'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;State 1&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;currentState='state1'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;State 2&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;currentState='state2'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></code></p>
<h3>setProperty, setStyle, setEventHandler</h3>
<p>La modification de propriété, de style, d&#8217;écouteur ne peut plus se faire via les méthodes respectives setProperty, setStyle et setEventHandler. A la place, une nouvelle syntaxe a été mise en place, on utilisera donc toujours attribut=&#8221;value&#8221; pour spécifier la valeur d&#8217;un attribut, et on utilisera attribut.<strong>XXX</strong>=&#8221;other value&#8221; pour spécifier la valeur de l&#8217;attribut lorsque l&#8217;on se trouve sur le state <strong>XXX</strong>.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Application</span> 	<span style="color: #000066;">xmlns:s</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">xmlns:fx</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:VerticalLayout</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- States --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;default&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;state1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;state2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> 	<span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Default label&quot;</span> <span style="color: #000066;">label.state1</span>=<span style="color: #ff0000;">&quot;Label State 1&quot;</span> <span style="color: #000066;">label.state2</span>=<span style="color: #ff0000;">&quot;Label State 3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- switch states --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;default State&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;currentState='default'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;State 1&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;currentState='state1'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;State 2&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;currentState='state2'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></code></p>
<p>Cela implique qu&#8217;il est désormais impératif de déclarer des noms de state &#8220;xml-attribute-compliant&#8221;, c&#8217;est à dire éviter les &#8220;.&#8221;, les &#8220;:&#8221;, etc.</p>
<p>Je conclurai en disant que pour ma part, ce changement est des plus pertinent. Il devient ainsi possible retrouver très facilement tous les états d&#8217;un composant au même endroit.</p>
<img src="http://feeds.feedburner.com/~r/palleas/~4/_yQtv4-YaT8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.palleas.com/fr/2009/05/02/flex-4-amelioration-de-la-gestion-des-states/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.palleas.com/fr/2009/05/02/flex-4-amelioration-de-la-gestion-des-states/</feedburner:origLink></item>
	</channel>
</rss>
