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

<channel>
	<title>Flashxpress &#187; Flash dynamique</title>
	<atom:link href="http://www.flashxpress.net/category/ressources-flash/flash-dynamique/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flashxpress.net</link>
	<description>Ressources pour la création et les technologies du web</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:00:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Flash Player 11 – Charger un MP3 local avec FileReference et loadMp3FromByteArray</title>
		<link>http://www.flashxpress.net/ressources-flash/flash-player-11-%e2%80%93-charger-un-mp3-local-avec-filereference/</link>
		<comments>http://www.flashxpress.net/ressources-flash/flash-player-11-%e2%80%93-charger-un-mp3-local-avec-filereference/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 09:25:55 +0000</pubDate>
		<dc:creator>alama</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Flash dynamique]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[incubator]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[loadFromByteArray]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[Player 11]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=6184</guid>
		<description><![CDATA[La classe <code>FileReference </code>permet de charger un MP3 depuis le disque dur local (client) via la méthode <code>load()</code>. Cependant, le fichier reçu se trouve dans un byteArray, nous recevons un RAW. Évidemment, la classe <code>Sound</code> ne permet pas de charger ce type de données, il faut alors passer par du code écrit sois même qui devra parser le MP3, gerer la partie ID3 et créer une classe <code>Sound</code> qui contient le son MP3. Ce genre de mini Framework existe, notamment AudioFx.]]></description>
			<content:encoded><![CDATA[<h3>Charger un fichier MP3 local</h3>
<p>La classe <code>FileReference </code>permet de charger un MP3 depuis le disque dur local (client) via la méthode <code>load()</code>. Cependant, le fichier reçu se trouve dans un byteArray, nous recevons un RAW. Évidemment, la classe <code>Sound</code> ne permet pas de charger ce type de données, il faut alors passer par du code écrit sois même qui devra parser le MP3, gerer la partie ID3 et créer une classe <code>Sound</code> qui contient le son MP3. Ce genre de mini Framework existe, notamment AudioFx.</p>
<h3>La méthode loadMp3FromByteArray de la classe Sound</h3>
<p>J&#8217;avais posté sur la branche jira de bugs.adobe à ce propos, je me suis d&#8217;ailleurs trompé, j&#8217;ai publié un bug post au lieu d&#8217;un request feature, mais bon, ça n&#8217;a apparemment pas porté à préjudice.. lol<br />
<a href="https://bugs.adobe.com/jira/browse/FP-5920" target="_blank">https://bugs.adobe.com/jira/browse/FP-5920 </a></p>
<p>Toujours est-il qu&#8217;une nouvelle feature à été ajoutée à la classe <code>Sound</code> afin de résoudre ce souci, elle est en <strong>préview </strong>sur le <strong>player 11 bêta</strong> et il n&#8217;y aurait <strong>aucune certitude</strong> que cette feature restera pour la sortie RC.  Alors, j&#8217;invite tous les lecteurs de mon tuto à appuyer cette demande en votant ou en laissant un message sur mon post chez Adobe. Il y a un lien <strong>Voting</strong> dans la colonne gauche. <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Afin de tester cette feature, vous devez installer les versions beta du <strong>plugin</strong> et <strong>activeX du player 11</strong>, vous pouvez les télécharger ici: <a href="http://labs.adobe.com/downloads/flashplatformruntimes_incubator.html" target="_blank">http://labs.adobe.com/downloads/flashplatformruntimes_incubator.html </a></p>
<p>Une fois installé, pour <strong>Chrome</strong>, vous devez le sélectionner de la manière suivante:<br />
Dans la barre d&#8217;adresse de chrome, tapez: <strong>about:plugins</strong> ensuite, cliquer sur <strong>details</strong>.</p>
<p>Dans la liste des plugins, il doit y avoir celui installé par chrome lui même et le 11 bêta installé dans votre système. Il suffit de désactiver celui installé par chrome et il prendra par défaut celui du système.</p>
<p>Si c&#8217;est réussi, vous devez voir lors de la lecture d&#8217;un SWF la mention <strong>Flash Player 11 (incubator build)</strong> en bas de l&#8217;animation.</p>
<p>Clic on black rectangle for load mp3.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_testLoadMp3FromByteArray_869489170"
			class="flashmovie"
			width="400"
			height="150">
	<param name="movie" value="http://www.covergraph.com/blog/flash/load_local_mp3/testLoadMp3FromByteArray.swf" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.covergraph.com/blog/flash/load_local_mp3/testLoadMp3FromByteArray.swf"
			name="fm_testLoadMp3FromByteArray_869489170"
			width="400"
			height="150">
		<param name="wmode" value="direct" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<h3>Tester l&#8217;API du beta player 11 sous FlashDevelop</h3>
<p>Afin de tester une <strong>API bêta</strong>, il faut préparer <strong>FlashDevelop</strong> en suivant les étapes suivantes:</p>
<ul>
<li>Télécharger le dernier <strong>SDK</strong> préconisé par Adobe Labs:<br />
<a href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+Hero" target="_blank">http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+Hero</a></li>
<li>Téléchager le <strong>playerglobal.swc</strong> du player beta:<br />
<a href="http://download.macromedia.com/pub/labs/flashplatformruntimes/incubator/flashplayer_inc_playerglobal_022711.swc" target="_blank">http://download.macromedia.com/pub/labs/flashplatformruntimes/incubator/flashplayer_inc_playerglobal_022711.swc</a></li>
<li>Créer un nouveau projet AS3 sous FD, ensuite, aller dans <strong>AS3Context</strong> et cibler le <strong>SDK</strong> téléchargé.</li>
<li>Aller dans le répertoire <strong>framework/libs/players/10.1</strong> du sdk et remplacer le playerGlobal présent par celui qu&#8217;on vient de télécharger. (en le renommant <strong>playerglobal.swc</strong>). C&#8217;est ce fichier qui contient toutes les références de classes de l&#8217;API que FlashDevelop utilise pour l&#8217;autoCompletion et que le mxmlc utilise pour compiler en mode strict.</li>
<li>Aller dans les propriétés du projet, cibler le <strong>player 10.1</strong>, ensuite, aller dans l&#8217;onglet <strong>compiler options</strong>, et dans <strong>Additional Compiler Options</strong>, ajouter <strong>-swf-version=13</strong>.</li>
</ul>
<p>Voilà, nous sommes prêt à programmer.</p>
<p><strong>FD4</strong> proposera <strong>peut être</strong> une auto reconnaissance des versions player par analyse du SDK ciblé, cela demandera moins de manipulation quand on devra tester des versions bêta et on ne devra plus attendre de mise à jour de FD pour cibler les nouveaux players. Là aussi, j&#8217;ai déposé une demande de feature, libre à vous de la soutenir également.. <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<a href="http://www.flashdevelop.org/community/viewtopic.php?f=5&amp;t=8050" target="_blank"> http://www.flashdevelop.org/community/viewtopic.php?f=5&amp;t=8050</a></p>
<h3>Au banc d&#8217;essai &#8211; code AS3</h3>
<p>Voici le code minimum de base afin d&#8217;exploiter cette nouvelle fonctionnalité.<br />
Il est a noté que la méthode <code>close()</code> et l&#8217;événement <code>complete</code> de la classe <code>Sound</code> ne fonctionne pas dans cette implémentation, ils ne s&#8217;appliquent apparemment qu&#8217;en cas de loading distant. Il ne faudra donc pas chercher a les utiliser pour un chargement local via <code>FileReference</code>.</p>
<p>Pour les <strong>ID3</strong>, AS3 propose les propriétés de base (songName, etc..) Mais je conseille d&#8217;utiliser directement les vrais identifiants définis par l&#8217;<strong>ID3 Org</strong> (les classiques sont les frames 4.2 serie): <a href="http://www.id3.org/d3v2.3.0" target="_blank"> http://www.id3.org/d3v2.3.0</a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6184code1'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p61841"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
</pre></td><td class="code" id="p6184code1"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.media</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.media</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=soundchannel%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:soundchannel.html"><span style="color: #004993;">SoundChannel</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=filefilter%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:filefilter.html"><span style="color: #004993;">FileFilter</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=filereference%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:filereference.html"><span style="color: #004993;">FileReference</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=textfieldautosize%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfieldautosize.html"><span style="color: #004993;">TextFieldAutoSize</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #3f5fbf;">/**
	 * ...
	 * @author Alama
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> fileRef<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=filereference%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:filereference.html"><span style="color: #004993;">FileReference</span></a><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> sound<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> channel<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=soundchannel%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:soundchannel.html"><span style="color: #004993;">SoundChannel</span></a><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> txt<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// entry point</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// button test</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> btn<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><span style="color: #000066; font-weight: bold;">;</span>
			btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x000000<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">150</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>btn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
			btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> btnClickHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// output text</span>
			txt = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a><span style="color: #000066; font-weight: bold;">;</span>
			txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span> = <a href="http://www.google.com/search?q=textfieldautosize%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfieldautosize.html"><span style="color: #004993;">TextFieldAutoSize</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>txt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnClickHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			fileRef = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=filereference%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:filereference.html"><span style="color: #004993;">FileReference</span></a><span style="color: #000066; font-weight: bold;">;</span>
			fileRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SELECT</span><span style="color: #000066; font-weight: bold;">,</span> fileRefSelectHandler<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			fileRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">browse</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=filefilter%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:filefilter.html"><span style="color: #004993;">FileFilter</span></a><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Music: *.mp3&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;*.mp3&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;*.MP3&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> fileRefSelectHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			fileRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> fileRefCompleteHandler<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			fileRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> fileRefCompleteHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			fileRef = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>channel <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				channel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				channel = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
				sound = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			sound = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			sound<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ID3</span><span style="color: #000066; font-weight: bold;">,</span> soundID3Handler<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			sound<span style="color: #000066; font-weight: bold;">.</span>loadMP3FromByteArray<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">,</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			channel = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=soundchannel%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:soundchannel.html"><span style="color: #004993;">SoundChannel</span></a><span style="color: #000066; font-weight: bold;">;</span>
			channel = sound<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> soundID3Handler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// sometimes, on fisrt load, this handler is invoked twice!!??</span>
			<span style="color: #009900; font-style: italic;">// it's a light bug, but not serious..</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">id3</span><span style="color: #000066; font-weight: bold;">.</span>TIT2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = sound<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">id3</span><span style="color: #000066; font-weight: bold;">.</span>TIT2<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Voilà, espérons que cette feature restera définitivement au sein de l&#8217;APPI AS3.. car elle est bien plus simple et rapide que des classes de parsing.</p>
<h3>Soutenez une autre request feature pour la gestion du son</h3>
<p>A propos du son dans Flash, depuis le player 10, nous pouvons fabriquer nos propres sons de façon binaire et l&#8217;envoyer à la lecture grâce à l&#8217;événement <code>SampleData</code>. C&#8217;est super, mais celui ci souffre d&#8217;un problème majeur! La taille minimum du buffer (le byteArray des samples) est de <strong>2048 samples</strong> !! cela introduit inévitablement une latence audible qui peut aller jusqu&#8217;à <strong>+/- 300 ms</strong> avec les pertes du modèle événementiel etc.. J&#8217;ai donc également introduit une demande de révision du principe en proposant d&#8217;autres solutions.. Cette tâche incombe à la partie <strong>Core Player</strong>, donc, impossible à régler via <strong>l&#8217;AVMplus</strong>, donc, à priori, seul <strong>Adobe</strong> peut changer cela.</p>
<p><strong>Je vous invite également à soutenir cette demande en votant et éventuellement en participant à la discussion ici:</strong><br />
<a href="https://bugs.adobe.com/jira/browse/FP-5655" target="_blank"> https://bugs.adobe.com/jira/browse/FP-5655</a></p>
<p>Enjoy <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/flash-player-11-%e2%80%93-charger-un-mp3-local-avec-filereference/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Création d’un lecteur de FLUX RSS en AIR avec Flash</title>
		<link>http://www.flashxpress.net/ressources-flash/creation-d%e2%80%99un-lecteur-de-flux-rss-en-air-avec-flash/</link>
		<comments>http://www.flashxpress.net/ressources-flash/creation-d%e2%80%99un-lecteur-de-flux-rss-en-air-avec-flash/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 14:15:14 +0000</pubDate>
		<dc:creator>Olivier</dc:creator>
				<category><![CDATA[Flash dynamique]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=5555</guid>
		<description><![CDATA[Salut à tous. Pour mon premier petit tuto sur Flashxpress, je vous propose de réaliser un lecteur de Flux RSS, en AIR, sous Flash. La but de ce tuto est donc de vous apprendre à récupérer un flux RSS en AS3 et instancier à la volée un MovieClip par article qui contiendra le titre de [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/presentationTutoReaderRSS.png"><img class="alignnone size-full wp-image-5592" title="presentationTutoReaderRSS" src="http://www.flashxpress.net/wp-content/uploads/2011/01/presentationTutoReaderRSS.png" alt="" width="630" height="187" /></a></p>
<p>Salut à tous. Pour mon premier petit tuto sur Flashxpress, je vous propose de réaliser un lecteur de Flux RSS, en AIR, sous Flash.</p>
<p>La but de ce tuto est donc de vous apprendre à récupérer un flux RSS en AS3 et  instancier à la volée un MovieClip par article qui contiendra le titre de l’article ainsi qu’un bouton, qui, lorsqu’il sera cliqué, ouvrira le navigateur et affichera la page de l’article choisi.</p>
<h1>Création du projet</h1>
<p>Ouvrez Flash et sur l’écran d’accueil choisissez un fichier de type « Adobe AIR 2 ».</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/01.jpg"><img class="alignnone size-full wp-image-5556" title="01" src="http://www.flashxpress.net/wp-content/uploads/2011/01/01.jpg" alt="" width="630" /></a></p>
<p>Enregistrer le fichier. Personnellement, je l’appelle « LecteurRSS ».</p>
<p>A partir de là, si on compile, on a bien une application AIR.</p>
<h1>Préparation des éléments graphiques</h1>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/02.jpg"><img class="alignnone size-full wp-image-5557" title="02" src="http://www.flashxpress.net/wp-content/uploads/2011/01/02.jpg" alt="" width="566" height="438" /></a></p>
<p>Niveau design nous allons rester simples car ce n’est pas le but du tuto.</p>
<p>Pour commencer, je ne souhaite pas que mon application s’ouvre dans une fenêtre de type Windows. Je souhaite ici designer moi-même le type de fenêtre et ses contrôles de gestion (le bouton réduire et le bouton fermer l’application).</p>
<p>Afin de ne plus avoir cette fenêtre, rendons nous dans le panneau Propriétés, dans Flash, et cliquons sur le bouton « Modifier » correspondant aux paramètres d’Adobe AIR 2.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/03.jpg"><img class="alignnone size-full wp-image-5558" title="03" src="http://www.flashxpress.net/wp-content/uploads/2011/01/03.jpg" alt="" width="304" height="465" /></a></p>
<p>Dans la fenêtre qui vient de s’ouvrir, sélectionnons dans le menu déroulant « Style de fenêtre », « Chrome personnalisé (transparent) ».</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/04.jpg"><img class="alignnone size-full wp-image-5559" title="04" src="http://www.flashxpress.net/wp-content/uploads/2011/01/04.jpg" alt="" width="500" height="702" /></a></p>
<p>Si l’on recompile l’application, nous ne voyons plus rien apparaitre… mais l’application est belle et bien lancée, en témoigne le petit icône d’Adobe AIR dans la barre des tâches.</p>
<p>Si rien n’est visible c’est simplement par ce que notre application est vide.</p>
<p>Attelons-nous à présent au design d’une des lignes du lecteur.</p>
<p>Commençons par tracer un rectangle de 300 pixels de largeur par 50 de hauteur.</p>
<p>Remplissons-le d’un dégradé allant d’un gris foncé (#666666) vers le noir (#000000).</p>
<p>Grace à l’outil de transformation de dégradé, orientons ce remplissage verticalement.</p>
<p>Voici le résultat :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/05.jpg"><img class="alignnone size-full wp-image-5560" title="05" src="http://www.flashxpress.net/wp-content/uploads/2011/01/05.jpg" alt="" width="301" height="50" /></a></p>
<p>Pour le bouton « Lire », qui lorsqu’il sera cliqué ouvrira le navigateur sur la page de l’article, dessinons simplement un rectangle de 50 pixels par 50 pixels et alignons-le à droite du premier rectangle dessiné. Inversons la direction du dégradé. Voici le résultat :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/06.jpg"><img class="alignnone size-full wp-image-5561" title="06" src="http://www.flashxpress.net/wp-content/uploads/2011/01/06.jpg" alt="" width="348" height="50" /></a></p>
<p>Nous devons à présent ajouter deux champs texte. L’un contiendra le titre de l’article et le second simplement le texte « Lire».</p>
<p>Grace à l’outil Texte, dessinons donc les deux champs.</p>
<p>Le champ pour le titre doit être de type « Classique » / « Dynamique ». Pendant que nous y sommes, donnons-lui comme nom d’occurrence « titreArticle ».</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/07.jpg"><img class="alignnone size-full wp-image-5562" title="07" src="http://www.flashxpress.net/wp-content/uploads/2011/01/07.jpg" alt="" width="304" height="99" /></a></p>
<p>Le champ texte contenant le mot « Lire » quant à lui n’a pas besoin d’être dynamique. Je choisis donc comme type de champ « Classique » et « Statique ».</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/08.jpg"><img class="alignnone size-full wp-image-5563" title="08" src="http://www.flashxpress.net/wp-content/uploads/2011/01/08.jpg" alt="" width="304" height="98" /></a></p>
<p>Voici comment j’ai placé mes textes :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/09.jpg"><img class="alignnone size-full wp-image-5564" title="09" src="http://www.flashxpress.net/wp-content/uploads/2011/01/09.jpg" alt="" width="351" height="51" /></a></p>
<p>Nous allons maintenant sélectionner le rectangle et le texte composant le bouton « Lire » et appuyer sur F8 afin de convertir le tout en symbole.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/10.jpg"><img class="alignnone size-full wp-image-5565" title="10" src="http://www.flashxpress.net/wp-content/uploads/2011/01/10.jpg" alt="" width="449" height="165" /></a></p>
<p>Nommons le symbole « boutonLire », sélectionnons le type « Bouton » dans le menu déroulant du même nom, laissons l’alignement par défaut et validons en pressant le bouton « OK ». Entrons dans le symbole et insérons une image clé pour l’etat « Dessus » ainsi que pour l’état « Abaissé ». Sur l’état « Dessus », sélectionnons le rectangle de fond et intervertissons la position des deux couleurs (on revient donc au même dégradé que celui que l’on a sur le rectangle sous le titre).</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/21.jpg"><img class="alignnone size-full wp-image-5575" title="21" src="http://www.flashxpress.net/wp-content/uploads/2011/01/21.jpg" alt="" width="630" /></a></p>
<p>Une fois le symbole crée, sélectionnons l’occurrence de celui-ci présente sur la scène et donnons-lui pour nom d’occurrence « btnLire ».</p>
<p><img class="alignnone size-full wp-image-5566" title="11" src="http://www.flashxpress.net/wp-content/uploads/2011/01/11.jpg" alt="" width="303" height="115" /></p>
<p>La dernière étape consiste tout simplement à sélectionner l’occurrence du bouton, le rectangle de fond du titre de l’article ainsi que le champ de texte « titreArticle » et à convertir le tout en symbole de type Clip.</p>
<p>Nommez le « Ligne ». Lors de la création du symbole, choisissons donc comme type dans le menu déroulant « Clip ». Nous devons en plus de cela, cocher la case « Exporter pour ActionScript » ainsi que « Exporter dans l’image 1 » (cette dernière se coche normalement de façon automatique).</p>
<p>Cela va nous permettre d’instancier ce clip directement par code. Veillez en revanche à bien mettre une majuscule au nom du symbole car ici nous créons une classe et que, par convention, les noms de classe commencent par une majuscule.</p>
<p>Le champ « Classe de base » doit en principe directement pointer vers la classe MovieClip, du fait que nous ayons choisi comme type de symbole « Clip ».</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/12.jpg"><img class="alignnone size-full wp-image-5567" title="12" src="http://www.flashxpress.net/wp-content/uploads/2011/01/12.jpg" alt="" width="498" height="601" /></a></p>
<p>Validons ensuite la création de ce symbole en cliquant sur le bouton « OK ».</p>
<p>Si l’on regarde à présent dans notre bibliothèque, nous avons donc deux symboles, un bouton (boutonLire) et un MovieClip (Ligne).</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/14.jpg"><img class="alignnone size-full wp-image-5568" title="14" src="http://www.flashxpress.net/wp-content/uploads/2011/01/14.jpg" alt="" width="304" height="165" /></a></p>
<p>La colonne « Liaison » du bouton lire doit en principe être remplie avec comme mention « Ligne ».</p>
<p>Notre premier élément graphique est prêt. Nous pouvons à présent supprimer l’occurrence du MovieClip présent sur la scène.</p>
<p>Bien, je vais maintenant importer le logo que je souhaite placer dans mon application. Histoire de faire bien original, je vais utiliser le logo Flashxpress (super site, vous connaissez ? ^_^).</p>
<p>Je me contenterais ici de faire un copier / coller depuis Illustrator.</p>
<p>Une fois importé et redimensionné (il fait maintenant  100 pixels de largeur pour 30 de hauteur), je le convertis en symbole de type Clip, sans cocher cette fois ci l’option « Exporter pour ActionScript » et le nomme « logoFXP ». Je place enfin l’occurrence du clip « logoFXP » sur la scène à une position en X et en Y de 0. Notre logo est prêt.</p>
<p>Il nous reste deux petits éléments à préparer. En effet, ayant choisi de ne pas afficher mon application dans une fenêtre classique, je dois quand même donner la possibilité aux utilisateurs de la réduire et de la fermer. Nous allons donc dessiner une petite croix ainsi qu’un petit tiret.</p>
<p>Avec l’outil rectangle, je dessine un rectangle et lui donne des dimensions de 12 par 5 avec des coins arrondis. Voici ce que j’obtiens :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/15.jpg"><img class="alignnone size-full wp-image-5569" title="15" src="http://www.flashxpress.net/wp-content/uploads/2011/01/15.jpg" alt="" width="152" height="32" /></a></p>
<p>Pour créer la croix nous allons nous servir de ce trait d&#8217;union. Sélectionnons-le et dupliquons-le (CTRL + C / CTRL + V).</p>
<p>A l’aide de l’Outil de Transformation, faisons pivoter de 45° (donc en maintenant la touche SHIFT pour nous simplifier la tâche) le tiret. Dupliquons ce tiret et faisons le pivoter de 90°. Notre croix est prête.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/16.jpg"><img class="alignnone size-full wp-image-5570" title="16" src="http://www.flashxpress.net/wp-content/uploads/2011/01/16.jpg" alt="" width="187" height="33" /></a></p>
<p>Nous devons à présent convertir nos deux icônes en symbole. Une fois de plus nous choisirons comme type « Bouton » et nommerons nos symboles respectivement « traitUnion » pour l’icône de réduction de l’application et « croix » pour l’icône de fermeture.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/17.jpg"><img class="alignnone size-full wp-image-5571" title="17" src="http://www.flashxpress.net/wp-content/uploads/2011/01/17.jpg" alt="" width="449" height="165" /></a></p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/18.jpg"><img class="alignnone size-full wp-image-5572" title="18" src="http://www.flashxpress.net/wp-content/uploads/2011/01/18.jpg" alt="" width="449" height="165" /></a></p>
<p>Profitons-en pour attribuer le nom d’occurrence à nos icônes. Utiliser pour chaque icône le nom du symbole.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/19.jpg"><img class="alignnone size-full wp-image-5573" title="19" src="http://www.flashxpress.net/wp-content/uploads/2011/01/19.jpg" alt="" width="303" height="116" /></a></p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/20.jpg"><img class="alignnone size-full wp-image-5574" title="20" src="http://www.flashxpress.net/wp-content/uploads/2011/01/20.jpg" alt="" width="303" height="114" /></a></p>
<p>Pour finaliser nos boutons, ouvrons chacun des deux symboles, et insérons une image clé sur les états « Dessus » et « Abaissé ». Sur l’état « Dessus » changeons la couleur de l’objet. Je vais pour ma part choisir du rouge.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/21.jpg"><img title="21" src="http://www.flashxpress.net/wp-content/uploads/2011/01/21.jpg" alt="" width="630" /></a></p>
<p>Il ne nous reste plus qu’à positionner les boutons sur la scène.  Pour cela je glisse depuis la bibliothèque une occurrence du MovieClip « Ligne ». Et le positionne juste sous le logo. Je place en suite mes deux icones.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/22.jpg"><img class="alignnone size-full wp-image-5576" title="22" src="http://www.flashxpress.net/wp-content/uploads/2011/01/22.jpg" alt="" width="351" height="88" /></a></p>
<p>Et voilà, tous nos éléments graphiques sont prêts. Nous allons compiler l’application afin de tester l’interaction sur les boutons.</p>
<p>Nous pouvons supprimer l’occurrence du MovieClip, sauvegarder, aller prendre un café, fumer une cigarette et nous passerons ensuite à la partie code…</p>
<h1>Le code</h1>
<p>Dans cette seconde partie nous allons passer au code. Créons donc un nouveau calque et nommons-le AS.</p>
<p>Nous devons dans un premier temps récupérer notre flux RSS. Pour cela, nous utiliserons un URLLoader. L’URLRequest de l’URLLoader est simplement l’url du flux. Pour la récupérer, cliquons-droit sur le lien « S’abonner au flux RSS » présent en bas du site FlashXPress et sélectionnons « Copier l’adresse du lien ».</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/24.jpg"><img class="alignnone size-full wp-image-5578" title="24" src="http://www.flashxpress.net/wp-content/uploads/2011/01/24.jpg" alt="" width="358" height="57" /></a></p>
<p>Voici l’url que j’obtiens : <a href="http://www.flashxpress.net/feed/">http://www.flashxpress.net/feed/</a></p>
<p>Le code de mon URLLoader est donc :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code22'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555522"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p5555code22"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> chargeur<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=urlloader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlloader.html"><span style="color: #004993;">URLLoader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlloader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlloader.html"><span style="color: #004993;">URLLoader</span></a><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;http://www.flashxpress.net/feed/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Afin de récupérer le contenu de l’URLLoader une fois qu’il aura fini de le charger, nous devons ajouter un écouteur sur ce dernier pour l’évènement « Event.COMPLETE »:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code23'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555523"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p5555code23"><pre class="actionscript3" style="font-family:monospace;">chargeur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Ici j’ai choisi de nommer la fonction “init”.</p>
<p>Cette fonction va avoir plusieurs rôles :</p>
<ul>
<li>lire le RSS</li>
</ul>
<ul>
<li>instancier à chaque fois qu’un article est repéré le MovieClip « Ligne »</li>
</ul>
<ul>
<li>remplir le champ « titreArticle » avec le titre de l’article</li>
</ul>
<ul>
<li>ajouter sur le MovieClip une propriété dynamique urlArticle et la remplir avec l’url de l’article</li>
</ul>
<ul>
<li>ajouter un écouteur sur ce bouton pour que lorsqu’il est cliqué, l’article s’ouvre dans le navigateur</li>
</ul>
<ul>
<li>positionner la ligne</li>
</ul>
<p>Pour faire cela nous utiliserons une boucle.</p>
<p>Créons donc notre fonction :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code24'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555524"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p5555code24"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Nous avons besoin d’un objet de type XML pour stoquer les données présente dans l’URLLoader :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code25'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555525"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p5555code25"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
           <span style="color: #6699cc; font-weight: bold;">var</span> monFlux<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Comme source de données pour l’objet XML nous choisissons ici e.target.data. Cela nous renvoie les données présentes dans l’URLLoader « chargeur » du fait que l’écouteur est placé dessus.</p>
<p>Afin de nous assurer que les données arrivent bien a destination, réalisons un petit trace de notre objet XML « monFlux ».</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code26'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555526"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p5555code26"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> monFlux<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>monFlux<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Exécuter le programme. Rien ne se passe ? Mais si, guettez votre panneau de sortie et attendez quelques secondes…magie, les données envahissent votre petit panneau !</p>
<p>Bien. Si on observe ces données on voit que le titre des articles est contenu dans le nœud <code>&lt;title&gt;</code> et que l’url de notre article ce trouve dans le nœud <code>&lt;link&gt;</code>. Ces deux nœuds sont tous deux contenus dans le nœud <code>&lt;item&gt;</code>. Le nœud <code>&lt;item&gt;</code> quant à lui se trouve dans le nœud <code>&lt;channel&gt;</code>, lui-même étant dans le nœud <code>&lt;xml&gt;</code>.</p>
<p>Voici une version quelques peu raccourcie du contenu de l’objet XML :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code27'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555527"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p5555code27"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rss</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">xmlns:content</span>=<span style="color: #ff0000;">&quot;http://purl.org/rss/1.0/modules/content/&quot;</span> <span style="color: #000066;">xmlns:wfw</span>=<span style="color: #ff0000;">&quot;http://wellformedweb.org/CommentAPI/&quot;</span> …<span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
…
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Graphic Live Session à Meudon-la-Forêt<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://feedproxy.google.com/~r/flashxpress/~3/O0doqsfPls8/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comments<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://www.flashxpress.net/news/graphic-live-session-a-meudon-la-foret/#comments<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comments<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tue, 25 Jan 2011 14:35:51 +0000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dc:creator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Olivier<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dc:creator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[News]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;guid</span> <span style="color: #000066;">isPermaLink</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>http://www.flashxpress.net/?p=5543<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
…
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Pour récupérer notre titre nous devrons donc faire : channel.item.title</p>
<p>Et pour le lien : channel.item.link</p>
<p>Créons donc notre boucle. Celle-ci va devoir parcourir chaque nœud item et effectuer pour chacun d’eux toutes les tâches décrite ci-dessus.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code28'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555528"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p5555code28"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> monFlux<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
           <span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>monFlux<span style="color: #000066; font-weight: bold;">.</span>channel<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
           <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Commençons par essayer de récupérer dans le panneau de sortie tous les titres des articles :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code29'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555529"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p5555code29"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>monFlux<span style="color: #000066; font-weight: bold;">.</span>channel<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
           <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>monFlux<span style="color: #000066; font-weight: bold;">.</span>channel<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>title<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Cela fonctionne. En effet à chaque itération de la boucle « i » s’incrémentant, et récupérant le titre présent dans le nœud item[i], on arrive a tracer le nœud titre de chacun des nœuds item. Chaque nœud item correspondant a un article, on récupère bien le titre de tous les articles.</p>
<p>Bien. Supprimons ce trace, et maintenant nous voulons qu’à chaque itération de la boucle une occurrence de notre MovieClip soit instanciée et qu’elle soit remplie.</p>
<p>Dans notre boucle on crée donc une instance :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code30'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555530"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p5555code30"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> ligneArticle<span style="color: #000066; font-weight: bold;">:</span>Ligne = <span style="color: #0033ff; font-weight: bold;">new</span> Ligne<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>On va remplir le champ titre juste après avec les informations du RSS :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code31'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555531"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p5555code31"><pre class="actionscript3" style="font-family:monospace;">ligneArticle<span style="color: #000066; font-weight: bold;">.</span>titreArticle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = monFlux<span style="color: #000066; font-weight: bold;">.</span>channel<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>title<span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Rappelez-vous, titreArticle c’est le nom d’occurrence du champ texte dans le MovieClip « Ligne ».</p>
<p>On crée une propriété urlArticle sur le MovieClip de la ligne en cour de création :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code32'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555532"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p5555code32"><pre class="actionscript3" style="font-family:monospace;">ligneArticle<span style="color: #000066; font-weight: bold;">.</span>urlArticle = monFlux<span style="color: #000066; font-weight: bold;">.</span>channel<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">link</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>On ajoute un écouteur sur le click du bouton de la ligne pour qu’au clic il ouvre la navigateur et affiche la page de l’article :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code33'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555533"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p5555code33"><pre class="actionscript3" style="font-family:monospace;">ligneArticle<span style="color: #000066; font-weight: bold;">.</span>btnLire<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> ouvrirArticle<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Nous créons la fonction ouvrir article sous la fonction init :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code34'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555534"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p5555code34"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> ouvrirArticle<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
           <span style="color: #004993;">navigateToURL</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parent</span><span style="color: #000066; font-weight: bold;">.</span>urlArticle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Cette fonction contient un simple navigateToURL. L’URLRequest à pour valeur e.target(donc le bouton).parent(le MovieClip en somme).urlArticle(la propriété dynamique crée dans la boucle) .</p>
<p>Bien. Nous pouvons à présent nous occuper de placer notre occurrence sur la scène.</p>
<p>Nous lui donnons une position en x de 0, et en y de la hauteur du MovieClip * i. Comme à la première itération de la boucle i à pour valeur 0, la première ligne ce placera alors à 0*50. A la seconde itération, i aura une valeur de 1 donc le Movie clip sera placé à 50 pixels en y et ainsi de suite. A cela nous devons ajouter un décalage de la hauteur du logo car celui-ci se trouve en haut de la liste plus une petite marge. J’ajouterais donc 35. J’aimerais aussi laisser 1 pixel entre chaque MovieClip. J’ajout donc 1 à la hauteur du Movie clip.</p>
<p>En synthèse :</p>
<p>MovieClip.y = (i * (hauteur du MovieClip + 1(pour espacer de 1))) + 35 (pour laisser la place au logo).</p>
<p>Voilà tout ce charabia traduit en AS3 :p :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code35'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555535"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p5555code35"><pre class="actionscript3" style="font-family:monospace;">ligneArticle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
ligneArticle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">51</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">35</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>On l’ajoute à la liste d’affichage :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code36'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555536"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p5555code36"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>ligneArticle<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Voici donc le code final de notre boucle :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code37'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555537"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p5555code37"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>monFlux<span style="color: #000066; font-weight: bold;">.</span>channel<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
           <span style="color: #6699cc; font-weight: bold;">var</span> ligneArticle<span style="color: #000066; font-weight: bold;">:</span>Ligne = <span style="color: #0033ff; font-weight: bold;">new</span> Ligne<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
           ligneArticle<span style="color: #000066; font-weight: bold;">.</span>titreArticle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = monFlux<span style="color: #000066; font-weight: bold;">.</span>channel<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>title<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
           ligneArticle<span style="color: #000066; font-weight: bold;">.</span>urlArticle = monFlux<span style="color: #000066; font-weight: bold;">.</span>channel<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">link</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
           ligneArticle<span style="color: #000066; font-weight: bold;">.</span>btnLire<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> ouvrirArticle<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
           ligneArticle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
           ligneArticle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">51</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">35</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
           <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>ligneArticle<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Compilons. Ça fonctionne ! Merveilleux. Si on clique sur l’un des boutons lire, le navigateur s’ouvre a la page de l’article relatif au bouton cliqué !</p>
<p>Alors peut être, selon la hauteur de vos éléments (pour ne pas dire « si vous avez utilisez les mêmes dimensions que moi » ^_^ ‘), une partie de votre application sera tronquée (vers le bas). Pour remédier à cela, changez les dimensions de la scène de Flash. Pour ma par j’ai fini par mettre 500px de large par 1000px de haut.</p>
<p>Bien. Nous sommes presque au bout. Il ne nous reste plus qu’à faire une fonction pour permettre le drag de l’application, une pour la réduire dans la barre des tâches ou le dock selon le système d’exploitation et une pour la fermer.</p>
<p>Commençons par nous occuper du drag.</p>
<p>Ajoutons un écouteur sur le stage et créons la fonction dragAPP sous la fonction ouvrirArticle:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code38'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555538"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p5555code38"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> dragAPP<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> dragAPP<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Dans la fonction dragAPP nous allons utilizer la methode startMove() de la class nativeWindows afin de drager notre application.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code39'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555539"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p5555code39"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> dragAPP<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
           <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span>nativeWindow<span style="color: #000066; font-weight: bold;">.</span>startMove<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Si l’on compile et que l’on drag l’application en la prenant par le logo ou tout autre point, on arrive à la déplacer. Formidable.</p>
<p>Maintenant la fonction pour la réduire dans le dock ou dans la barre des tâches. On doit ajouter un écouteur sur l’icône réduire et créer la fonction minimizeAPP:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code40'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555540"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p5555code40"><pre class="actionscript3" style="font-family:monospace;">traitUnion<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> minimizeAPP<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> minimizeAPP<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
           <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span>nativeWindow<span style="color: #000066; font-weight: bold;">.</span>minimize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Nous faisons de nouveau appel à la classe nativeWindows, mais cette fois ci à sa méthode minimize() afin d’effectuer cette action.</p>
<p>Ajoutons un écouteur sur le bouton de fermeture de l’application et créons la fonction closeAPP :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5555code41'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p555541"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p5555code41"><pre class="actionscript3" style="font-family:monospace;">croix<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> closeAPP<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> closeAPP<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
           NativeApplication<span style="color: #000066; font-weight: bold;">.</span>nativeApplication<span style="color: #000066; font-weight: bold;">.</span>exit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Compilons et testons.</p>
<p>L’application est fonctionnelle. Nous pouvons donc préparer le fichier .air que vous distribuerez.</p>
<p>Dans le panneau des propriétés, cliquons sur le bouton « Modifier » des Paramètres d’Adobe AIR 2.</p>
<p>Dans l’onglet « Général » saisissons nos informations.</p>
<p>Notez que pour ID APP la convention veux que l’on retourne son nom de domaine et, qu’après un slash, on mette le nom de l’application.</p>
<p>A présent nous allons configurer l’icône de notre application. Pour cela, rendez-vous dans l’onglet « Icônes ». Vous devez avoir au préalable créé 4 tailles d’icône. Une en 16*16px, une autre en 32*32px, une troisième en 48*48 et une dernière en 128*128px. Indiquons donc en cliquant sur le petit bouton parcourir la path vers l’icône correspondante à la taille sélectionnée.</p>
<p>Pour terminer, rendons nous dans l’onglet « Signature ».</p>
<p>Dans celui-ci nous allons devoir cibler un certificat au format p12 et saisir son mot de passe.</p>
<p>Dans le cas ou vous n’avez pas de certificat, vous pouvez en générer un en cliquant sur le bouton « Créer » et en remplissant le champ de la fenêtre qui viens de s’ouvrir.</p>
<p>Cliquons maintenant sur le bouton « Publier ».</p>
<p>Notre fichier AIR est généré et prêt à être distribué.</p>
<p>Le but de ce didacticiel est atteint, je pense donc que nous arrivons au terme de ce tuto.</p>
<p>En espérant qu’il vous aura servi.</p>
<p>Amicalement,</p>
<p>Olivier.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/01/LecteurRSS-app.zip">Télécharger les sources</a> <span style="text-decoration: underline;"><span style="color: #ff0000;">! Flash CS5 est nécessaire pour ouvrir le .fla !</span><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/creation-d%e2%80%99un-lecteur-de-flux-rss-en-air-avec-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Envoyer un email via un formulaire et un script php</title>
		<link>http://www.flashxpress.net/ressources-flash/envoyer-un-email-via-un-formulaire-et-un-script-php/</link>
		<comments>http://www.flashxpress.net/ressources-flash/envoyer-un-email-via-un-formulaire-et-un-script-php/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 14:20:49 +0000</pubDate>
		<dc:creator>Nicolas Gans</dc:creator>
				<category><![CDATA[Flash dynamique]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS1]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=1363</guid>
		<description><![CDATA[Comment envoyer un mail depuis un formulaire grâce à la méthode sendAndLoad et un script php.

Télécharger email_loadvars.zip]]></description>
			<content:encoded><![CDATA[<p>
<object width="630" height="480">
<param name="movie" value="http://www.flashxpress.net/wp-content/uploads/2008/11/email_loadvars_2008.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<param name="allowFullScreen" value="true"></param>
<embed type="application/x-shockwave-flash" width="630" height="480" src="http://www.flashxpress.net/wp-content/uploads/2008/11/email_loadvars_2008.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" allowFullScreen="true" ></embed>
</object>
</p>
<p>Comment envoyer un mail depuis un formulaire grâce à l&#8217;objet loadVars, la méthode sendAndLoad et un script php.</p>
<p><em><strong>Note : </strong>suite à des abus, le script d&#8217;envoi de mail est désactivé dans cette page. La validation ne fonctionne donc pas, mais vous trouverez le script qui fonctionne dans l&#8217;archive .zip. A vous de placer ce script sur votre serveur pour que cela fonctionne.</em></p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2008/11/email_loadvars.zip">Télécharger email_loadvars.zip</a></p>
<p>Pour une méthode plus simple, reportez-vous à ce tutoriel :<br />
<a title="Envoyer un email avec getURL()" href="http://www.flashxpress.net/ressources-flash/envoyer-un-email-avec-geturl/">Envoyer un email avec getURL()</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/envoyer-un-email-via-un-formulaire-et-un-script-php/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Charger du son dynamiquement dans Flash</title>
		<link>http://www.flashxpress.net/ressources-flash/charger-du-son-dynamiquement-dans-flash/</link>
		<comments>http://www.flashxpress.net/ressources-flash/charger-du-son-dynamiquement-dans-flash/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 11:43:31 +0000</pubDate>
		<dc:creator>Thibault Imbert</dc:creator>
				<category><![CDATA[Flash dynamique]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS1]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=1253</guid>
		<description><![CDATA[Tout comme pour les images bitmaps, vous pouvez charger dynamiquement des sons sauvegardés dans un format particulier, en l&#8217;occurence ici le MP3. Prenez donc soin de bien enregistrer vos sons dans ce format, qui est d&#8217;ailleurs de par ses caractéristiques le mieux adapté à une diffusion sur Internet (rapport qualité/poids notamment). ActionScript 1 et 2 [...]]]></description>
			<content:encoded><![CDATA[<p>Tout comme pour les images bitmaps, vous pouvez charger dynamiquement des sons sauvegardés dans un format particulier, en l&#8217;occurence ici le MP3. Prenez donc soin de bien enregistrer vos sons dans ce format, qui est d&#8217;ailleurs de par ses caractéristiques le mieux adapté à une diffusion sur Internet (rapport qualité/poids notamment).</p>
<ol>
<li>
<h4><strong>ActionScript 1 et 2 &#8211; niveau débutant</strong></h4>
</li>
<p>Ce qui va nous permettre de charger dynamiquement un son dans un SWF est la méthode <strong>loadSound()</strong>, qui est une méthode de l&#8217;objet Son.<br />
Avant de charger un son au format <strong>MP3</strong>, il faut d&#8217;abord créer une occurence (ou instance) de l&#8217;objet Son dans laquelle on chargera le fichier MP3, qui nous permettra de cibler celui-ci et donc de manipuler certaines de ses propriétés (volume, balance&#8230;).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1253code48'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125348"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1253code48"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Création d'un nouveau son appelé &quot;monSon&quot;:</span>
monSon = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sound</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Une fois cet objet monSon créé, il nous faut encore lui assigner un son. Lorsque l&#8217;on souhaite jouer des sons importés dans flash, on utilise la méthode <strong>attachSound() </strong>qui permet de lui associer un son se trouvant dans la bibliothèque, auquel on avait pris soin au préalable de donner un identifiant de liaison. Pas vraiment dynamique tout ça <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Avec la méthode <strong>loadSound()</strong>, il n&#8217;est plus nécessaire d&#8217;importer le son dans le fichier FLA, de lui attribuer un identifiant de liaison, etc&#8230; Vous placez le fichier MP3 sur le serveur aux côtés du SWF, et ce dernier se chargera du reste&#8230; à condition toutefois que vous lui ayez demandé de le charger <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1253code49'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125349"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1253code49"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Création d'un nouveau son appelé &quot;monSon&quot;</span>
monSon = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sound</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// Chargement d'un fichier &quot;musique.mp3&quot; en flux continu dans monSon</span>
monSon.<span style="color: #0066CC;">loadSound</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;musique.mp3&quot;</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Une remarque sur le deuxième paramètre de cette méthode <strong>loadSound().</strong> Il s&#8217;agit d&#8217;un booléen qui permet de préciser si on veut que le son se joue en flux continu (téléchargement progressif ou s&#8217;il s&#8217;agit d&#8217;un son d&#8217;évènement, auquel cas le paramètre sera mis à <strong>false </strong>et le son entièrement chargé avant de jouer.</p>
<li>
<h4><strong>ActionScript 3 &#8211; niveau avancé</strong></h4>
</li>
<p>Le chargement de son peut être réalisé de manière dynamique. Les fichiers audio résident à l’extérieur de l’animation et sont chargées dynamiquement. Deux techniques peuvent être employées : La première consiste à créer un objet <strong>URLRequest </strong>valide pointant vers le fichier <strong>MP3 </strong>et passer ce dernier au constructeur de la classe <strong>Sound </strong>:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1253code50'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125350"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1253code50"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// création d'un objet Sound, la méthode load est automatiquement appelée</span>
<span style="color: #6699cc; font-weight: bold;">var</span> monSon<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a> <span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;son.mp3&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #3f5fbf;">/*
Si la classe Sound détecte un objet URLRequest valide, le son est chargé automatiquement au sein du lecteur à l’aide de la méthode load.
Le cas échéant, l’appel de la méthode load est obligatoire pour démarrer le chargement du son. La méthode load possède la signature suivante :
*/</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>stream<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a><span style="color: #000066; font-weight: bold;">,</span> context<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=soundloadercontext%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:soundloadercontext.html"><span style="color: #004993;">SoundLoaderContext</span></a> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> Voici le <span style="color: #004993;">d</span>étail de</pre></td></tr></table></div>

<p>chacun des paramètres :<br />
• <strong>stream </strong>: un objet <strong>URLRequest </strong>pointant vers le fichier MP3 à charger.<br />
• <strong>context </strong>: un objet <strong>SoundLoaderContext </strong>spécifiant la durée de préchargement en mémoire tampon ainsi que des consignes liées au chargement de fichiers de régulation.<br />
Attention, contrairement à l’intégration de son au sein de la bibliothèque compatible avec la plupart des formats audio, la méthode <strong>load </strong>de la classe <strong>Sound </strong>permet uniquement le chargement de fichiers <strong>MP3</strong>. Si nous tentons de charger un autre format de fichiers audio, aucune erreur spécifique n’est levée, le son n’est pas joué. La seconde technique consiste à créer l’objet <strong>Sound </strong>puis appeler manuellement la méthode <strong>load</strong>. Dans le code suivant nous ne passons pas d’objet <strong>URLRequest </strong>au constructeur de la classe <strong>Sound</strong>, le son est chargé à l’aide de la méthode <strong>load </strong>:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1253code51'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125351"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p1253code51"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// création d'un objet Sound</span>
<span style="color: #6699cc; font-weight: bold;">var</span> monSon<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// chargement dynamique du son</span>
son<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span> <span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;son.mp3&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Afin de gérer le chargement de son dynamique, l’objet Sound diffuse différents événements dont voici le détail :<br />
• <strong>Event.COMPLETE</strong> : diffusé lorsque le chargement du son est terminé.<br />
• <strong>Event.ID3</strong>: diffusé lorsque les informations ID3 sont disponibles.<br />
• <strong>IOErrorEvent.IO_ERROR</strong> : diffusé lorsque le chargement du son échoue.<br />
• <strong>Event.OPEN</strong> : diffusé lorsque le lecteur commence à charger le son.<br />
• <strong>ProgressEvent.PROGRESS</strong> : diffusé lorsque le chargement est en cours. Celui-ci renseigne sur le nombre d’octets chargés et totaux.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1253code52'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125352"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code" id="p1253code52"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// instanciation d'un objet Sound</span>
<span style="color: #6699cc; font-weight: bold;">var</span> son<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// chargement dynamique du son</span>
son<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span> <span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;son.mp3&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">// écoute des différents événements</span>
&nbsp;
son<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">OPEN</span><span style="color: #000066; font-weight: bold;">,</span> chargementDemarre <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
son<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ID3</span><span style="color: #000066; font-weight: bold;">,</span> informationsID3 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
son<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PROGRESS</span><span style="color: #000066; font-weight: bold;">,</span> chargementEnCours <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
son<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> chargementTermine <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
son<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=ioerrorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:ioerrorevent.html"><span style="color: #004993;">IOErrorEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> erreurChargement <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> chargementDemarre <span style="color: #000000;">&#40;</span> pEvt<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;chargement démarré&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> informationsID3 <span style="color: #000000;">&#40;</span> pEvt<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;informations ID3&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> chargementEnCours <span style="color: #000000;">&#40;</span> pEvt<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;chargement en cours : &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> pEvt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesLoaded</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; / &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> pEvt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesTotal</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> chargementTermine <span style="color: #000000;">&#40;</span> pEvt<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;chargement terminé&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> erreurChargement <span style="color: #000000;">&#40;</span> pEvt<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=ioerrorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:ioerrorevent.html"><span style="color: #004993;">IOErrorEvent</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;erreur de chargement&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Quelle que soit la technique employée pour charger dynamiquement un son, sa lecture doit être initiée à l’aide de la méthode <strong>play()</strong>. Si celle-ci est appelée en même temps que la méthode <strong>load()</strong>, la lecture du son est entamée lorsque suffisamment de données audio ont été téléchargées. Si nous tentons de démarrer la lecture du son avant l’avoir chargé, une erreur de type <strong>ArgumentError </strong>est levée : <em>ArgumentError: Error #2068: Son non valide</em></p>
<p>Attention, dans un contexte de chargement dynamique, la méthode <strong>load()</strong> ne renvoie pas d’objet <strong>SoundChannel</strong>. Seule la méthode <strong>play() </strong>le permet :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1253code53'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125353"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1253code53"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// instanciation d'un objet Sound, la méthode load est automatiquement appelée</span>
<span style="color: #6699cc; font-weight: bold;">var</span> son<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a> <span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;son.mp3&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">// lecture du son, la méthode play retourne un objet SoundChannel</span>
<span style="color: #6699cc; font-weight: bold;">var</span> canalSon<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=soundchannel%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:soundchannel.html"><span style="color: #004993;">SoundChannel</span></a> = son<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p><em>Remarque ::</em><br />
Il est important de noter que le chargement dynamique de sons est régit par le modèle de sécurité du lecteur. Par défaut, le chargement et la lecture d’un fichier son provenant d’un domaine différent est autorisée, mais l’accès aux données du fichier son est régulée. Dans un contexte inter-domaine, l’utilisation de la propriété id3 de l’objet <strong>Sound</strong>, de la méthode <strong>computeSpectrum</strong>, de la classe <strong>SoundMixer </strong>ou de l’objet <strong>SoundTransform </strong>lève une erreur de type <strong>SecurityError</strong>. Il convient alors d’utiliser un fichier de régulation sur le domaine distant afin d’autoriser la manipulation du son. Rappelez-vous que le lecteur Flash ne charge pas automatiquement de fichier de régulation afin de limiter la bande passante utilisée.</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/charger-du-son-dynamiquement-dans-flash/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Découverte de Remoting 2.0</title>
		<link>http://www.flashxpress.net/ressources-flash/decouverte-de-remoting-20/</link>
		<comments>http://www.flashxpress.net/ressources-flash/decouverte-de-remoting-20/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 13:41:40 +0000</pubDate>
		<dc:creator>Thibault Imbert</dc:creator>
				<category><![CDATA[Flash dynamique]]></category>
		<category><![CDATA[Tutoriel]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[WebTV]]></category>
		<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Remoting]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=856</guid>
		<description><![CDATA[Fichiers à télécharger : Amfphp ComposantComposants Remoting Qu’est ce que Flash remoting ? Flash Remoting est une passerelle permettant d’échanger des données avec un serveur de manière ultra simplifiée tout en conservant les types de données. Flash Remoting utilise un format binaire nommé ActionScript Message Format (AMF) permettant un gain de performances remarquable lors des échanges [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.envrac.org/images/title_tutos.png" alt="" /><br />
<strong>Fichiers à télécharger : </strong></p>
<p><a href="http://jaist.dl.sourceforge.net/sourceforge/amfphp/amfphp-1.1.0.zip" target="_blank">Amfphp</a><br />
<a href="http://www.macromedia.com/software/flashremoting/downloads/components/" target="_blank">ComposantComposants Remoting </a></p>
<p><strong>Qu’est ce que Flash remoting ?</strong></p>
<p><a href="http://www.macromedia.com/devnet/flashremoting/" target="_blank">Flash Remoting</a> est une passerelle permettant d’échanger des  données avec un serveur de manière ultra simplifiée tout en conservant les types de données.</p>
<p>Flash Remoting utilise un  format binaire nommé ActionScript Message Format (AMF) permettant un gain de  performances remarquable lors des échanges entre le serveur et Flash, le format  AMF étant un format natif compressé du lecteur. Le développeur Flash appelle des  méthodes distantes définies sur un service distant qui est en fait une classe  PHP définie sur le serveur.</p>
<p>La puissance de Flash Remoting consiste dans la  conversion automatique des données entre le serveur et le player Flash,  autrement dit, plus aucune sérialisation des données, Remoting s’occupe de  tout, vous passez un tableau à votre méthode distante, Remoting va convertir le  tableau ActionScript en un tableau compatible PHP, une Date ne sera pas  convertie automatiquement mais interprétée et passée en timestamp, mais il sera tout de même possible de renvoyer de PHP un objet Date à Flash en spécifiant le type retourné dans les attributs de la méthode dans le service distant.</p>
<p><strong>Pourquoi pas XML ? </strong></p>
<p>Le format XML permet de structurer vos données mais  nécessite un travail au niveau du schéma de représentation des données. Les  données n&#8217;étant pas compatible entre une application serveur et le player  Flash, vous ne pourrez pas renvoyer un tableau PHP à Flash de  manière transparente et inversement, il vous faudra à chaque fois sérialiser puis desérialiser  le tableau, d&#8217;où l&#8217;intérêt du XML.</p>
<p>Flash Remoting permet de gérer la conversion  des différents types d&#8217;objets automatiquement entre l&#8217;application serveur et le player Flash, tout cela au format AMF, ce qui  permet une intérpretation des données beaucoup plus performante qu&#8217;un parse de chaîne  de caractère (XML) qui necessiterait une sérialisation de la chaine vers un objet XML, un gain notable aussi bien au niveau performance que niveau bande passante  utilisée. De plus Flash Remoting a la capacité de retourner à Flash des  ressources mySQL sans aucun traitement à effectuer <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Pour utiliser Remoting et  PHP nous utiliserons <a href="http://www.amfphp.org" target="_blank">Amfphp</a>, car les classes Remoting que vous ajoutez en  installant les composants permettant la manipulation des données, les classes  nécessaires à la connexion mais n’intègre pas les classes gérant la conversion  des types entre Flash et le serveur pour cela vous pouvez utilisez Amfphp pour PHP,  <a href="http://fluorine.thesilentgroup.com/" target="_blank">Fluorine</a> pour .NET, <a href="http://www.openamf.org/cms/" target="_blank">OpenAMF</a> pour Java, ou encore <a href="http://www.simonf.com/flap/" target="_blank">Flap</a> pour Perl et Python.  Voici un tableau détaillant les types correspondants entre ActionScript et PHP  par exemple :</p>
<p><img src="http://www.flashxpress.net/images/r_flash/f_remoting/decouverte/images/conversion.png" alt="hjk" width="500" height="350" /></p>
<p>Voici un schéma expliquant le fonctionnement de Flash  Remoting :</p>
<p><img src="http://www.flashxpress.net/images/r_flash/f_remoting/decouverte/images/introa.gif" alt="jhk" width="442" height="511" /></p>
<p><a href="http://www.amfphp.org" target="_blank">Amfphp</a> installé sur votre serveur gère la conversion des  données entre Flash et la classe PHP, AMPHP est gratuit et open-source,  relativement léger il s’installe en quelques minutes sur votre serveur  mutualisé ou dédié. Il est aussi possible d’appeler des WebServices avec  AMFPHP, dans notre tutoriel nous utiliserons un service simple que nous  créerons.</p>
<p>Le but de ce tutoriel est d’aborder Flash Remoting au terme  de cette vidéo sous serez capable de vous connectez à une service distant et  d’appeler une méthode sur ce service, nous n’aborderons pas les thèmes comme le  débogage, ou encore l’optimisation de performances ou encore le design objet,  mais simplement comment débuter avec Flash Remoting. Trois tutoriaux seront  très bientôt disponible traitant du débogage avec Remoting, puis du Service  Browser permettant un développement des services distants extrêmement  simplifié, et enfin une explication avancée des différents attributs  disponibles pour la propriété methodTable.</p>
<p><strong>Attention</strong> : Pour bénéficier de l&#8217;encodage automatique des caractères spéciaux Français, veillez à bien décommenter la ligne suivante dans votre passerelle (gateway.php) comme ci dessous :</p>
<p><img src="http://www.flashxpress.net/images/r_flash/f_remoting/decouverte/images/decode.png" alt="" width="506" height="84" /></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="520" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="quality" value="high" /><param name="menu" value="false" /><param name="src" value="http://www.flashxpress.net/images/r_flash/f_remoting/decouverte/loader.swf" /><embed type="application/x-shockwave-flash" width="640" height="520" src="http://www.flashxpress.net/images/r_flash/f_remoting/decouverte/loader.swf" menu="false" quality="high"></embed></object></p>
<p><strong>Erratum </strong>: Dans la partie 3, une petite etourderie m&#8217;a fait importer la classe PendingCall du paquetage mx.services.PendingCall lors de l&#8217;appel de méthode distante. Cette classe correspond en fait aux PendingCall utilisés lors d&#8217;appels de méthodes de WebServices, la classe correcte est mx.remoting.PendingCall <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Dans l&#8217;absolu ce n&#8217;est pas grave cela fonctionne aussi, mais mieux vaut utiliser mx.remoting.PendingCall qui correspond au vrai type de données ( vérifiez avec instanceof ).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/decouverte-de-remoting-20/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Upload de Fichiers avec Flash</title>
		<link>http://www.flashxpress.net/ressources-flash/upload-de-fichiers-avec-flash/</link>
		<comments>http://www.flashxpress.net/ressources-flash/upload-de-fichiers-avec-flash/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 10:59:30 +0000</pubDate>
		<dc:creator>Eric Ambrosi</dc:creator>
				<category><![CDATA[Flash dynamique]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[Downloads]]></category>
		<category><![CDATA[FileReference]]></category>
		<category><![CDATA[Uploads]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=836</guid>
		<description><![CDATA[Objectif : Depuis Flash 8, une nouvelle API d&#8217;upload / download de fichiers est disponible, les classes de cet API se situent dans le répertoire flash.net.* Nous allons ensemble découvrir les classes et méthodes que Flash 8 propose pour gérer l&#8217;upload de fichiers sur un serveur distant. Au passage, nous utiliserons la notion d&#8217;écouteur. Ce [...]]]></description>
			<content:encoded><![CDATA[<h3>Objectif :</h3>
<p>Depuis Flash 8, une nouvelle API d&#8217;upload / download de fichiers est disponible, les classes de cet API se situent dans le répertoire flash.net.* Nous allons ensemble découvrir les classes et méthodes que Flash 8 propose pour gérer l&#8217;upload de fichiers sur un serveur distant. Au passage, nous utiliserons la notion d&#8217;écouteur.</p>
<p>Ce tutorial est la première partie d&#8217;un tout consacré à FileReference et ne traitera que de l&#8217;upload, nous verrons dans quelques semaines le donwload et les tips &amp; tricks de FileReference ainsi que la classe FileReferenceList.</p>
<p><strong>Niveau requis</strong> : Débutant Prog. AS 2.0 / Notions de serveurs Web<br />
<strong> Auteur :</strong> Eric Ambrosi<br />
<strong> Thèmes abordés :</strong> Installation du serveur Apache Wamp, configuration de wamp, utilisation de la classe FileReference<br />
<strong>Notions abordées :</strong> Les écouteurs, les méthodes asynchrones, serveurs Web<br />
<strong> Classes abordées :</strong> FileReference, Alert, PendingCall<br />
<strong> Logiciels :</strong> Flash 8, un serveur apache type (wamp,  easyphp, mamp (mac), IIS, etc)<br />
<strong>Fichiers à télécharger :</strong></p>
<p>Fichiers d&#8217;installation <a title="WampServer" href="http://sourceforge.net/project/downloading.php?groupname=wampserver&amp;filename=wamp5_1.6.6.exe&amp;use_mirror=switch" target="_blank">Wamp Server </a> &#8211; <a href="http://www.wampserver.com/download.php" target="_blank">site de WampServer</a></p>
<h3>Qu&#8217;est-ce que WampServer ?</h3>
<p>WampServer est un soft qui va nous permettre d&#8217;installer, sur un ordinateur windows, les services (ou daemons sous linux) apache et mysql.  Ces services vont être capables d&#8217;interpréter correctement les scripts de types php par exemple et si on en avait le besoin de nous permerttre de nous connecter à une base de donnée de type my-sql ou autre.</p>
<p>Pour réaliser un upload avec flash, il nous faudra utiliser un script php très simple qui sera interprété grâce à notre serveur apache. Wamp a de nombreux autres avantages et je vous invite à faire un tour sur leur site si vous souhaitez plus de détail sur cette technologie. D&#8217;autres très bonnes alternatives comme <em>easyphp </em>par exemple sont possibles pour réaliser cet exercice.</p>
<h3>Installation et Configuration de WampServer</h3>
<p>Tout d&#8217;abord télécharger et installer le server Wamp. Pour cela, il faut simplement suivre la procédure indiquer et valider tout le temps sans trop se poser de questions. Ce qui est vraiment intéressant par la suite est que wamp ne nécessite que très peu de configuration et permet le fonctionnement d&#8217;autres technologies comme remoting. <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h4>I &#8211; Création d&#8217;un nouveau répertoire</h4>
<p>La première chose à faire est de vous créer un nouveau répertoire sur <em><strong>c:</strong></em> que nous allons appeler <strong><em>upFlash</em></strong>. C&#8217;est ici que nous allons stocker nos fla, swf, et notre fameux script php. Vous vous retouvez donc avec un répertoire <strong>c:\upFlash\</strong>.</p>
<p>Le problème que nous avons à ce stade est que si nous plaçons ici un fichier php, il ne pourra pas être interprété par un quelquonque navigateur. Pour cela il nous faut créer un alias dans wamp.</p>
<h4>II &#8211; Mise en place d&#8217;un nouvel Alias</h4>
<h5>Définition d&#8217;un alias :</h5>
<p>Un alias est en fait la relation qu&#8217;il y a entre l&#8217;accès au répertoire <strong>c:\upFlash\ </strong>et l&#8217;accès à ce même répertoire, mais cette fois, au sein d&#8217;un navigateur Internet.</p>
<h5>Création de l&#8217;alias :</h5>
<p>Pour créer un alias faites un clique gauche sur l&#8217;icone wamp dans la barre windows. Allez sur <strong>alias directories =&gt; add an alias </strong>(image ci-dessous)<img title="addAlias" src="http://www.flashxpress.net/images/r_flash/f_dynamique/dy_FileRef/addAlias.jpg" alt="ajout d'un alias via wamp" width="489" height="370" /></p>
<h5>Configuration de l&#8217;alias :</h5>
<p>Une fenêtre DOS s&#8217;ouvre</p>
<blockquote>
<blockquote><p><span class="grasRouge">a &#8211; Le premier paramètre</span> est l&#8217;adresse su répertoire dans votre navigateur. Il faut simplement entrer le <strong><em>nom </em></strong>du répertoire que vous souhaitez configurer sous localhost. Je m&#8217;explique, à chaque fois que vous souhaiterez rendre accessible un dossier celui-ci sera accessible à l&#8217;adresse :<em><strong> http://localhost/</strong></em><strong><em>nom/</em></strong><em> </em></p>
<p>Ici <strong>nom </strong>sera le premier paramètre que vous rentrez pour la création de l&#8217;alias. Entrons comme nom <strong>exoUpFlash.</strong></p>
<p>Le répertoire c:\upFlash\ sera donc accessible à l&#8217;adresse: <em><strong>http://localhost/</strong><strong>exoUpFlash</strong></em><strong><em>/</em></strong><em> </em></p></blockquote>
</blockquote>
<p><span class="grasRouge">b &#8211; Le second paramètre</span> est l&#8217;adresse du répertoire sur le disque dur : il faut donc passer en paramêtre : <strong>c:\upFlash\</strong> et faire Entrer. A ce stade wamp doit redémarrer si ce n&#8217;est pas fait, redémarrez le manuellement en cliquant gauche puis Stop All Services puis Start All Services.</p>
<h5>Création d&#8217;un nouveau FLA</h5>
<p>Créer un nouvel Fla (fichier Flash) et l&#8217;enregistrer sur <strong>c:\upFlash\exo.fla</strong>. Ensuite ouvrez votre navigateur préféré puis tapez dans la barre d&#8217;adresse  :<em><strong> http://localhost/</strong><strong>exoUpFlash</strong></em><strong><em>/</em></strong>.<em> Vous y verrez votre </em><strong>exo.fla</strong> nouvellement créé.</p>
<h4>III &#8211; Configuration du php.ini</h4>
<p><em><span style="text-decoration: underline;">Remarque :</span> Cette étape est facultative dans la plus part des cas et l&#8217;upload de fichiers supéreurs à 8M peut fonctionner avec du wamp mais cette étape devient importante pour des serveurs de production.</em></p>
<ul>
<li>Nous allons maintenant configurer le fichier php.ini afin de travailler dans des conditions réelles, pour cela 2 variables du serveur sont à modifier.</li>
</ul>
<p><strong> post_max_size</strong></p>
<p><strong> upload_max_filesize</strong></p>
<p>Je sais que peu de monde modifie ces variables, pour ma part j&#8217;ai travaillé sur la mise en place d&#8217;une appli de gestion de doc (hébergée sur un serveur Linux Debian) et sans la modification de ces variables l&#8217;upload des fichiers ne dépassait pas 8M.  8M étant la valeur par défaut spécifiée dans le php.ini.</p>
<p>Cliquer sur l&#8217;icone wampserver à nouveau et sélectionner configFile =&gt; php.ini, trouvez les lignes suivantes via CTRL+F</p>
<p>(image ci-dessous)</p>
<p><img title="configPhp" src="http://www.flashxpress.net/images/r_flash/f_dynamique/dy_FileRef/config.jpg" alt="Configuration du php.ini" width="330" height="357" /></p>
<p>Modifier les lignes de cette façon :</p>
<p><strong>upload_max_filesize = 300M</strong></p>
<p><strong>post_max_size = 300M</strong></p>
<ul>
<li>Redémarrez WampServer en stoppant puis en relançant les services.</li>
</ul>
<p>Vous avez fini de configurer la partie serveur <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Mais à quoi peut bien servir de mettre 300M puisque FileReference est officiellement, selon Adobe, restreint à 100Mo . Je vous laisse faire vos propres test  <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<h3>Mise en place du script php</h3>
<p>Tout d&#8217;abord nous allons créer un sous répertoire c:\upFlash\<strong>uploads\. </strong>Il nous servira à stocker nos fichiers uploadés. Voici le script php que nous allons utiliser, c&#8217;est un script très simple que nous allons essayer de comprendre ensemble :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p836code56'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p83656"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p836code56"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// $_FILES s'apparente à $_POST; en fait la classe de flash 8 FileReference</span>
<span style="color: #666666; font-style: italic;">// utilise la méthode POST afin de transférer des fichiers à php,</span>
<span style="color: #666666; font-style: italic;">// on récupère notre fichier via la propriété Filedata</span>
<span style="color: #666666; font-style: italic;">// du Tableau associatif $_FILES</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Filedata&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$file</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//à l'arrivée de $file</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// on transfert le fichier temporaire créé sur le serveur</span>
<span style="color: #666666; font-style: italic;">// dans le répertoire uploads nouvellement créé</span>
<a href="http://www.php.net/move_uploaded_file"><span style="color: #990000;">move_uploaded_file</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;./uploads/&quot;</span> <span style="color: #339933;">.</span><a href="http://www.php.net/utf8_decode"><span style="color: #990000;">utf8_decode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// petite astuse donnée par Thibault / DickRivers</span>
<span style="color: #666666; font-style: italic;">// pour mac et certains serveurs</span>
<span style="color: #666666; font-style: italic;">// bug du onComplete jamais déclenché côte flash</span>
<span style="color: #666666; font-style: italic;">// donc pour déclencher le onComplete sous mac faire un simple echo</span>
<span style="color: #666666; font-style: italic;">// d'une chaine de caractère avec au moins 1 espace</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; Script Ok !&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Enregistrer ce script directement dans le répertoire <strong>c:\upFlash\ </strong>avec comme nom : <strong>upload.php</strong>.<br />
Ouvrez votre navigateur à l&#8217;adresse :  <span style="text-decoration: underline;"><em>http://localhost/exoUpFlash</em><em>/</em><strong><em>upload.php</em></strong></span><br />
Si votre script est correcte, vous devriez voir s&#8217;afficher le texte : <strong>Script Ok !</strong><br />
Si il y a une erreur alors souvent, il s&#8217;agit d&#8217;un point virgule ou d&#8217;une parenthèse manquante.</p>
<p><em><span style="text-decoration: underline;">Remarque : </span>la propriété <strong>Filedata </strong>ne s&#8217;écrit pas comme on s&#8217;y attendrait en flash <strong>fileData </strong>alors faites attention c&#8217;est une faute courante.</em></p>
<h3>La classe FileReference de Flash 8  / Notre premier Upload</h3>
<p>Ouvrez le fla que vous avez créé récemment <strong>exo.fla </strong>dans le répertoire <strong>c:\upFlash\ </strong>ou créez le si ce n&#8217;est déjà fait.</p>
<p>1 &#8211; Ajouter un nouveau calque et le nommer &#8216;action&#8217;, renommer l&#8217;ancien calque &#8216;contenu&#8217;. Notre code sera centralisé sur le calque action.</p>
<p>2 &#8211; Ouvrir le panneau des composants et déplacer 2 composants bouton sur la scene ainsi qu&#8217;un composant progressbar.<br />
Nommer la progressbar &#8216;my_pb&#8217;, le premier bouton &#8216;upload_btn&#8217; et le second bouton &#8216;cancel_btn&#8217;.<br />
Dans l&#8217;onglet paramètres du premier bouton changer la propriété label en &#8216;UpLoader&#8217;.<br />
Dans l&#8217;onglet paramètres du premier bouton changer la propriété label en &#8216;Annuler&#8217;.</p>
<p>3 &#8211; transférer un composant Alert dans votre bibliothèque, ce composant nous permettra d&#8217;afficher des messages d&#8217;alerte au sein de flash. Voici à quoi devrait ressembler votre scene sous Flash8 :<br />
<img title="configFla" src="http://www.flashxpress.net/images/r_flash/f_dynamique/dy_FileRef/scene.jpg" alt="Mise en place du fla" width="419" height="274" /></p>
<p>4 &#8211; Pour rappel : l&#8217;objectif de cette appli est de permettre d&#8217;uploader un fichier dans un répertoire cible, en l&#8217;occurence le répertoire de stockage sera <strong>c:\upFlash\uploads\ </strong>ou via notre navigateur internet <strong>http://localhost/exoUpFlash/uploads/</strong>.</p>
<p>5 &#8211; ouvrir le panneau action sur la frame du layer action (raccourci F9). Voici le code côté flash de notre application :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p836code57'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p83657"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
</pre></td><td class="code" id="p836code57"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Nous commençons par importer dans flash la classe FileReference.</span>
<span style="color: #808080; font-style: italic;">// Nous devons importer la classe FileReference car ce n'est pas une classe top level</span>
<span style="color: #808080; font-style: italic;">// , c'est à dire qu'elle n'est pas importée par défaut par le compilateur</span>
<span style="color: #808080; font-style: italic;">// au contraire de la classe MovieClip par exemple</span>
&nbsp;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">FileReference</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//ensuite nous devons importer la classe Alert qui va nous permettre</span>
<span style="color: #808080; font-style: italic;">//d'afficher des messages d'alertes sous forme de pop-up</span>
<span style="color: #808080; font-style: italic;">//n'oubliez pas de transférer un composant Alert dans votre bibliothèque</span>
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//création d'un nouvel Objet FileReference</span>
<span style="color: #808080; font-style: italic;">//c'est cet objet qui va nous permettre d'uploader un fichier vers le serveur</span>
<span style="color: #808080; font-style: italic;">//avec la méthode upload</span>
<span style="color: #000000; font-weight: bold;">var</span> myFileRefUpload:FileReference = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//configuration de la progress barre en mode manuel</span>
<span style="color: #808080; font-style: italic;">//Ce paramêtrage peut aussi se faire à partir de l'IDE de flash</span>
<span style="color: #808080; font-style: italic;">//en mode manuel nous pourrons fournir à la progressbar</span>
<span style="color: #808080; font-style: italic;">//le nombre de bytes chargés et le nombre de bytes total</span>
my_pb.<span style="color: #006600;">mode</span> = <span style="color: #ff0000;">&quot;manual&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//on crée ici un objet d'écoute</span>
<span style="color: #808080; font-style: italic;">//cet objet va centraliser toutes les méthodes asynchrones de FileReference</span>
<span style="color: #000000; font-weight: bold;">var</span> monEcouteurUpload:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//l'évènement onSelect est déclenché lorsque l'utilisateur a sélectionné</span>
<span style="color: #808080; font-style: italic;">//un fichier présent dans un répertoire</span>
monEcouteurUpload.<span style="color: #0066CC;">onSelect</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>pFile:FileReference<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//pFile est un objet de type FileReference, c'est l'objet passé en paramètre</span>
	<span style="color: #808080; font-style: italic;">//qui contient en propriété le nom du fichier que l'on souhaite uploader</span>
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> z <span style="color: #b1b100;">in</span> pFile<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>z+<span style="color: #ff0000;">&quot; :: &quot;</span>+pFile<span style="color: #66cc66;">&#91;</span>z<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #808080; font-style: italic;">//&amp;lt;= toujours passer le chemin absolu pour que cela fonctionne dans flash</span>
	<span style="color: #000000; font-weight: bold;">var</span> lienUpload = <span style="color: #ff0000;">&quot;http://localhost/exoUpFlash/upload.php&quot;</span>;
	pFile.<span style="color: #006600;">upload</span><span style="color: #66cc66;">&#40;</span>lienUpload<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
<span style="color: #808080; font-style: italic;">//L'évènement onProgress est déclenché lors de l'upload de fichier et renvoie 3 paramêtres</span>
<span style="color: #808080; font-style: italic;">//dont 2 qui récupèrent l'état du téléchargement en cours</span>
monEcouteurUpload.<span style="color: #006600;">onProgress</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>pFile:FileReference, pBytesLoaded:<span style="color: #0066CC;">Number</span>, pBytesTotal:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//la méthode setProgress affecte des valeurs à la progressbar</span>
	<span style="color: #808080; font-style: italic;">//à chaque fois que l'upload se met à jour</span>
	my_pb.<span style="color: #006600;">setProgress</span><span style="color: #66cc66;">&#40;</span>pBytesLoaded,pBytesTotal<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
<span style="color: #808080; font-style: italic;">//évènement déclenché lorsque l'upload est terminé</span>
monEcouteurUpload.<span style="color: #006600;">onComplete</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>pFile:FileReference<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//on ouvre un pop-up pour signifier que l'upload est terminé</span>
	<span style="color: #000000; font-weight: bold;">var</span> nomFichier = pFile.<span style="color: #0066CC;">name</span>;
	Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Le fichier &quot;</span>+nomFichier+<span style="color: #ff0000;">&quot; a été correctement uploadé !&quot;</span>,<span style="color: #ff0000;">&quot;Upload Terminé&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
<span style="color: #808080; font-style: italic;">//la méthode cancel se déclenche uniquement lorsque l'utilisateur annule l'upload dans</span>
<span style="color: #808080; font-style: italic;">//la fenêtre parcourir ( lors du browse() )</span>
monEcouteurUpload.<span style="color: #006600;">onCancel</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>pFile:FileReference<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//la méthode show de la classe Alert permet d'afficher un pop-up</span>
	Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;L'upload du fichier a été annulé !&quot;</span>,<span style="color: #ff0000;">&quot;Upload Annulé!!&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'toto'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
<span style="color: #808080; font-style: italic;">//la méthode onIOError se déclenche lorsque l'utilisateur annule l'upload ou le download</span>
<span style="color: #808080; font-style: italic;">//une fois que ceux-ci sont en cours et signale de façon plus général une interuption du flux</span>
monEcouteurUpload.<span style="color: #006600;">onIOError</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>pFile:FileReference<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>pFile.<span style="color: #0066CC;">name</span> <span style="color: #66cc66;">!</span>= <span style="color: #0066CC;">undefined</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> nomFichier = pFile.<span style="color: #0066CC;">name</span>+<span style="color: #ff0000;">&quot; &quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Upload en cours du fichier &quot;</span>+nomFichier+<span style="color: #ff0000;">&quot; a été annulé par l'utilisateur!&quot;</span>,<span style="color: #ff0000;">&quot;Annulation Utilisateur !&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
<span style="color: #808080; font-style: italic;">//myFileRefUpload souscrit à l'écouteur monEcouteurUpload</span>
<span style="color: #808080; font-style: italic;">//Bizarrement Adobe n'a pas utiliser le modele évèenementiel d'AS2.0 avec</span>
<span style="color: #808080; font-style: italic;">//addEventListener, mais cela est corrigé en AS3.0</span>
myFileRefUpload.<span style="color: #0066CC;">addListener</span><span style="color: #66cc66;">&#40;</span>monEcouteurUpload<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//gestion des boutons</span>
<span style="color: #808080; font-style: italic;">//la méthode browse de FileReference peut prendre un tableau d'objet ( tableau associatif )</span>
<span style="color: #808080; font-style: italic;">//en paramêtre ou bien aucun paramêtre. Lorsqu'aucun argument n'est fourni, tous les types</span>
<span style="color: #808080; font-style: italic;">//de fichiers sont sélectionnables pour l'upload, aucun filtre n'est appliqué.</span>
<span style="color: #808080; font-style: italic;">//voici un exemple de tableau à passer comme argument à la méthode</span>
<span style="color: #808080; font-style: italic;">//browse pour filtrer le type de fichiers que l'on souhaite rendre accessibles.</span>
<span style="color: #000000; font-weight: bold;">var</span> monTabType:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>description:<span style="color: #ff0000;">&quot;Divers Formats Images [*.gif,*.GIF,*.tga,*.TGA,*.bmp,*.BMP]&quot;</span>, extension:<span style="color: #ff0000;">&quot;*.gif;*.GIF;*.tga;*.TGA;*.bmp,*.BMP&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>description:<span style="color: #ff0000;">&quot;JPEG&quot;</span>, extension:<span style="color: #ff0000;">&quot;*.jpeg;*.JPEG&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>description:<span style="color: #ff0000;">&quot;PNG&quot;</span>, extension:<span style="color: #ff0000;">&quot;*.png;*.PNG&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>description:<span style="color: #ff0000;">&quot;Vidéo AVI&quot;</span>, extension:<span style="color: #ff0000;">&quot;*.avi;*.AVI&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>description:<span style="color: #ff0000;">&quot;Vidéo QuickTime [*.mov,*.MOV,*.mpeg]&quot;</span>, extension:<span style="color: #ff0000;">&quot;*.mov;*.MOV;*.mpeg&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>description:<span style="color: #ff0000;">&quot;MSI&quot;</span>, extension:<span style="color: #ff0000;">&quot;*.msi;*.MSI&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>description:<span style="color: #ff0000;">&quot;Exécutable&quot;</span>, extension:<span style="color: #ff0000;">&quot;*.exe;*.EXE&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>description:<span style="color: #ff0000;">&quot;Tous les fichiers&quot;</span>, extension:<span style="color: #ff0000;">&quot;*.*&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//on utilise ici un raccourci avec Handler</span>
upload_btn.<span style="color: #006600;">clickHandler</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//déclenchement de la méthode browse pour parcourir notre disque</span>
	<span style="color: #808080; font-style: italic;">//à la recherche d'un fichier cobaye</span>
	myFileRefUpload.<span style="color: #006600;">browse</span><span style="color: #66cc66;">&#40;</span>monTabType<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
<span style="color: #808080; font-style: italic;">//on annule l'upload grâce à la méthode cancel</span>
cancel_btn.<span style="color: #006600;">clickHandler</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//déclenchement de la méthode cancel manuellement</span>
	<span style="color: #808080; font-style: italic;">//l'évènement onIOResult et non l'évènement onCancel sera déclenché par cette méthode</span>
	myFileRefUpload.<span style="color: #006600;">cancel</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&lt;</span>a href=<span style="color: #ff0000;">&quot;http://www.flashxpress.net/_wp/wp-content/uploads/2008/11/illus_tuto_upload.jpg&quot;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>a<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Ca y est tout est en place pour que notre petite appli fonctionne <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
<p>Il ne suffit plus que de faire un ctrl+enter et vous pourrez vous lancer dans des back-offices incluant du FileReference <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p class="arial11">
<p class="arial11" align="center"><a title="sources" href="http://www.flashxpress.net/images/r_flash/f_dynamique/dy_FileRef/upFlash.zip" target="_blank">Voici les sources</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/upload-de-fichiers-avec-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chargement dynamique d&#8217;images ou de swf</title>
		<link>http://www.flashxpress.net/ressources-flash/chargement-dynamique-dimages-ou-de-swf/</link>
		<comments>http://www.flashxpress.net/ressources-flash/chargement-dynamique-dimages-ou-de-swf/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 07:25:45 +0000</pubDate>
		<dc:creator>Eric Ambrosi</dc:creator>
				<category><![CDATA[Flash dynamique]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS1]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/2005/08/12/medias-chargement-dynamique-mp3-et-jpeg/</guid>
		<description><![CDATA[La fonctionnalité dont nous allons parler ici est très certainement dans le top 5 des fonctionnalités les plus recherchées, nous allons donc décrire le code permettant de gérer ce chargement en AS1/AS2 ainsi qu&#8217;en AS3. Charger une image bitmap Petit historique : Depuis Flash MX le chargement d&#8217;image est possible, à l&#8217;époque, en 1978 l&#8217;année [...]]]></description>
			<content:encoded><![CDATA[<p>La fonctionnalité dont nous allons parler ici est très certainement dans le top 5 des fonctionnalités les plus recherchées, nous allons donc décrire le code permettant de gérer ce chargement en AS1/AS2 ainsi qu&#8217;en AS3.</p>
<h3>Charger une image bitmap</h3>
<p>Petit historique : Depuis Flash MX le chargement d&#8217;image est possible, à l&#8217;époque, en 1978 l&#8217;année de la consécration des &laquo;&nbsp;Bee Gees&nbsp;&raquo; avec &laquo;&nbsp;<em>Stayin&#8217; Alive</em>&nbsp;&raquo; et oui ça remonte à loin tout ça, nous ne pouvions charger que du jpeg non-progressif. Aujourd&#8217;hui la majeur partie des formats d&#8217;image sont pris en charge. Cependant Flash évolue dans un contexte on-line et même si les débits ont largement augmenté, il est de bon ton de compresser (en mode RVB) au préalable via Photoshop ou tout autre logiciel de retouche, les images que vous allez charger dynamiquement.</p>
<ol>
<li>
<h4><strong>En ActionScript 1 et 2 &#8211; niveau débutant :</strong></h4>
</li>
<p>Pour charger une image JPEG, on utilise la méthode de MovieClip<strong> <span class="script">loadMovie()</span></strong>, exactement de la même manière que lorsqu&#8217;on désire charger un swf externe.<br />
Dans notre exemple, nous allons charger une photo au format JPEG dans notre animation, au lancement de celle-ci, c&#8217;est-à-dire sur sa première image.<br />
Afin de pouvoir la manipuler comme s&#8217;il s&#8217;agissait d&#8217;un clip d&#8217;animation, nous allons la charger dans un clip vide. Cette manière de procéder est courante, elle va nous permettre d&#8217;utiliser une méthode introduite depuis Flash MX(1978). celle-ci permet la création dynamique de clips d&#8217;animation, par programmation: <strong><span class="script">createEmptyMovieClip()</span>.</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code65'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58565"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p585code65"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Création d'un clip vide nommé &quot;conteneur&quot;,</span>
<span style="color: #808080; font-style: italic;">// à la profondeur 1, sur _root:</span>
<span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">createEmptyMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;conteneur&quot;</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Maintenant que nous avons créé un clip vide, nous pouvons charger notre photo dans celui-ci:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code66'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58566"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p585code66"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Chargement d'une photo dans le nouveau clip &quot;conteneur&quot;:</span>
conteneur.<span style="color: #0066CC;">loadMovie</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;photo.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Et voilà! Nous venons de charger dynamiquement une image dans un clip, auquel vous pouvez appliquer toutes les transformations applicables à n&#8217;importe quel clip.<br />
Attention, comme lorsque l&#8217;on charge des animations au format SWF, pour cibler une image bitmap chargée dynamiquement, vous utiliserez comme chemin de ciblage le nom du clip dans lequel le fichier a été chargé, et non pas le nom du fichier.<br />
Ainsi, par exemple, pour redimensionner la photo précédemment chargée, on écrira:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code67'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58567"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p585code67"><pre class="actionscript" style="font-family:monospace;">conteneur.<span style="color: #0066CC;">_xscale</span> <span style="color: #66cc66;">/</span>= <span style="color: #cc66cc;">3</span>;
conteneur.<span style="color: #0066CC;">_yscale</span> <span style="color: #66cc66;">/</span>= <span style="color: #cc66cc;">3</span>;</pre></td></tr></table></div>

<li>
<h4><strong>En ActionScript 3 &#8211; niveau avancé :</strong></h4>
</li>
<p>ActionScript 3 élimine les nombreuses fonctions et méthodes existantes dans les précédentes versions d’ActionScript telle loadMovie et étend le concept de la classe MovieClipLoader introduite avec Flash MX 2004.</p>
<p>Afin de charger différents types de contenus tels des images ou des animations nous utilisons la classe <strong>flash.display.Loader</strong>. Celle-ci hérite de la classe <strong>DisplayObjectContainer </strong>et peut donc être ajoutée à la liste d’affichage. D’autres classes telles <strong>flash.net.URLLoader</strong> ou <strong>flash.net.URLStream</strong> peuvent être utilisées afin de charger tout type de contenu, mais leur utilisation s’avère plus complexe.</p>
<p>• La classe Loader permet le chargement de contenu graphique seulement.<br />
• Celle-ci hérite de la classe <strong>DisplayObjectContainer </strong>et peut donc être ajoutée à la liste d’affichage.<br />
• Il faut considérer la classe <strong>Loader </strong>comme un objet d’affichage.</p>
<p>La classe <strong>Loader </strong>permet de charger des images au format PNG, JPEG, JPEG progressif et GIF non animé. Des animations SWF peuvent aussi être chargées. Nous instancions tout d’abord la classe Loader :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code68'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58568"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p585code68"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> chargeur<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Puis nous appelons la méthode load dont voici la signature :</ol>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code69'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58569"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p585code69"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>request<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a><span style="color: #000066; font-weight: bold;">,</span> context<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loadercontext%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loadercontext.html"><span style="color: #004993;">LoaderContext</span></a> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<ol>Celle-ci requiert deux paramètres dont voici le détail :<br />
• request : un objet URLRequest contenant l’adresse de l’élément à charger.<br />
• context : un objet LoaderContext définissant le contexte de l’élément chargé inutile dans cet exemple.</p>
<p>La classe URLRequest est utilisée pour toute connexion externe HTTP liée aux classes URLLoader, URLStream, Loader et FileReference.</p>
<p>Dans le code suivant, nous enveloppons l’URL à atteindre dans un objet URLRequest :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code70'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58570"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p585code70"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// création du chargeur</span>
<span style="color: #6699cc; font-weight: bold;">var</span> chargeur<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// url à atteindre</span>
<span style="color: #6699cc; font-weight: bold;">var</span> maRequete<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;bob.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// chargement du contenu</span>
chargeur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span> <span style="color: #000000;">&#40;</span> maRequete <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>L’utilisation d’un objet <strong>URLRequest </strong>diffère des précédentes versions d’ActionScript où une simple chaîne de caractères était passée aux différentes fonctions liées au chargement externe. Certaines classes ActionScript 3 telles <strong>Socket, URLStream</strong>, <strong>NetConnection et NetStream </strong>font néanmoins exception et ne nécessitent pas d’objet <strong>URLRequest</strong>.</p>
<p>Afin de rendre graphiquement le contenu chargé nous devons ajouter l’objet Loader à la liste d’affichage :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code71'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58571"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p585code71"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// création du chargeur</span>
<span style="color: #6699cc; font-weight: bold;">var</span> chargeur<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// url à atteindre</span>
<span style="color: #6699cc; font-weight: bold;">var</span> maRequete<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;bob.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// chargement du contenu</span>
chargeur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span> <span style="color: #000000;">&#40;</span> maRequete <span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// ajout à la liste d'affichage</span>
<span style="color: #004993;">addChild</span> <span style="color: #000000;">&#40;</span> chargeur <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//L’image est alors affichée</span></pre></td></tr></table></div>

</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/chargement-dynamique-dimages-ou-de-swf/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

