<?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 ActionScript</title>
	<atom:link href="http://www.flashxpress.net/category/ressources-flash/flash-actionscript/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>Nouveautés Flash Player 11.2 &#8211; mouseLock, right click et cie..</title>
		<link>http://www.flashxpress.net/ressources-flash/nouveautes-flash-player-11-2-mouselock-right-click-et-cie/</link>
		<comments>http://www.flashxpress.net/ressources-flash/nouveautes-flash-player-11-2-mouselock-right-click-et-cie/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 11:56:00 +0000</pubDate>
		<dc:creator>alama</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Flash général]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[Flash Player 11.2]]></category>
		<category><![CDATA[middle_click]]></category>
		<category><![CDATA[MouseEvent.RIGHT_CLICK]]></category>
		<category><![CDATA[mouseLock]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=6842</guid>
		<description><![CDATA[Nouveautés Flash Player 11.2 (Beta au 7/12/2011) Les nouveautés principales que la majorité des programmeurs risquent d&#8217;utiliser tournent autour de la gestion souris. Voyons ça en détail. !! Les swfs d&#8217;exemples necessitent le Player 11.2 (beta) ou supérieur !! Téléchargez la beta 11.2 ici Gestion du right clic et du middle clic de la souris [...]]]></description>
			<content:encoded><![CDATA[<h1>Nouveautés Flash Player 11.2 (Beta au 7/12/2011)</h1>
<p>Les nouveautés principales que la majorité des programmeurs risquent d&#8217;utiliser tournent autour de la gestion souris. Voyons ça en détail.</p>
<p><strong>!! Les swfs d&#8217;exemples necessitent le Player 11.2 (beta) ou supérieur !!<br />
</strong></p>
<p><a href="http://labs.adobe.com/downloads/flashplayer11-2.html" target="_blank">Téléchargez la beta 11.2 ici</a></p>
<h1>Gestion du right clic et du middle clic de la souris</h1>
<p>Commençons par la plus simple, on peut désormais écouter des événements <strong><span class="typ">MouseEvent</span><span class="pun">.</span><span class="pln">RIGHT_CLICK</span></strong> et <strong><span class="typ">MouseEvent</span><span class="pun">.</span><span class="pln">MIDDLE_CLICK</span></strong>.</p>
<p>Concernant le middle clic, sur la plupart des souris, c&#8217;est l&#8217;enfoncement de la roulette.</p>
<p>Concernant le clic droit, par défaut, le clic droit fait apparaître le menu contextuel natif de Flash. Menu que l&#8217;on peut d&#8217;ailleurs modifier en partie, en ajoutant de nouvelles entrées. Depuis la version 11.2, le simple fait d&#8217;ajouter un écouteur d&#8217;événement sur le clic droit désactive le menu natif de Flash. Cela permet de faire d&#8217;autres choses au clic droit, ou de faire son propre menu avec son propre skin et ses propres entrées&#8230;</p>
<p>Aucune classe native de menu contextuel ne pourra servir de base, il faudra créer à 100% son menu et le gérer. L&#8217;avantage est une liberté totale.</p>
<p>Voici un simple exemple, il est évident qu&#8217;en situation réelle, il faudra créer une classe pour ce menu et la faire autrement avec des méthodes &laquo;&nbsp;addItem&nbsp;&raquo;, etc., plus un contrôle de positionnement en bord d&#8217;application, que je n&#8217;ai pas pris la peine de faire&#8230; Ici, c&#8217;est juste pour l&#8217;exemple.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_rightclic_1002981531"
			class="flashmovie"
			width="400"
			height="300">
	<param name="movie" value="http://www.covergraph.com/blog/flash/player11.2features/rightclic.swf" />
	<param name="scale" value="noscale" />
	<param name="allowfullscreen" value="true" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.covergraph.com/blog/flash/player11.2features/rightclic.swf"
			name="fm_rightclic_1002981531"
			width="400"
			height="300">
		<param name="scale" value="noscale" />
		<param name="allowfullscreen" value="true" />
	<!--<![endif]-->
		<br />
<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>Code de test:</h3>

<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('p6842code3'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p68423"><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
105
106
107
108
109
110
111
112
113
114
</pre></td><td class="code" id="p6842code3"><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.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>
	<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> menuItems<span style="color: #000066; font-weight: bold;">:</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: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> menu<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;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> output<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;">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>
		<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>
			menuItems = <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: #000066; font-weight: bold;">;</span>
			makeExampleMenu<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			output = <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>
			output<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>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Action: &quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>output<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<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>RIGHT_CLICK<span style="color: #000066; font-weight: bold;">,</span> mouseRightClikHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<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>MIDDLE_CLICK<span style="color: #000066; font-weight: bold;">,</span> mouseMiddleClikHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<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;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> mouseClikHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #3f5fbf;">/*__________________________________________________________________________________
		*
		*  Events Handlers
		* __________________________________________________________________________________
		*/</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> mouseRightClikHandler<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>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Action: <span style="">\&quot;</span>Right Click<span style="">\&quot;</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
			menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span>
			menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> mouseMiddleClikHandler<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>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Action: <span style="">\&quot;</span>Middle Click<span style="">\&quot;</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> mouseClikHandler<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>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Action: <span style="">\&quot;</span>Left Click<span style="">\&quot;</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> menuClickHandler<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>
			e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stopPropagation</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Action: Click on <span style="">\&quot;</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> menuItems<span style="color: #000000;">&#91;</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;">name</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\&quot;</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> menuItemOverHandler<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>
			menuItems<span style="color: #000000;">&#91;</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;">name</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span> = 0xff6600<span style="color: #000066; font-weight: bold;">;</span>
			menuItems<span style="color: #000000;">&#91;</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;">name</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">alpha</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> menuItemMouseOutHandler<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>
			menuItems<span style="color: #000000;">&#91;</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;">name</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span> = 0xffffff<span style="color: #000066; font-weight: bold;">;</span>
			menuItems<span style="color: #000000;">&#91;</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;">name</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">alpha</span> = <span style="color: #000066; font-weight: bold;">.</span>5<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #3f5fbf;">/*__________________________________________________________________________________
		*
		*  Privates Functions
		* __________________________________________________________________________________
		*/</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> makeExampleMenu<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>
			menu = <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>
			<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=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000; font-weight:bold;">6</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>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label = <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>
				<span style="color: #009900; font-style: italic;">// ! casting just for AutoCompletion helper</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: #000000;">&#40;</span>menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000000;">&#41;</span><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>
				<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: #000000;">&#40;</span>menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">selectable</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Ceci est l'Item &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span> = 0xffffff<span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseEnabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = i <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>btn = <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>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = i<span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</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>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</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;">MOUSE_OVER</span><span style="color: #000066; font-weight: bold;">,</span> menuItemOverHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</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;">MOUSE_OUT</span><span style="color: #000066; font-weight: bold;">,</span> menuItemMouseOutHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</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;">beginFill</span><span style="color: #000000;">&#40;</span>0x000000<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</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;">0</span><span style="color: #000066; font-weight: bold;">,</span> i <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</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>
				menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">alpha</span> = <span style="color: #000066; font-weight: bold;">.</span>5<span style="color: #000066; font-weight: bold;">;</span>
				menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>btn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>menuItems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			menu<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> menuClickHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			menu<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>menu<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h1>Le mouseLock et le movementMouse</h1>
<p>Une autre nouvelle fonctionnalité est le <strong>mouseLock</strong>. Le but ici est de rendre la souris active tout le temps! Même en dehors du stage (donc, en dehors de l&#8217;animation et même de l&#8217;écran).</p>
<p>Seule restriction, le <strong>mouseLock </strong>n&#8217;est possible qu&#8217;on mode <strong>fullScreen </strong>! Si on essaye de l&#8217;activer en mode normal, cela génère une erreur d&#8217;exécution visible par le player debugger.</p>
<p>Lorsque le <strong>mouseLock </strong>est <strong>activé</strong>, le <strong>curseur </strong>de la souris <strong>disparaît </strong>! A la base, c&#8217;est logique, puisque dans ce mode, nous n&#8217;avons pas besoin de savoir où se trouve réellement la souris. &laquo;&nbsp;Ha bon&nbsp;&raquo;, vous allez me dire.. Oui! dans ce mode, seules les variations de souris nous intéressent.. Voici l&#8217;explication..</p>
<p>Normalement, quand a besoin de connaître les coordonnées de la souris, on lit une des propriétés <strong>stageX</strong>(Y) ou <strong>localX</strong>(Y) d&#8217;un évènement <code>MouseEvent</code>. Lorsque le <strong>mouseLock </strong>est <strong>actif</strong>, ces propriétés sont fixée à <strong>0 </strong>et ne peuvent plus servir! On peut être tenté d&#8217;utiliser <code>le stage.mouseX(Y)</code>, mais celui-ci ne fonctione plus non plus&#8230; Il renverra n&#8217;importe quoi, basé sur un delta que nous allons voir ci après. Donc, en mode &laquo;&nbsp;<strong>mouseLock</strong>&laquo;&nbsp;, on oublie le système de coordonnées classique.</p>
<p>Par contre, deux nouvelles propriétés ont été ajoutées à <code>MouseEvent</code>! Il s&#8217;agit de <strong>movementX </strong>et <strong>movementY</strong>. Ces nouvelles propriétés, à l&#8217;inverse des anciennes, ne sont actives qu&#8217;en mode mouseLock! Le reste du temps, elles sont fixées à 0.</p>
<p>Le &laquo;&nbsp;movement&nbsp;&raquo; est en fait un deltaMouse, le nombre de pixels de déplacement qui a eu lieu entre 2 appels de l&#8217;<code>Event</code> mouseMove.</p>
<p>Cette nouveauté peut servir à plein de choses&#8230; surtout pour les jeux et certaines applications&#8230; On est plus contraint à la taille de l&#8217;animation, on peut juste regretter que cette <strong>fonctionalité ne soit disponible qu&#8217;en fullScreen</strong>..</p>
<p>Dans l&#8217;exemple ci dessous, je fais tourner un jog shuttle sans math, juste grace au <strong>movementX</strong>.</p>
<p><strong>Pour passer en fullScreen, veuillez cliquer sur le rectangle noir</strong>.</p>
<p>On peut voir que les propriétés <strong>mouseX(Y)</strong> ne fonctionnent qu&#8217;en <strong>normalScreen </strong>et que les <strong>movementX(Y)</strong> ne fonctionnent qu&#8217;en <strong>fullScreen</strong>. Cela est dû à <strong>l&#8217;activation du mouseLock</strong> au moment du passage en fullScreen.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_mouselock_1704787730"
			class="flashmovie"
			width="400"
			height="300">
	<param name="movie" value="http://www.covergraph.com/blog/flash/player11.2features/mouselock.swf" />
	<param name="scale" value="noscale" />
	<param name="allowfullscreen" value="true" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.covergraph.com/blog/flash/player11.2features/mouselock.swf"
			name="fm_mouselock_1704787730"
			width="400"
			height="300">
		<param name="scale" value="noscale" />
		<param name="allowfullscreen" value="true" />
	<!--<![endif]-->
		<br />
<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>Code simple qui permet de tester la chose.</h3>

<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('p6842code4'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p68424"><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
</pre></td><td class="code" id="p6842code4"><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.display</span><span style="color: #000066; font-weight: bold;">.</span>StageDisplayState<span style="color: #000066; font-weight: bold;">;</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=stagescalemode%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:stagescalemode.html"><span style="color: #004993;">StageScaleMode</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.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> menuItems<span style="color: #000066; font-weight: bold;">:</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: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> menu<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;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> output<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;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> shuttle<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>
&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>
			output = <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>
			output<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>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Stage Size = &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; X &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>output<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<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;">5</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">50</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;
			shuttle = <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>
			shuttle<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>0x333333<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			shuttle<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;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</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: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			shuttle<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>
			shuttle<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>0x999999<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			shuttle<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;">drawCircle</span><span style="color: #000000;">&#40;</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: #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;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			shuttle<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>
			shuttle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span>
			shuttle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">260</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>shuttle<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<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=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;">RESIZE</span><span style="color: #000066; font-weight: bold;">,</span> stageResizeHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<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_MOVE</span><span style="color: #000066; font-weight: bold;">,</span> stageMouseMoveHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/*__________________________________________________________________________________
		 *
		 *  Events Handlers
		 * __________________________________________________________________________________
		 */</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>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">displayState</span> = StageDisplayState<span style="color: #000066; font-weight: bold;">.</span>FULL_SCREEN<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span>mouseLock = <span style="color: #0033ff; font-weight: bold;">true</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> stageResizeHandler<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>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Stage Size = &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; X &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</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> stageMouseMoveHandler<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>
			output<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Stage Size = &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; X &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">+</span>
			<span style="color: #990000;">&quot;<span style="">\n</span>mouseX: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageX</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; - mouseY: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageY</span> <span style="color: #000066; font-weight: bold;">+</span>
			<span style="color: #990000;">&quot;<span style="">\n</span>movementX: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> e<span style="color: #000066; font-weight: bold;">.</span>movementX <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; - movementY: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> e<span style="color: #000066; font-weight: bold;">.</span>movementY<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			shuttle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span> <span style="color: #000066; font-weight: bold;">+</span>= e<span style="color: #000066; font-weight: bold;">.</span>movementX<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>

<h1>Conclusion</h1>
<p>Ces nouvelles fonctionnalités vont sans doute trouver un certain succès auprès des programmeurs&#8230; Surtout la gestion du clic droit et le fait de pouvoir faire ses propres menus contextuels.</p>
<p>Le mouseLock est très bien lorqu&#8217;on souhaitera avoir un contrôle qui va au-delà de l&#8217;espace de l&#8217;animation et même au-delà de l&#8217;écran (défilement de quelque chose, jeux, ..).</p>
<p>Il y a encore d&#8217;autres nouveautés telles que la mise à jour automatique du Player en arrière plan (tâche de fond) ou le décodage de la video (h264) en background, dans un thread séparé.</p>
<p>Les exemples de code (et swfs) présents sur cette page sont très primaires, ils ont pour but de démystifier les nouvelles fonctionnalités du Flash Player 11.2. A chacun d&#8217;y trouver un usage propre et de développer ses algorithmes persos&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/nouveautes-flash-player-11-2-mouselock-right-click-et-cie/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Introduction au Starling Framework</title>
		<link>http://www.flashxpress.net/ressources-flash/introduction-au-starling-framework/</link>
		<comments>http://www.flashxpress.net/ressources-flash/introduction-au-starling-framework/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 12:41:30 +0000</pubDate>
		<dc:creator>Nicolas Gans</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Stage3D]]></category>
		<category><![CDATA[Starling]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=6643</guid>
		<description><![CDATA[Avec la sortie de Flash player 11, une petite révolution fait son apparition : Stage3D. Connue auparavant sous le nom de Molehill, cette nouvelle API apporte ce dont beaucoup de développeurs Flash on rêvé : la VRAIE 3D, calculée par le GPU (carte graphique) de l'ordinateur. Si Stage3D permet évidemment d'afficher des modèles 3D complexes de plusieurs dizaine de milliers de polygones (voir ici, ici et là), un autre usage a rapidement été envisagé : l'affichage 2D. En effet, qu'est ce que la 2D, sinon de la 3D avec une dimension en moins ;)]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-6704" title="starling_header" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_header.jpg" alt="" width="630" height="300" /></p>
<h1>Starling Framework ? Keskeussé ?</h1>
<p>Avec la sortie de Flash player 11, une petite révolution fait son apparition : <strong>Stage3D</strong>. Connue auparavant sous le nom de Molehill, cette nouvelle API apporte ce dont beaucoup de développeurs Flash ont rêvé : la <span style="text-decoration: underline;"><strong>VRAIE</strong></span> 3D, calculée par le GPU (carte graphique) de l&#8217;ordinateur. Si Stage3D permet évidemment d&#8217;afficher des modèles 3D complexes de plusieurs dizaines de milliers de polygones (voir <a title="Les Chinois" href="http://www.leschinois.com/" target="_blank">ici</a>, <a title="Flare3D" href="http://www.flare3d.com/demos/max/gargoile.html" target="_blank">ici</a> et <a title="Alternativa3D" href="http://alternativaplatform.com/en/demos/crash/" target="_blank">là</a>), <strong>un autre usage a rapidement été envisagé : l&#8217;affichage 2D.</strong> En effet, qu&#8217;est ce que la 2D, sinon de la 3D avec une dimension en moins <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Dans cette optique, Adobe a annoncé récemment la sortie d&#8217;une librairie nommée <a title="Starling Framework" href="http://www.starling-framework.org/" target="_blank">Starling Framework</a> qui permet un affichage 2D beaucoup plus rapide que l&#8217;affichage &laquo;&nbsp;classique&nbsp;&raquo; de Flash, en s&#8217;appuyant sur la puissance de calcul du GPU et les nouvelles API de Stage3D. Signalons qu&#8217;Adobe n&#8217;a pas développé Starling directement, mais que c&#8217;est <a href="http://bytearray.org" target="_blank">Thibault Imbert</a>, product manager responsable de Stage3D, qui a demandé à <strong>Daniel Sperl</strong> de porter Sparrow &#8211; une librairie pour iOS reproduisant les mécanismes de la liste d&#8217;affichage de Flash &#8211; en ActionScript 3. La bonne nouvelle, <span style="text-decoration: underline;">c&#8217;est que Starling est Open Source et fortement communautaire</span> : chacun a accès au code, peut le modifier et l&#8217;enrichir selon ses besoins propres ou ceux de la communauté !</p>
<p><strong>Note culturelle</strong> : <em>en français, Starling signifie étourneau. D&#8217;où l&#8217;image utilisée comme illustration</em> <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h1>Demo Time !</h1>
<p>Mettons de côté le blabla quelques secondes et allez voir ces deux petits tests que j&#8217;ai réalisé pour vous rendre compte des performances de Starling (<span style="text-decoration: underline;">ATTENTION : il faut le Flash Player 11</span>) :</p>
<p><a title="Particules Starling" href="http://www.kouma.fr/lab/StarlingParticles/" target="_blank"><img class="alignnone size-full wp-image-6645" title="starling_tuto_01" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_01-e1319034008695.png" alt="" width="630" height="369" /><br />
</a>Des petites particules, parce que c&#8217;est joli et que&#8230; tout le monde aime les particules <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a title="Starling Stress Test" href="http://www.kouma.fr/lab/StarlingStressTest/" target="_blank"><img class="alignnone size-full wp-image-6648" title="starling_tuto_02" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_02-e1319034440957.png" alt="" width="630" height="367" /><br />
</a>Un stress test pour voir jusqu&#8217;où Starling tient : cliquez sur le bouton en haut à gauche pour ajouter plein de MovieClip et les faire bouger dans tous les sens.</p>
<p>Je ne sais pas ce que vous en pensez, mais personnellement je trouve que Starling envoie ! Pour les mauvais esprits (il y&#8217;en a), notez bien que <strong>Starling n&#8217;en est qu&#8217;à la V1 et que des optimisations sont déjà envisagées</strong>, qui seront ajoutées dans une mise à jour future.</p>
<h1>Pourquoi utiliser Starling ?</h1>
<p>En premier lieu, <strong>pour les performances</strong> ! D&#8217;autant que Stage3D arrivera bientôt sur nos téléphones et tablettes via <strong>AIR 3.1</strong>. Alors que des optimisations complexes étaient nécessaire pour atteindre péniblement les 30 fps avec la liste d&#8217;affichage traditionnelle de Flash, on peut tout à fait envisager que Stage3D nous permette de rivaliser en terme de performances avec les applications &laquo;&nbsp;natives&nbsp;&raquo;.</p>
<p>En second lieu, parce que Starling a été pensé <strong>pour coller à l&#8217;API de la DisplayList de Flash</strong> : on y retrouve nos Sprite, MovieClip, addChild(), removeChild(), etc&#8230; ainsi qu&#8217;un modèle événementiel calqué sur celui de Flash avec un support du bubbling. <strong>La transition est donc largement simplifiée pour les développeurs</strong>, avec tout de même des spécificités propres à un environnement &laquo;&nbsp;full GPU&nbsp;&raquo;. En effet, dès lors que l&#8217;on confie l&#8217;affichage au GPU et non plus au CPU, il faut dire adieu au vectoriel et n&#8217;utiliser que des bitmaps. Mais nous allons en reparler dans ce tutoriel&#8230;</p>
<p>Enfin, il faut reconnaître que Starling a été <strong>pensé avant tout pour le jeu 2D</strong>, et même si on peut tout-à-fait l&#8217;envisager pour de l&#8217;application mobile ou du site &laquo;&nbsp;multimédia&nbsp;&raquo;, ce n&#8217;est pas son but premier&#8230; Pas étonnant dès lors que les premières démos crées avec Starling soient des casual games Flash :</p>
<p><iframe src="http://www.youtube.com/embed/yOtnRSaoK-c" frameborder="0" width="630" height="350"></iframe><br />
Angry Bird pour le player 11, c&#8217;est pour bientôt dans le browser.</p>
<p>Toutefois, la nature &laquo;&nbsp;low-level&nbsp;&raquo; de Stage3D permet à chacun &#8211; pour peu qu&#8217;il en ait la capacité &#8211; de créer son propre moteur 2D. <strong>Il existe ainsi un &laquo;&nbsp;concurrent&nbsp;&raquo; à Starling</strong> : <a title="ND2D framework" href="https://github.com/nulldesign/nd2d" target="_blank">ND2D</a>, qui fait à peu près la même chose et qui est plutôt plus optimisé. Et même si Starling est officiellement supporté par Adobe, rien ne vous oblige à l&#8217;utiliser !</p>
<p>Ceci étant dit, passons à la pratique !</p>
<h1>Mise en place</h1>
<p>Pour notre exemple nous utiliserons Flash Builder 4.5.</p>
<h2>Téléchargements</h2>
<p>Tout d&#8217;abord, il faut télécharger les fichiers suivants :</p>
<ul>
<li>Si le SDK 4.5.1 n&#8217;est pas déjà installé dans le dossier &laquo;&nbsp;sdks&nbsp;&raquo; du répertoire d&#8217;install de Flash Builder, il faudra le télécharger : <a title="Flex SDK 4.5.1" href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.5" target="_blank">http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.5</a></li>
</ul>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_03.png"><img class="alignnone size-full wp-image-6669" style="border-width: 1px; border-color: black; border-style: solid;" title="starling_tuto_03" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_03-e1319099653341.png" alt="" width="594" height="284" /></a></p>
<ul>
<li>Télécharger le SDK AIR 3.0 : <a title="AIR SDK" href="http://www.adobe.com/special/products/air/sdk/" target="_blank">http://www.adobe.com/special/products/air/sdk/</a></li>
<li>Télécharger la librairie Starling : <a title="Starling Framework" href="http://www.starling-framework.org" target="_blank">http://www.starling-framework.org</a> (le gros bouton &laquo;&nbsp;DOWNLOAD&nbsp;&raquo;)</li>
</ul>
<h2>Installation du SDK</h2>
<h3>Windows</h3>
<p>1) Allez dans le dossier &laquo;&nbsp;<strong>sdks</strong>&nbsp;&raquo; du répertoire d&#8217;installation de Flash Builder 4.5. Si le SDK 4.5.1 est déjà présent, faites-en une copie et renommez-la « <strong>AIR 3.0</strong> ». Sinon, dézippez l&#8217;archive téléchargée à l&#8217;étape précédente et renommez le répertoire « <strong>AIR 3.0</strong> ».</p>
<p>2) Copiez ensuite le .zip du SDK AIR 3.0 dans le dossier « AIR 3.0 » et dézippez-la <span style="text-decoration: underline;"><strong>en veillant bien à écraser les fichiers déjà présents</strong></span>.</p>
<h3>MAC OS</h3>
<p>1) Allez dans le dossier « <strong>sdks</strong> » du répertoire d&#8217;installation de Flash Builder 4.5. Si le SDK 4.5.1 est déjà présent, faites-en une copie et renommez-la « <strong>AIR 3.0</strong> ». Sinon, dézippez l&#8217;archive téléchargée à l&#8217;étape précédente et renommez le répertoire « <strong>AIR 3.0</strong> ».</p>
<p>2) Placer l’archive « <strong>AdobeAIRSDK.tbz2</strong> » dans le répertoire « <strong>AIR 3.0</strong> ».</p>
<p>3) Ouvrir le Terminal, aller dans le répertoire dans lequel on a copié le AIR SDK avec la commande suivante (valider en appuyant sur return) :</p>
<pre><span style="color: #808080;">cd /Applications/Adobe Flash Builder 4.5/sdks/</span></pre>
<p>Il faut échapper les espaces avec un « \ »</p>
<p><strong>Note</strong> : <em>on peut faire un drag n’drop du répertoire dans le terminal pour récupérer automatiquement le chemin d’accès. <strong>METTRE « cd » devant le chemin !!</strong></em></p>
<p>4) Puis taper la commande suivante et appuyer sur return :</p>
<pre><span style="color: #808080;">tar jxvf AdobeAIRSDK.tbz2</span></pre>
<p>Cela dézippera l’archive et la fusionnera avec Flex SDK.</p>
<h3>playerglobal.swc</h3>
<p><span style="text-decoration: underline;">Ajout du 27 octobre 2011 (merci à Dredge pour le commentaire).</span></p>
<p>Vous aurez éventuellement besoin du playerglobal.swc de Flash 11 : il contient les définitions de classes compilés et si il n&#8217;est pas présent par défaut dans le SDK, il faut donc l&#8217;ajouter.</p>
<p>Pour vérifier si ce fichier est présent, aller dans le répertoire de Flash Builder, puis dans « sdks\AIR 3.0\frameworks\libs\player ». <strong>Si le répertoire « 11.0 » n&#8217;est pas présent, il faut l&#8217;ajouter.</strong></p>
<p>Pour remédier à ça :<br />
- Télécharger le playerglobal.swc depuis cette url : <a href="http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/playerglobal11_0.swc" rel="nofollow">http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/playerglobal11_0.swc</a><br />
- renommer le fichier en « playerglobal.swc »<br />
- dans le répertoire de Flash Builder, aller dans « sdks\AIR 3.0\frameworks\libs\player »<br />
- créer un répertoire « 11.0 » et y placer le « playerglobal.swc »</p>
<p>Si FB vous signale une erreur, nettoyer le projet via le menu « project/clean/ », cela devrait supprimer l’erreur.</p>
<h3>Ajout du SDK à Flash Builder</h3>
<p>1) Lancer Flash Builder et aller dans les préférences. <strong>Window &gt; Preferences</strong> (Fenêtre &gt; Préférences) sous Windows ou <strong>Flash Builder &gt; Preferences</strong> sous MAC OS.</p>
<p>2) Dans le champ de recherche, taper “<strong>sdk</strong>”, puis sélectionner “<strong>Installed Flex SDKs</strong>”.</p>
<p>3) Vous pouvez voir la liste des SDKs installés, les mêmes que dans le répertoire &laquo;&nbsp;<strong>sdks</strong>&nbsp;&raquo; de l&#8217;application. Cliquer sur le bouton &laquo;&nbsp;<strong>Add…</strong>&nbsp;&raquo; situé à droite de la liste :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_04.png"><img class="alignnone size-full wp-image-6671" title="starling_tuto_04" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_04.png" alt="" width="774" height="537" /></a></p>
<p>4) Dans la fenêtre ouverte, &laquo;&nbsp;<strong>Flex SDK location</strong>&nbsp;&raquo; : parcourir le disque dur et sélectionner le répertoire « <strong>AIR 3.0</strong> » créé précédemment.</p>
<p>5) &laquo;&nbsp;<strong>Flex SDK name</strong>&nbsp;&raquo; : taper « <strong>AIR 3.0</strong> ».</p>
<p>6) Puis valider en cliquant sur &laquo;&nbsp;<strong>OK</strong>&laquo;&nbsp;.</p>
<p><strong>En principe, le SDK doit dorénavant apparaître dans la liste des SDKs installés.</strong></p>
<h2>Création d&#8217;une librairie Starling</h2>
<p>Pour utiliser la librairie Starling dans différents projets Flash Builder, nous allons créer une librairie <strong>qui pourra être partagée entre différents projets</strong>, évitant ainsi la duplication des classes Starling.</p>
<p>1) Créer un projet de type &laquo;&nbsp;<strong>Flex Library Project</strong>&nbsp;&raquo;</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_05.png"><img class="alignnone size-full wp-image-6676" title="starling_tuto_05" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_05.png" alt="" width="661" height="137" /></a></p>
<p>2) Nommer ce projet StarlingLib et choisir le SDK « <strong>AIR 3.0</strong> » :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_06.png"><img class="alignnone size-full wp-image-6677" title="starling_tuto_06" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_06.png" alt="" width="525" height="577" /></a></p>
<p>3) Une fois le projet créé, faire un <strong>clic droit sur le projet &gt; &laquo;&nbsp;Properties</strong>&laquo;&nbsp;, puis sélectionner &laquo;&nbsp;<strong>Flex Librairy Compiler</strong>&nbsp;&raquo; dans la colonne de gauche. Cibler le <strong>player 11.0.0</strong> et ajouter « <strong>-swf-version=13</strong> » dans les paramètres additionnels du compilateur :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_07.png"><img class="alignnone size-full wp-image-6678" title="starling_tuto_07" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_07.png" alt="" width="784" height="697" /></a></p>
<p>4) Copier les classes de l&#8217;archive du Starling Framework dans le dossier &laquo;&nbsp;<strong>src</strong>&nbsp;&raquo; du projet StarlingLib. Les classes de Starling se trouvent dans le dossier &laquo;&nbsp;<strong>Starling/src</strong>&nbsp;&raquo; de l&#8217;archive. <strong><span style="text-decoration: underline;">Il faut aussi copier le dossier &laquo;&nbsp;media&nbsp;&raquo;, sinon une erreur d&#8217;embed sera générée par Flash Builder !</span></strong> Au final, vous aurez trois répertoires dans le dossier &laquo;&nbsp;<strong>src</strong>&nbsp;&raquo; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_08.png"><img class="alignnone size-full wp-image-6679" title="starling_tuto_08" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_08.png" alt="" width="411" height="78" /></a></p>
<p>5) En principe, un fichier <strong>StarlingLib.swc</strong> a été créé dans le répertoire &laquo;&nbsp;<strong>bin</strong>&nbsp;&raquo; du projet StarlingLib.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_09.png"><img class="alignnone size-full wp-image-6680" title="starling_tuto_09" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_09.png" alt="" width="378" height="136" /></a></p>
<p><strong>Note</strong> : <em>si Flash Builder peine à créer le .swc, faites un clic droit sur le projet &gt; &laquo;&nbsp;Refresh&nbsp;&raquo;.</em></p>
<p><strong>Vous pourrez maintenant utiliser cette librairie pour tous vos projets Starling, en l&#8217;ajoutant au &laquo;&nbsp;library path&nbsp;&raquo; du projet (voir exemple ci-dessous).</strong></p>
<h2>Création d&#8217;un premier projet Starling</h2>
<p>1) Dans Flash Builder, créer un nouveau &laquo;&nbsp;<strong>ActionScript Project</strong>&nbsp;&raquo; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_10.png"><img class="alignnone size-full wp-image-6682" title="starling_tuto_10" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_10.png" alt="" width="636" height="133" /></a></p>
<p>2) Choisir le SDK &laquo;&nbsp;<strong>AIR 3.0</strong>&nbsp;&raquo; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_11.png"><img class="alignnone size-full wp-image-6683" title="starling_tuto_11" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_11.png" alt="" width="515" height="547" /></a></p>
<p>3) Dans le panneau suivant, cliquer sur &laquo;&nbsp;<strong>Add Project</strong>&nbsp;&raquo; pour ajouter la StarlingLib à votre projet (<strong>Note</strong> : <em>le projet StarlingLib doit être ouvert</em>) :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_12.png"><img class="alignnone size-full wp-image-6684" title="starling_tuto_12" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_12.png" alt="" width="530" height="313" /></a></p>
<p>4) Une fois le projet créé, faire un <strong>clic droit sur le projet &gt; &laquo;&nbsp;Properties&nbsp;&raquo;</strong>, puis sélectionner &laquo;&nbsp;<strong>ActionScript Compiler</strong>&nbsp;&raquo; dans la colonne de gauche. Cibler le <strong>player 11.0.0</strong> et ajouter &laquo;&nbsp;<strong>-swf-version=13</strong>&nbsp;&raquo; dans les paramètres additionnels du compilateur :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_13.png"><img class="alignnone size-full wp-image-6685" title="starling_tuto_13" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_13.png" alt="" width="784" height="687" /></a></p>
<p>5) Dernière étape, <strong>il faut modifier le template HTML</strong> utilisé par Flash Builder. En effet le &laquo;&nbsp;<strong>wmode</strong>&nbsp;&raquo; utilisé par Stage3D est le mode &laquo;&nbsp;<strong>direct</strong>&laquo;&nbsp;. <strong>Si vous ne le modifiez pas, rien ne s&#8217;affichera dans le .swf !<br />
</strong>Ouvrir le fichier &laquo;&nbsp;index.template.html&nbsp;&raquo; dans l&#8217;éditeur de texte de Flash Builder :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_14.png"><img class="alignnone size-full wp-image-6686" title="starling_tuto_14" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_14.png" alt="" width="671" height="403" /></a></p>
<p>6) Il faut ajouter à ce template le<strong> wmode=direct</strong> à plusieurs endroits :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_15.png"><img class="alignnone size-full wp-image-6687" style="border-width: 1px; border-color: black; border-style: solid;" title="starling_tuto_15" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_15.png" alt="" width="736" height="382" /></a></p>
<p>et là aussi :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_16.png"><img class="alignnone size-full wp-image-6688" style="border-width: 1px; border-color: black; border-style: solid;" title="starling_tuto_16" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_16.png" alt="" width="468" height="483" /></a></p>
<p><strong>Félicitations ! Vous voilà prêt à faire votre premier projet en Starling.</strong></p>
<h1>Codons un peu&#8230;</h1>
<p>Pour fonctionner, un projet Starling doit contenir une classe qui hérite de &laquo;&nbsp;<strong>starling.display.Sprite</strong>&nbsp;&raquo; qui sera le root de notre application Starling. En effet, Starling n&#8217;utilise pas la display list de Flash mais s&#8217;affiche via Stage3D qui est une autre couche de rendu du player Flash, indépendante de la display list &laquo;&nbsp;classique&nbsp;&raquo;.</p>
<p>Nous allons donc commencer par créer cette &laquo;&nbsp;<strong>classe du document Starling</strong>&nbsp;&raquo; :</p>
<p>1) Clic droit sur le dossier &laquo;&nbsp;<strong>src</strong>&nbsp;&raquo; du projet, puis &laquo;&nbsp;<strong>New &gt; ActionScript Class</strong>&nbsp;&raquo;</p>
<p>2) Indiquez un package (j&#8217;ai mis &laquo;&nbsp;classes&nbsp;&raquo;), nommez votre classe &laquo;&nbsp;<strong>StarlingMain</strong>&nbsp;&raquo; et faites-là hériter de &laquo;&nbsp;<span style="text-decoration: underline;"><strong>starling.display.Sprite</strong></span>&nbsp;&raquo; (et non de &laquo;&nbsp;flash.display.Sprite&nbsp;&raquo;) :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_17.png"><img class="alignnone size-full wp-image-6693" title="starling_tuto_17" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_17.png" alt="" width="525" height="617" /></a></p>
<p>3) Créer un dossier &laquo;&nbsp;<strong>assets</strong>&nbsp;&raquo; dans votre projet HelloStarling et y placer un .jpg de votre choix en le nommant &laquo;&nbsp;<strong>starling.jpg</strong>&nbsp;&raquo; : cette image sera incluse via un <a title="Embed" href="http://www.flashxpress.net/ressources-flash/embarquer-des-assets-externes-avec-embed/" target="_blank">embed</a> et utilisée <strong>comme texture d&#8217;affichage</strong>.</p>
<p>4) Puis taper le code suivant :</p>
<p><strong>Note</strong> : <em><span style="text-decoration: underline;">faites bien attention aux import des classes</span>. En effet, Starling utilise les mêmes noms de classes que les DisplayObjects Flash, il peut donc y avoir des conflits entre les deux. Toutes les classes du framework commence par le package &laquo;&nbsp;starling&nbsp;&raquo;.</em></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('p6643code5'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66435"><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
</pre></td><td class="code" id="p6643code5"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> classes
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> starling<span style="color: #000066; font-weight: bold;">.</span>display<span style="color: #000066; font-weight: bold;">.</span>Image<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> starling<span style="color: #000066; font-weight: bold;">.</span>display<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> starling<span style="color: #000066; font-weight: bold;">.</span>events<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> starling<span style="color: #000066; font-weight: bold;">.</span>textures<span style="color: #000066; font-weight: bold;">.</span>Texture<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> StarlingMain <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: #009900; font-style: italic;">// embed avec le chemin d'accès à notre .jpg contenu dans le dossier assets</span>
		<span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;../assets/starling.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static const myBitmap<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</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> StarlingMain<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</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=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;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>event<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: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</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>
&nbsp;
			<span style="color: #009900; font-style: italic;">// création d'une Texture à partir du bitmap embedé</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> texture<span style="color: #000066; font-weight: bold;">:</span>Texture = Texture<span style="color: #000066; font-weight: bold;">.</span>fromBitmap <span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> myBitmap<span style="color: #000000;">&#40;</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;">// création d'une instance d'Image avec notre texture</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> image<span style="color: #000066; font-weight: bold;">:</span>Image = <span style="color: #0033ff; font-weight: bold;">new</span> Image<span style="color: #000000;">&#40;</span>texture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// affichage de l'image</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>image<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>5) Dans la classe <strong>HelloStarling</strong> (classe du document) de votre projet, tapez le code suivant :</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('p6643code6'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66436"><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
</pre></td><td class="code" id="p6643code6"><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> classes<span style="color: #000066; font-weight: bold;">.</span>StarlingMain<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<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.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=stagealign%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:stagealign.html"><span style="color: #004993;">StageAlign</span></a><span style="color: #000066; font-weight: bold;">;</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=stagescalemode%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:stagescalemode.html"><span style="color: #004993;">StageScaleMode</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> starling<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Starling<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;60&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;#DDDDDD&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;960&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;660&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> HelloStarling <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>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> myStarling<span style="color: #000066; font-weight: bold;">:</span>Starling<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> HelloStarling<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <a href="http://www.google.com/search?q=stagealign%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:stagealign.html"><span style="color: #004993;">StageAlign</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TOP_LEFT</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleMode</span> = <a href="http://www.google.com/search?q=stagescalemode%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:stagescalemode.html"><span style="color: #004993;">StageScaleMode</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NO_SCALE</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// création d'une instance de Starling</span>
			myStarling = <span style="color: #0033ff; font-weight: bold;">new</span> Starling<span style="color: #000000;">&#40;</span>StarlingMain<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// réglage de l'antialiasing (valeur haute = meilleure qualité, mais performances moindres)</span>
			myStarling<span style="color: #000066; font-weight: bold;">.</span>antiAliasing = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// démarrage</span>
			myStarling<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><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>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>7) Compiler votre projet&#8230; et voilà le résultat :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_18-e1319108538125.png"><img class="alignnone size-full wp-image-6694" title="starling_tuto_18" src="http://www.flashxpress.net/wp-content/uploads/2011/10/starling_tuto_18-e1319108538125.png" alt="" width="630" height="453" /></a></p>
<p>Bravo ! Votre premier projet Starling fonctionne.</p>
<p><strong>Rien de très impressionnant pour le moment, mais nous verrons dans de prochains tutoriels comment donner un peu vie à tout ça.</strong></p>
<p>Merci pour votre patience et à bientôt pour la suite <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://twitter.com/#!/nicolasgans" target="_blank">Nicolas Gans</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/introduction-au-starling-framework/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>E-seminaire &#171;&#160;Développement de jeu avec AIR mobile&#160;&#187; chez Adobe le 4 octobre</title>
		<link>http://www.flashxpress.net/ressources-flash/e-seminaire-developpement-de-jeu-avec-air-mobile-chez-adobe-le-4-octobre/</link>
		<comments>http://www.flashxpress.net/ressources-flash/e-seminaire-developpement-de-jeu-avec-air-mobile-chez-adobe-le-4-octobre/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 14:40:10 +0000</pubDate>
		<dc:creator>Nicolas Gans</dc:creator>
				<category><![CDATA[Evénements]]></category>
		<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Flash mobile]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=6565</guid>
		<description><![CDATA[Le 4 octobre prochain de 14h à 15h, Nicolas Gans &#8211; formateur Flash chez Regart.net &#8211; sera chez Adobe France pour animer un e-seminaire sur le thème &#171;&#160;Développement de jeu avec AIR mobile&#160;&#187;. Lors de cet atelier online, il abordera la création d&#8217;un casse-brique en AIR mobile avec Flash CS5.5 et Flash Builder, depuis la [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/09/illus_focus_eseminar.png"><img class="alignnone size-full wp-image-6568" title="illus_focus_eseminar" src="http://www.flashxpress.net/wp-content/uploads/2011/09/illus_focus_eseminar.png" alt="" width="630" height="225" /></a></p>
<p><strong>Le 4 octobre prochain de 14h à 15h</strong>, Nicolas Gans &#8211; formateur Flash chez <a title="Centre de formation agréé Adobe" href="http://www.regart.net" target="_blank">Regart.net</a> &#8211; sera chez Adobe France pour animer un e-seminaire sur le thème &laquo;&nbsp;Développement de jeu avec AIR mobile&nbsp;&raquo;.</p>
<p>Lors de cet atelier online, il abordera la création d&#8217;un casse-brique en AIR mobile avec Flash CS5.5 et Flash Builder, depuis la création des assets graphiques jusqu&#8217;au code et la compilation pour les différentes plate-formes (iOS, Android&#8230;).</p>
<p>Au programme :<br />
- le concept de multi-screen et ses conséquences pour le développement d&#8217;applications mobiles<br />
- préparation des éléments graphiques dans Flash CS5.5<br />
- optimisation des éléments graphiques pour le mobile<br />
- choix du mode de rendu : CPU ou GPU<br />
- configuration de la compilation pour iOS et Android : certificats, provisioning profiles&#8230;<br />
- gestion des différentes tailles d&#8217;écran<br />
- liaison avec Flash Builder<br />
- mise en cache des éléments graphiques<br />
- partial et full blitting<br />
- object pooling</p>
<p>Le e-seminar nécessite une inscription en ligne, cliquez sur ce lien :<br />
<a href="http://www.adobe-events-france.com/event/creation-dapplications-mobile-flash-avec-flash-pro-et-flash-builder/" target="_blank">http://www.adobe-events-france.com/event/creation-dapplications-mobile-flash-avec-flash-pro-et-flash-builder/</a></p>
<p><span style="text-decoration: underline;"><strong>Edit du 4 octobre 2011 :</strong></span><br />
<strong><a href="http://www.flashxpress.net/wp-content/uploads/2011/10/eseminaire_regart_adobe_04_10_2011.zip">&gt;&gt; Télécharger les fichiers du e-séminaire</a></strong></p>
<p><strong>Notes :</strong><br />
- pour compiler le casse brique, il faudra importer le projet &laquo;&nbsp;Casse brique&nbsp;&raquo; dans Flash Builder 4.5<br />
- il vous faudra aussi créer vos certificats .p12 et provisioning profiles si vous souhaitez compiler le projet</p>
<div id="__ss_9542663" style="width: 595px;">
<p><strong style="display: block; margin: 12px 0 4px;"><a title="e-séminaire Regart.net / Adobe : &quot;Création d'un jeu AIR mobile&quot;" href="http://www.slideshare.net/maru.maru/esminaire-regartnet-adobe-cration-dun-jeu-air-mobile-p" target="_blank">e-séminaire Regart.net / Adobe : &laquo;&nbsp;Création d&#8217;un jeu AIR mobile&nbsp;&raquo;</a></strong> <object id="__sse9542663" width="595" height="497" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=eseminaireregartadobe04102011-111004092528-phpapp01&amp;stripped_title=esminaire-regartnet-adobe-cration-dun-jeu-air-mobile-p&amp;userName=maru.maru" /><param name="allowscriptaccess" value="always" /><param name="allowfullscreen" value="true" /><embed id="__sse9542663" width="595" height="497" type="application/x-shockwave-flash" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=eseminaireregartadobe04102011-111004092528-phpapp01&amp;stripped_title=esminaire-regartnet-adobe-cration-dun-jeu-air-mobile-p&amp;userName=maru.maru" allowFullScreen="true" allowScriptAccess="always" allowscriptaccess="always" allowfullscreen="true" /> </object></p>
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/maru.maru" target="_blank">maru.maru</a></div>
</div>
<p>A très bientôt !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/e-seminaire-developpement-de-jeu-avec-air-mobile-chez-adobe-le-4-octobre/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Dopez votre frameRate avec les classes AnimatedBitmap et AnimatedBitmapData</title>
		<link>http://www.flashxpress.net/ressources-flash/dopez-votre-framerate-avec-les-classes-animatedbitmap-et-animatedbitmapdata/</link>
		<comments>http://www.flashxpress.net/ressources-flash/dopez-votre-framerate-avec-les-classes-animatedbitmap-et-animatedbitmapdata/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 13:02:07 +0000</pubDate>
		<dc:creator>Nicolas Gans</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Flash mobile]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Optimisation]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=6246</guid>
		<description><![CDATA[C'est un fait avéré que l'animation de clips vectoriels peut être coûteuse en CPU et en mémoire. Ce phénomène s'accentue d'autant plus lors de développements sur mobile où le processeur et la mémoire vive sont extrêmement limités par rapport à des machines de bureau.]]></description>
			<content:encoded><![CDATA[<p>C&#8217;est un fait avéré que l&#8217;animation de clips vectoriels peut être coûteuse en CPU et en mémoire. Ce phénomène s&#8217;accentue d&#8217;autant plus lors de développements sur mobile où le processeur et la mémoire vive sont extrêmement limités par rapport à des machines de bureau.</p>
<p>Pour optimiser les animations et augmenter le frame rate de nos .swf, il existe des techniques de mise en cache natives des éléments vectoriels (cacheAsBitmap, cacheAsBitmapMatrix&#8230;) ou &laquo;&nbsp;manuelles&nbsp;&raquo; (méthode draw() de la classe BitmapData) qui sont efficaces. Le principe est toujours le même : il s&#8217;agit de faire un rendu bitmap (une rasterisation) à l&#8217;exécution, autrement dit de générer un png transparent à partir des données vectorielles, plus lourd en mémoire, mais beaucoup plus rapide à animer en terme de CPU.</p>
<p>J&#8217;ai dressé un panorama de ces techniques de mise en cache et des gains associés lors de ma <a title="Mise en cache des assets vectoriels pour AIR mobile" href="http://www.flashxpress.net/ressources-flash/mise-en-cache-des-assets-vectoriels-pour-air-mobile/">mini-conf des lightning talks</a>. Toutefois, lorsque l&#8217;on souhaite mettre en cache des éléments animés de type MovieClip, ces techniques sont totalement inefficaces &#8211; voire contre-performantes.</p>
<p>C&#8217;est pourquoi je vous livre ici deux classes, <strong>AnimatedBitmap </strong>et <strong>AnimatedBitmapData </strong>qui permettent de mettre en cache à l&#8217;exécution les movie clips animés <strong>pour un gain de performance spectaculaire</strong>.</p>
<p>Un petit benchmark pour commencer, décochez &laquo;&nbsp;use Cache&nbsp;&raquo; pour passer à la version vectorielle (beaucoup plus lente).</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_RetD_AnimatedBitmap_bench_230183456"
			class="flashmovie"
			width="630"
			height="400">
	<param name="movie" value="http://www.flashxpress.net/wp-content/uploads/2011/03/RetD_AnimatedBitmap_bench.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashxpress.net/wp-content/uploads/2011/03/RetD_AnimatedBitmap_bench.swf"
			name="fm_RetD_AnimatedBitmap_bench_230183456"
			width="630"
			height="400">
	<!--<![endif]-->
		<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></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Sur ma machine, je peux créer 2000 chiens animés et le <strong>frame rate reste à 30 ips</strong>. En mode vectoriel (use cache décoché), au-dessus de 100 chiens, le frame rate commence à diminuer.</p>
<h2>Classes AnimatedBitmap et AnimatedBitmapData</h2>
<p>Ces deux classes s&#8217;utilisent à la manière des classes <strong>Bitmap </strong>et <strong>BitmapData </strong>: une classe contient les data (AnimatedBitmapData) et l&#8217;autre gère l&#8217;affichage des data (AnimatedBitmap). De cette manière, on peut ré-utiliser les mêmes data pour x objets animés sans les dupliquer, d&#8217;où un gain de mémoire et de temps de rendu.</p>
<h2>AnimatedBitmapData</h2>
<p>La première chose à faire, avant tout rendu, c&#8217;est d&#8217;initialiser la classe en appelant dessus la méthode statique init() au moins une fois. La classe a en effet besoin d&#8217;une référence au Stage pour fonctionner.</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('p6246code7'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62467"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p6246code7"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Initialisation de la classe</span>
AnimatedBitmapData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">// le clip à mettre en cache</span>
<span style="color: #6699cc; font-weight: bold;">var</span> dog<span style="color: #000066; font-weight: bold;">:</span>Dog = <span style="color: #0033ff; font-weight: bold;">new</span> Dog<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">// création des data</span>
<span style="color: #6699cc; font-weight: bold;">var</span> abd<span style="color: #000066; font-weight: bold;">:</span>AnimatedBitmapData = <span style="color: #0033ff; font-weight: bold;">new</span> AnimatedBitmapData<span style="color: #000000;">&#40;</span>dog<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>En interne, la classe va parcourir la time line du clip et faire un draw() sur chaque frame, puis stocker les bitmapData obtenus dans un Vector.</p>
<p>Quelques infos sur le fonctionnement de cette classe :</p>
<ul>
<li> Si le clip a des couleurs modifiées (teinte, alpha&#8230;), mais que vous ne souhaitez pas les conserver, il faudra passer le second param &laquo;&nbsp;preserveColor&nbsp;&raquo; du constructeur à false.</li>
<li>Dans certains cas, notamment avec des filtres flous, <strong>les images du rendu peuvent être coupées sur les bords</strong>.  Cela est dû aux méthodes getBounds() et generateFilterRect() de Flash  qui renvoient parfois des valeurs imprécises. Si cela arrive, vous  pouvez passer en 3e param du constructeur une marge en pixel qui  agrandira la zone de rendu.</li>
<li>Enfin, si votre clip possède des étiquettes (frameLabels) elles seront conservées et accessibles.</li>
<li>Les transformations &laquo;&nbsp;matricielles&nbsp;&raquo; du clips sont supportées (rotation, scale&#8230;), ainsi que les filtres.</li>
</ul>
<p>Lorsque vous souhaitez détruire l&#8217;instance, appelez dessus la méthode destroy(), qui libèrera automatiquement la mémoire occupée via la méthode dispose() de la classe BitmapData.</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('p6246code8'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62468"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p6246code8"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// destruction des data et libération de la mémoire</span>
abd<span style="color: #000066; font-weight: bold;">.</span>destroy<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>

<h2>AnimatedBitmap</h2>
<p>C&#8217;est la classe d&#8217;affichage, qui a besoin d&#8217;un AnimatedBitmapData pour fonctionner.</p>
<p>On l&#8217;instancie de la façon suivante.</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('p6246code9'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62469"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p6246code9"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// instanciation : on passe en 1er param un AnimatedBitmapData</span>
<span style="color: #6699cc; font-weight: bold;">var</span> ab<span style="color: #000066; font-weight: bold;">:</span>AnimatedBitmap = <span style="color: #0033ff; font-weight: bold;">new</span> AnimatedBitmap<span style="color: #000000;">&#40;</span>abd<span style="color: #000066; font-weight: bold;">,</span> AnimatedBitmap<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">// affichage</span>
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>ab<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Les params du constructeurs sont les suivants :</p>
<ul>
<li>source:AnimatedBitmapData &gt; une instance d&#8217;AnimatedBitmapData</li>
<li> ticker:String &gt; le type &laquo;&nbsp;d&#8217;horloge&nbsp;&raquo; utilisé pour animer l&#8217;instance. Vous avez le choix entre<strong> &laquo;&nbsp;timer&nbsp;&raquo;, &laquo;&nbsp;enterFrame&nbsp;&raquo; et &laquo;&nbsp;external&nbsp;&raquo;</strong>. Vous pouvez utiliser les constantes statiques de la classe pour renseigner ce param : AnimatedBitmap.TIMER, AnimatedBitmap.ENTER_FRAME ou AnimatedBitmap.EXTERNAL.</li>
<li>frameRate:uint &gt; la cadence d&#8217;animation de votre objet. <strong>Comme elle n&#8217;est pas liée au frameRate de votre swf, elle peut être différente de celui-ci (plus lente ou plus rapide).</strong></li>
<li>updateAfterEvent:Boolean &gt; passez true si vous utilisez un ticker de type &laquo;&nbsp;timer&nbsp;&raquo; et que la cadence de l&#8217;objet est plus rapide que celle du document. Cela forcera le rendu du player à chaque nouvelle image pour plus de fluidité (et plus de process).</li>
<li>pixelSnapping:Boolean &gt; pour que les coordonnées des bitmaps du cache soit ou non sur des pixels entiers.</li>
<li>smoothing:Boolean &gt; activation ou non du lissage, utile lorsque l&#8217;objet subit une rotation ou un scale.</li>
</ul>
<p>Quelques infos sur le type de ticker (2nd param) :</p>
<p><strong>AnimatedBitmap.TIMER (défaut)</strong> : une instance de Timer est utilisée. Pratique si l&#8217;on souhaite aller plus vite que le frame rate de l&#8217;animation, mais moins optimisé qu&#8217;un enterFrame.<br />
<strong>AnimatedBitmap.ENTER_FRAME</strong> : un enterFrame est utilisé. A choisir si votre objet animé doit avoir le même frameRate que votre animation.<br />
<strong>AnimatedBitmap.EXTERNAL</strong> : aucune horloge interne ne sera mise en place, ce sera à vous d&#8217;implémenter votre propre horloge externe et d&#8217;appeler la méthode update() sur vos AnimatedBitmap. C&#8217;est la méthode la plus optimisée (pas de multiplication des horloges), à choisir si vous avez beaucoup d&#8217;objets animés ou si vous faites du jeu.</p>
<p>Exemple pour le type &laquo;&nbsp;external&nbsp;&raquo; :</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('p6246code10'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p624610"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p6246code10"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">this</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=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;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>event<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: #6699cc; font-weight: bold;">var</span> lng<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> = dogs<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">numChildren</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> dog<span style="color: #000066; font-weight: bold;">:</span>AnimatedBitmap<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: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> lng<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>
        dog = dogs<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> AnimatedBitmap<span style="color: #000066; font-weight: bold;">;</span>
        dog<span style="color: #000066; font-weight: bold;">.</span>update<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>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h2>Méthodes et propriétés de la classe AnimatedBitmap</h2>
<p>J&#8217;ai repris l&#8217;API de la classe MovieClip, donc on retrouve toutes les méthodes et propriétés classiques d&#8217;un MC : totalFrames, currentFrame, currentLabel, currentFrameLabel, play(), stop(), gotoAndPlay(frame/label) &#8230;</p>
<p>Des méthodes spécifiques existent cependant :</p>
<ul>
<li><strong>playTo(frame/label)</strong> : la tête de lecture part de sa position actuelle et s&#8217;arrêtera à la frame/étiquette passée en paramètre.</li>
<li><strong>playFromTo(startFrame, endFrame)</strong> : joue la tête de lecture depuis une frame/étiquette de départ jusqu&#8217;à une frame/étiquette d&#8217;arrivée.</li>
<li><strong>replace(target:MovieClip)</strong> : une petite méthode qui permet de remplacer automatiquement un clip affiché par un AnimatedBitmap. Pratique pour faire du remplacement automatique.</li>
</ul>
<p>Des propriétés aussi :</p>
<ul>
<li><strong>frameRate:uint </strong>&gt; pour modifier à la volée le frameRate de votre instance.</li>
<li><strong>isPlaying:Boolean</strong> &gt; pour savoir si le clip est en cours de lecture ou non.</li>
</ul>
<p>Un petit aperçu :</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_RetD_AnimatedBitmap_913287359"
			class="flashmovie"
			width="630"
			height="400">
	<param name="movie" value="http://www.flashxpress.net/wp-content/uploads/2011/03/RetD_AnimatedBitmap.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashxpress.net/wp-content/uploads/2011/03/RetD_AnimatedBitmap.swf"
			name="fm_RetD_AnimatedBitmap_913287359"
			width="630"
			height="400">
	<!--<![endif]-->
		<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></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Pour l&#8217;exemple, voici le code du swf 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('p6246code11'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p624611"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p6246code11"><pre class="actionscript3" style="font-family:monospace;">AnimatedBitmapData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> dog<span style="color: #000066; font-weight: bold;">:</span>Dog = <span style="color: #0033ff; font-weight: bold;">new</span> Dog<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
dog<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleX</span> = dog<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleY</span> = <span style="color: #000000; font-weight:bold;">2.2</span><span style="color: #000066; font-weight: bold;">;</span>
dog<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">0.5</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span>
dog<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>dog<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> abd<span style="color: #000066; font-weight: bold;">:</span>AnimatedBitmapData = <span style="color: #0033ff; font-weight: bold;">new</span> AnimatedBitmapData<span style="color: #000000;">&#40;</span>dog<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> ab<span style="color: #000066; font-weight: bold;">:</span> = <span style="color: #0033ff; font-weight: bold;">new</span> AnimatedBitmap<span style="color: #000000;">&#40;</span>abd<span style="color: #000066; font-weight: bold;">,</span> AnimatedBitmap<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TIMER</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">frameRate</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>
ab<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">replace</span><span style="color: #000000;">&#40;</span>dog<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p><strong>Destruction des instances :</strong></p>
<p>La classe possède une méthode <strong>destroy()</strong>, qui supprime tous les écouteurs et retire l&#8217;instance de la display list.<br />
Par ailleurs, il existe une <strong>propriété statique destroyData:Boolean</strong>,  réglée par défaut sur false. Passée à true, elle met en place une  destruction automatique et générale des AnimatedBitmapData au moment de  la destruction d&#8217;un AnimatedBitmap ou lors de l&#8217;écrasement d&#8217;un  animatedBitmapData par un autre via la propriété du même nom.</p>
<h2>Conclusion</h2>
<p>Ces classes se montreront particulièrement utiles pour du dev AIR mobile. <strong>Lorsqu&#8217;elles sont couplées au mode GPU (renderMode) le frame rate bondit</strong> !<br />
Par contre les limites sont le temps de rendu et la mémoire occupée. Je vous renvoie aux slides de ma mini-conf pour cela. Je pense peut-être implémenter une classe SpriteSheet à coupler avec AnimatedBitmapData pour utiliser des sprite sheets et réduire le temps de rendu.</p>
<p>Faites-moi part de vos remarques, questions, et éventuels bugs.</p>
<p>La classe est documentée (en anglais) &gt; <a title="AnimatedBitmap doc" href="http://www.flashxpress.net/wp-content/animatedBitmap/doc/">accéder à la doc</a></p>
<p>Voici les sources : <a title="Télécharger les sources" href="http://www.flashxpress.net/wp-content/animatedBitmap/AnimatedBitmap_sources.zip">AnimatedBitmap_sources</a></p>
<p>Et merci à Thibault et son composant Banana Slice pour l&#8217;inspiration : <a href="http://www.bytearray.org/?p=117">http://www.bytearray.org/?p=117</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/dopez-votre-framerate-avec-les-classes-animatedbitmap-et-animatedbitmapdata/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>HD Video Accélérée avec la classe StageVideo du Player 10.2</title>
		<link>http://www.flashxpress.net/ressources-flash/hd-video-acceleree-avec-la-classe-stagevideo-du-player-10-2/</link>
		<comments>http://www.flashxpress.net/ressources-flash/hd-video-acceleree-avec-la-classe-stagevideo-du-player-10-2/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 09:33:10 +0000</pubDate>
		<dc:creator>alama</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Direct]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[GPU]]></category>
		<category><![CDATA[HD]]></category>
		<category><![CDATA[Player 10.2]]></category>
		<category><![CDATA[StageVideo]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=6167</guid>
		<description><![CDATA[A partir de la version <strong>10.2 du player Flash</strong>, Avec la possibilité de changer l'icône du mouseCursor, Adobe a introduit une couche supplémentaire permettant de lire de la vidéo de manière plus rapide et utilisant l'accélération matérielle des cartes graphique.

Cette couche se trouve au niveau de l'objet stage de votre animation, elle est directe et ne fait pas partie de la liste d'affichage à proprement parler, elle n'est pas un <code>DisplayObject</code>. En conséquence, elle ne bénéficie pas des méthodes et propriétés habituelles des <code>DisplayObjects</code>, elle ne gère pas non plus la couche alpha.]]></description>
			<content:encoded><![CDATA[<h3>La classe StageVideo</h3>
<p>A partir de la version <strong>10.2 du player Flash</strong>, avec la possibilité de changer l&#8217;icône du mouseCursor, Adobe a introduit une couche supplémentaire permettant de lire de la vidéo de manière plus rapide et utilisant l&#8217;accélération matérielle des cartes graphique.</p>
<p>Cette couche se trouve au niveau de l&#8217;objet stage de votre animation, elle est directe et ne fait pas partie de la liste d&#8217;affichage à proprement parler, elle n&#8217;est pas un <code>DisplayObject</code>. En conséquence, elle ne bénéficie pas des méthodes et propriétés habituelles des <code>DisplayObjects</code>, elle ne gère pas non plus la couche alpha.</p>
<p>Cette couche est une instance de la classe <code>StageVideo</code>, je dis une, mais en réalité, lors de l&#8217;initialisation de l&#8217;objet stage, une série d&#8217;objets stageVideos vont être créés allant de <strong>1</strong> à <strong>x</strong> suivant votre matériel, sur mon portable, j&#8217;ai <strong>16</strong> layers <code>stageVideo </code>disponibles. Ces layers sont référencés dans un <code>array</code> en tant que propriété de <code>stage</code>.</p>
<p>Cliquer sur la vidéo pour mettre en lecture / pause</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_stageVideo02_225832817"
			class="flashmovie"
			width="600"
			height="400">
	<param name="movie" value="http://www.covergraph.com/blog/flash/stage_video/stageVideo02.swf" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.covergraph.com/blog/flash/stage_video/stageVideo02.swf"
			name="fm_stageVideo02_225832817"
			width="600"
			height="400">
		<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></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<h3>Au banc d&#8217;essai</h3>
<p>Au départ, j&#8217;ai suivi le getting started rédigé par <a href="http://www.bytearray.org/" target="_blank">Thibault Imbert</a> sur le site d&#8217;Adobe:</p>
<p><a href="http://www.adobe.com/devnet/flashplayer/articles/stage_video.html">http://www.adobe.com/devnet/flashplayer/articles/stage_video.html</a></p>
<p>Sur mon portable, tout allait bien, mais sur une machine équipée d&#8217;une Matrox Parhélia 256 Tripple head, fini! Image noire! Elle pilote 3 écrans, mais ne possède pas de décodeur pour le <strong>H264 </strong>qui est la norme actuelle. Alors j&#8217;ai tout repris à partir de zéro.</p>
<p>Il est clair qu&#8217;il ne faut jamais implémenter un lecteur vidéo basé sur un stageVideo sans y ajouter une version normale de secours de type <code>DisplayObject </code>classique. Afin de s&#8217;assurer que l&#8217;objet stagevideo peut réellement prendre en charge la vidéo, il faut passer par 2 tests.</p>
<p>Il faut tester si un ou plusieurs objets stageVideos ont été créés par le player Flash, grâce à un <strong>Event  StageVideoAvailability</strong> généré par le stage au moment de l&#8217;initiation de l&#8217;anim. Si ce test est ok, il faut encore tester le type de décodage sur l&#8217;event <strong>RenderState </strong>généré par l&#8217;objet video, c&#8217;est à dire par l&#8217;objet qui affiche la vidéo (<strong>stageVideo </strong>ou <strong>video</strong>), car le player peut reconnaître un decodeur matériel et instancier des stageVideos tout en affichant une image noire. Si un des test retourne « <strong>unavailable </strong>», il faut switcher sur une version classique sofware.</p>
<p>Il est à noter que l&#8217;objet stageVideo s&#8217;affiche dans un <strong>viewport </strong>(comme en 3D) et non dans un displayObject classique, donc, les réglages de taille et de coordonées x,y ne se font pas de la même façon. Le viewport se règle sur base d&#8217;un objet <code>Rectangle</code>. L&#8217;Event <strong>renderState </strong>n&#8217;émane pas du même target.</p>
<p>L&#8217;intégration HTML doit se faire en <strong>wmode=&nbsp;&raquo;direct&nbsp;&raquo;</strong> ou éventuellement &laquo;&nbsp;gpu&nbsp;&raquo; si vous n&#8217;avez pas de vectoriel à traiter dans l&#8217;application.</p>
<h3>Le code AS3</h3>
<p>Voici le code de base permettant d&#8217;utiliser le stageVideo en intégrant une prise en charge par un objet vidéo classique comme solution de secours.</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('p6167code12'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p616712"><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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
</pre></td><td class="code" id="p6167code12"><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>StageVideoAvailabilityEvent<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>StageVideoEvent<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>VideoEvent<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=rectangle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:rectangle.html"><span style="color: #004993;">Rectangle</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>StageVideo<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=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</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=netconnection%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netconnection.html"><span style="color: #004993;">NetConnection</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=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</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: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;1&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;#000000&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</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> static const FILE_NAME<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;file.f4v&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> nc<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netconnection%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netconnection.html"><span style="color: #004993;">NetConnection</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> ns<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</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> rc<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=rectangle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:rectangle.html"><span style="color: #004993;">Rectangle</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> video<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</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> stageVideo<span style="color: #000066; font-weight: bold;">:</span>StageVideo<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> ratioVideo<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</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> videoObject<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</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> renderType<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</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> txtOut<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: #3f5fbf;">/**
		 * Construct
		 *
		 */</span>
		<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: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// On attend que la classe document soit complètement instanciée et dans la displayList.</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> onAddedToStage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 *
		 * @param event
		 *
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onAddedToStage<span style="color: #000000;">&#40;</span>event<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;">// Connection</span>
			nc = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netconnection%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netconnection.html"><span style="color: #004993;">NetConnection</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			nc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			ns = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>nc<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// client pour la fonction onMetaData</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> customClient<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">;</span>
			customClient = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">;</span>
			customClient<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">onMetaData</span> = onMetaDataHandler<span style="color: #000066; font-weight: bold;">;</span>
			ns<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = customClient<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// on ecoute l'init des stageVideos sur le stage</span>
			<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>StageVideoAvailabilityEvent<span style="color: #000066; font-weight: bold;">.</span>STAGE_VIDEO_AVAILABILITY<span style="color: #000066; font-weight: bold;">,</span> stageVideoAvailabilityHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// text output</span>
			txtOut = <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>
			txtOut<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span> = 0xffffff<span style="color: #000066; font-weight: bold;">;</span>
			txtOut<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>txtOut<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> stageVideoAvailabilityHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>StageVideoAvailabilityEvent<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;">// (facultatif) On peut vérifier l'existance de 1 à x StageVideos maximum en testant le array</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Number of stageVideos: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span>stageVideos<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>
			<span style="color: #009900; font-style: italic;">// Nous n'avons plus besoin du listener</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span>StageVideoAvailabilityEvent<span style="color: #000066; font-weight: bold;">.</span>STAGE_VIDEO_AVAILABILITY<span style="color: #000066; font-weight: bold;">,</span> stageVideoAvailabilityHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// on teste si on a un objet stageVideo de dispo</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span>availability == <span style="color: #990000;">&quot;available&quot;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// si oui, on utilise le premier</span>
				stageVideo = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span>stageVideos<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #009900; font-style: italic;">// on lui colle le stream video</span>
				stageVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachNetStream</span><span style="color: #000000;">&#40;</span>ns<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #009900; font-style: italic;">// on ecoute l'etat du render qui sera déclenché au play()</span>
				stageVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>StageVideoEvent<span style="color: #000066; font-weight: bold;">.</span>RENDER_STATE<span style="color: #000066; font-weight: bold;">,</span> stageVideoRenderStateHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #009900; font-style: italic;">// on lance le play pour déclencher le renderState</span>
				ns<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span>FILE_NAME<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// Sinon, on utilise la méthode video normale (displayObject classique)</span>
				useDisplayObjectVideo<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>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">// Handler du renderState StageVideo</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> stageVideoRenderStateHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>StageVideoEvent<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;">// on vérifie si le décodage est bien réalisé ou pas</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">status</span> == <span style="color: #990000;">&quot;unavailable&quot;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// si pas de rendu, on libère les ressources</span>
				stageVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span>StageVideoEvent<span style="color: #000066; font-weight: bold;">.</span>RENDER_STATE<span style="color: #000066; font-weight: bold;">,</span> stageVideoRenderStateHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				stageVideo = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
				useDisplayObjectVideo<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>
			<span style="color: #0033ff; font-weight: bold;">else</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// sinon, on garde l'objet stageVideo comme lecteur</span>
				videoObject = <span style="color: #990000;">&quot;stageVideo&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
				renderType = e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">status</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">// video normale (DisplayObject)</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> useDisplayObjectVideo<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>
			video = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">smoothing</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
			video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachNetStream</span><span style="color: #000000;">&#40;</span>ns<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">;</span>
			video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>VideoEvent<span style="color: #000066; font-weight: bold;">.</span>RENDER_STATE<span style="color: #000066; font-weight: bold;">,</span> videoRenderStateHandler<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>video<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			ns<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span>FILE_NAME<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">//Handler du renderState video classique</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> videoRenderStateHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>VideoEvent<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>
			videoObject = <span style="color: #990000;">&quot;displayObjectVideo&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			renderType = e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">status</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> onMetaDataHandler<span style="color: #000000;">&#40;</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</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;metadata: duration=&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>duration <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; width=&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; height=&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; framerate=&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>framerate<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// on prend le rapport d'image</span>
			ratioVideo = <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// le cadrage video ne se fait pas de la même manière, stageVideo est un viewPort et non un displayObject.</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>videoObject == <span style="color: #990000;">&quot;stageVideo&quot;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> posY<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: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">*</span> ratioVideo<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
				stageVideo<span style="color: #000066; font-weight: bold;">.</span>viewPort = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=rectangle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:rectangle.html"><span style="color: #004993;">Rectangle</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> posY<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">*</span> ratioVideo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				txtOut<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Render Type: [StageVideo] - Decoder: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> renderType<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span>
			<span style="color: #000000;">&#123;</span>
				video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">*</span> ratioVideo<span style="color: #000066; font-weight: bold;">;</span>
				video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">-</span> video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
				txtOut<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Render Type: [DisplayObject] - Decoder: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> renderType<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>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/hd-video-acceleree-avec-la-classe-stagevideo-du-player-10-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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_1458104537"
			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_1458104537"
			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('p6184code13'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p618413"><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="p6184code13"><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>Mise en cache des assets vectoriels pour AIR mobile</title>
		<link>http://www.flashxpress.net/ressources-flash/mise-en-cache-des-assets-vectoriels-pour-air-mobile/</link>
		<comments>http://www.flashxpress.net/ressources-flash/mise-en-cache-des-assets-vectoriels-pour-air-mobile/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 16:15:28 +0000</pubDate>
		<dc:creator>Nicolas Gans</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Flash mobile]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Playbook]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=6201</guid>
		<description><![CDATA[Je vous mets en ligne mes slides de la mini-conf de 10 minutes que j'ai présenté lors de l'événement "Lightning talks" organisé par Adobe, les Tontons Flexeurs et Flashxpress le 24 mars 2011.

J'y ai présenté un aperçu des techniques et bonnes pratiques en matière de cache des éléments vectoriels d'un jeu ou d'une application AS3 pour AIR mobile. Toutes ces techniques permettent de faire grimper significativement le framerate de vos applications.]]></description>
			<content:encoded><![CDATA[<p>Je vous mets en ligne les slides de la mini-conf de 10 minutes que j&#8217;ai présenté lors de l&#8217;événement <a href="http://www.flashxpress.net/focus/evenement-a-paris-lightning-talks/" target="_self">&laquo;&nbsp;Lightning talks&nbsp;&raquo;</a> organisé par Adobe, les Tontons Flexeurs et Flashxpress le 24 mars 2011.</p>
<p>J&#8217;y ai présenté un aperçu des techniques et bonnes pratiques en matière de cache des éléments vectoriels pour un jeu ou une application AS3 pour AIR mobile. Toutes ces techniques permettent de faire grimper significativement le framerate de vos applications. Cliquez sur les slides, puis flèche droite/gauche du clavier pour se déplacer.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_slides_1388604879"
			class="flashmovie"
			width="630"
			height="400">
	<param name="movie" value="http://www.flashxpress.net/wp-content/uploads/2011/03/slides.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashxpress.net/wp-content/uploads/2011/03/slides.swf"
			name="fm_slides_1388604879"
			width="630"
			height="400">
	<!--<![endif]-->
		<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></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>En bonus, une petite vidéo des démos que j&#8217;ai présenté à cette soirée, pour vous donner une idée des performances si vous appliquez ces techniques.</p>
<p><div id="cache_air_mobile">
<video controls="controls" width="630" height="473">
<source src="http://ks358667.kimsufi.com/~video/webtv/iPhone/cache_air_mobile.mp4" type="video/mp4" />
</video>
</div>
<script type="text/javascript">
jwplayer("cache_air_mobile").setup({
flashplayer: "http://www.flashxpress.net/wp-content/uploads/jw-player-plugin-for-wordpress/player/player.swf",
file: "http://ks358667.kimsufi.com/~video/webtv/cache_air_mobile.f4v",
image: "http://ks358667.kimsufi.com/~video/webtv/posters/cache_air_mobile.f4v.jpg",
width: 630,
height: 473
});
</script>
<p>&nbsp;</p>
</p>
<p>Merci à tous ceux qui étaient présents, à bientôt pour une prochaine édition !</p>
<p><span style="text-decoration: underline;"><strong>MAJ 28 mars</strong></span><br />
Voici les sources de ces démos, ce sont des &laquo;&nbsp;ActionScript mobile projects&nbsp;&raquo; faits dans Flash Builder Burrito. <a title="Flash Builder Burrito" href="http://labs.adobe.com/technologies/flashbuilder_burrito/" target="_blank">Il faut télécharger et installer Burrito</a> (preview de Flash Builder 4.5) pour les importer.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2011/03/exemples_lightning_talks.zip">Télécharger les sources</a></p>
<p>Je n&#8217;ai pas inclus l&#8217;exemple qui utilise mes classes AnimatedBitmapData et AnimatedBitmap. Je dois cleaner un peu le code avant de les poster. Stay tuned !!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/mise-en-cache-des-assets-vectoriels-pour-air-mobile/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Créer une appli Android avec Flash Builder 4</title>
		<link>http://www.flashxpress.net/ressources-flash/creer-une-appli-android-avec-flash-builder-4/</link>
		<comments>http://www.flashxpress.net/ressources-flash/creer-une-appli-android-avec-flash-builder-4/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 15:22:40 +0000</pubDate>
		<dc:creator>Nicolas Gans</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[Tutoriels Flex]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Builder]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=5361</guid>
		<description><![CDATA[Avec la sortie de AIR 2.5, il est maintenant possible de développer avec Flash ou Flash Builder 4 des appli AIR s&#8217;exécutant sous Android 2.2 (Froyo). Très bonne nouvelle donc, mais passer de l&#8217;intention à la pratique n&#8217;est pas de tout repos. Avec un peu de patience et ce tutoriel, vous devriez y parvenir ! [...]]]></description>
			<content:encoded><![CDATA[<p id="internal-source-marker_0.7492338532393342"><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/illust_tuto_AIR_2.5.jpg"><img class="alignnone size-full wp-image-5414" title="illust_tuto_AIR_2.5" src="http://www.flashxpress.net/wp-content/uploads/2010/11/illust_tuto_AIR_2.5.jpg" alt="" width="630" height="200" /></a></p>
<p>Avec la sortie de AIR 2.5, il est maintenant possible de développer avec Flash ou Flash Builder 4 des appli AIR s&#8217;exécutant sous Android 2.2 (Froyo).</p>
<p>Très bonne nouvelle donc, mais passer de l&#8217;intention à la pratique n&#8217;est pas de tout repos. Avec un peu de patience et ce tutoriel, vous devriez y parvenir !</p>
<p>Nous allons donc voir ensemble comment créer une appli AIR pour Android à l&#8217;aide Flash Builder 4.</p>
<h2>Installation de AIR 2.5 pour Flash Builder 4</h2>
<p>Tout d’abord il faut télécharger le SDK de AIR 2.5 à cette URL<br />
<a href="http://www.adobe.com/products/air/sdk/">http://www.adobe.com/products/air/sdk/</a></p>
<p>Si Flash Builder 4 est ouvert, le fermer.</p>
<p>Puis aller dans le répertoire de FB4 qui contient les SDK.<br />
Sur windows, il se trouve par défaut ici : <strong>C:\Program Files\Adobe\Adobe Flash Builder 4\sdks</strong></p>
<p>Dans ce répertoire se trouvent les différents SDKs installés :<br />
Vérifier que le 4.1.0 est bien installé (si ce SDK n&#8217;est pas installé, il faut le télécharger à cette URL <a title="Flex SDK 4.1" href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4" target="_blank">http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4</a>, et suivre la même procédure) :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_1.png"><img class="alignnone size-full wp-image-5382" title="012_install_AIR2.5_1" src="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_1.png" alt="" width="578" height="121" /></a></p>
<p>Créer une copie du répertoire 4.1.0 :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_2.png"><img class="alignnone size-full wp-image-5383" title="012_install_AIR2.5_2" src="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_2.png" alt="" width="512" height="118" /></a></p>
<p>Renommer la copie en &#8216;AIR2.5&#8242; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_3.png"><img class="alignnone size-full wp-image-5384" title="012_install_AIR2.5_3" src="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_3.png" alt="" width="513" height="110" /></a></p>
<p>Coller  le .zip du SDK téléchargé précédemment dans ce répertoire, et extraire  le .zip dans le répertoire en <strong>veillant bien à ce que les fichiers  extraits écrasent les fichiers existant portant le même nom (c’est  important)</strong> :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_4.png"><img class="alignnone size-full wp-image-5385" title="012_install_AIR2.5_4" src="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_4.png" alt="" width="245" height="363" /></a></p>
<p>Lancer FB et aller dans les préférences. Window &gt; preferences (Fenêtre &gt; préférences)<br />
Dans le moteur de recherche, taper “sdk”, puis sélectionner “Installed Flex SDKs”.<br />
Vous pouvez voir la liste des SDKs installés, les mêmes que dans le répertoire &#8216;sdks&#8217; vu précédemment. Cliquer sur le bouton &#8216;Add&#8230;&#8217; situé à droite de la liste :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_5.png"><img class="alignnone size-full wp-image-5386" title="012_install_AIR2.5_5" src="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_5.png" alt="" width="629" height="443" /></a></p>
<p>Dans la fenêtre ouverte,<br />
&#8216;Flex SDK location&#8217; : parcourir le disque dur et sélectionner le répertoire &#8216;AIR2.5&#8242; crée précédemment.<br />
&#8216;Flex SDK name&#8217; : taper &#8216;AIR2.5&#8242;<br />
Puis valider en cliquant sur &#8216;OK&#8217; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_6.png"><img class="alignnone size-full wp-image-5387" title="012_install_AIR2.5_6" src="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_6.png" alt="" width="514" height="195" /></a></p>
<p>En principe, le SDK doit dorénavant apparaître dans la liste des SDKs installés :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_7.png"><img class="alignnone size-full wp-image-5388" title="012_install_AIR2.5_7" src="http://www.flashxpress.net/wp-content/uploads/2010/11/012_install_AIR2.5_7.png" alt="" width="642" height="443" /></a></p>
<p>Nous pouvons maintenant créer notre premier projet Android dans Flash Builder 4.</p>
<h2>Créer un projet AIR 2.5 dans Flash Builder 4</h2>
<p><strong>Pour faire du AIR2.5 en ActionScript 3 pur (sans le framework Flex), il faut créer un projet &laquo;&nbsp;Flex Project&nbsp;&raquo;.</strong><br />
Il est en effet impossible de créer un projet AIR dans FB4 avec les projets &#8216;ActionScript&#8217; ou &#8216;Flash Professional&#8217;.</p>
<p><strong>Pour faire un projet Flex pour Android, il faudra attendre la sortie de Flex &laquo;&nbsp;Hero&nbsp;&raquo;.</strong></p>
<p>Aller dans le menu &#8216;File &gt; new &gt; Flex Project&#8217;.<br />
Donner un nom à votre projet, ici &#8216;PremiereAppli&#8217;<br />
Laisser l&#8217;emplacement par défaut ou choisir un autre emplacement.<br />
Sélectionner &#8216;Desktop&#8217;.<br />
Sélectionner le SDK &#8216;AIR2.5&#8242; crée précédemment.<br />
Puis cliquer sur &#8216;Next&#8217;, puis à nouveau sur &#8216;Next&#8217; pour arriver à la troisième étape.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/001_projet_AIR.png"><img class="alignnone size-full wp-image-5365" title="001_projet_AIR" src="http://www.flashxpress.net/wp-content/uploads/2010/11/001_projet_AIR.png" alt="" width="602" height="634" /></a></p>
<p>Dans le champ &#8216;Main application file&#8217; (la classe du document de votre projet), <strong>changer l&#8217;extension &#8216;.mxml&#8217; en &#8216;.as&#8217;.</strong><br />
Donner une ID unique à votre projet en ajoutant un namespace (com.votresite.VotreAppli) dans le champ du dessous.<br />
Puis cliquer sur &#8216;Finish&#8217; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/002_projet_AIR.png"><img class="alignnone size-full wp-image-5366" title="002_projet_AIR" src="http://www.flashxpress.net/wp-content/uploads/2010/11/002_projet_AIR.png" alt="" width="602" height="712" /></a></p>
<p id="internal-source-marker_0.7492338532393342">En principe, votre projet doit apparaître dans le &#8216;Package Explorer&#8217;.<br />
Dans le dossier &#8216;src&#8217; (les sources), vous devriez voir votre classe du document (<strong>PremiereAppli.as</strong>) ainsi qu&#8217;un fichier &#8216;<strong>PremierAppli-app.xml</strong>&#8216; : il s&#8217;agit du fichier <strong>Descriptor</strong>, qui va vous permettre de configurer l&#8217;apparence et le comportement de base de votre appli Android.</p>
<p><a href="../wp-content/uploads/2010/11/003_projet_AIR_package_explorer.png"><img title="003_projet_AIR_package_explorer" src="../wp-content/uploads/2010/11/003_projet_AIR_package_explorer.png" alt="" width="399" height="171" /></a></p>
<h2>Le fichier descriptor</h2>
<p>Le fichier &#8216;<strong>PremierAppli-app.xml</strong>&#8216; est un fichier &#8216;descriptor&#8217;. Ce fichier est généré automatiquement lors de la création d’un projet AIR dans FB. Il s&#8217;agit d&#8217;un template, qu&#8217;il va falloir modifier.<br />
Vous y trouverez une flopée de nœuds XML qui permettent de configurer  notre appli. La plupart sont commentés (&lt;!&#8211; &lt;noeud&gt; &#8211;&gt;) :<strong> il faudra décommenter les noeuds que vous souhaitez renseigner. </strong></p>
<p>Pour cibler AIR Android, <strong>il faudra obligatoirement renseigner certains noeuds</strong>.</p>
<p>Pour la liste complète des noeuds et leur description, c&#8217;est ici : <a href="http://j.mp/dB688N">http://j.mp/dB688N</a></p>
<p>Ouvrer le fichier descriptor du répertoire &#8216;src&#8217; dans FB ou avec un éditeur XML.</p>
<p><span style="text-decoration: underline;"><strong>A renseigner obligatoirement :</strong></span></p>
<p>- Le <strong>namespace </strong>: version de AIR ciblée. Si vous ne voyez pas ceci au début du fichier, il y a un soucis :</p>
<pre>&lt;application xmlns="http://ns.adobe.com/air/application/2.5"&gt;</pre>
<p>- Les &#8216;<strong>profiles</strong>&#8216; : un &#8216;profile&#8217; permet de cibler tel ou tel device (appli de bureau, appli mobile&#8230;) en activant ou désactivant certaines fonctionnalités de AIR en fonction de cette cible.  Pour la liste complète des &#8216;profiles&#8217; AIR 2.5 et leur description, voir ici : <a href="http://bit.ly/aOlHQ3">http://bit.ly/aOlHQ3</a>.<br />
<strong>Si vous utilisez l’accéleromètre ou la géolocalisation dans votre appli</strong>, il faudra renseigner le noeud &lt;supportedProfile&gt; (penser à décommenter !) :</p>
<pre>&lt;supportedProfiles&gt;mobileDevice&lt;/supportedProfiles&gt;</pre>
<p>- Décommenter le noeud <strong>&lt;visible&gt;</strong> et le passer à true :</p>
<pre>&lt;visible&gt;true&lt;/visible&gt;</pre>
<p><span style="text-decoration: underline;"><strong><br />
Optionnel : </strong></span><br />
les icones de l’appli (pour android, ne mettre que les suivantes)</p>
<pre>&lt;icon&gt;
&lt;image16x16&gt;icone_16x16.png&lt;/image16x16&gt;
&lt;image32x32&gt;icone_32x32.png&lt;/image32x32&gt;
&lt;image48x48&gt;icone_48x48.png&lt;/image48x48&gt;
&lt;image128x128&gt;icone_128x128.png&lt;/image128x128&gt;
&lt;/icon&gt;</pre>
<p>Pour Android, décommenter le noeud &lt;android&gt; qui va permettre de générer un manifest.xml dans l&#8217;appli :<br />
&lt;android&gt;<br />
&#8230;<br />
&lt;/android&gt;</p>
<h2>Le certificat</h2>
<p>Pour générer votre appli, il va vous falloir la signer avec un <strong>certificat</strong>, fichier au format .p12.</p>
<p>Si vous possédez déjà un tel fichier, vous pouvez l&#8217;utiliser, sinon il va falloir générer ce certificat. Flash Builder permet de le faire.</p>
<p>Cliquer sur l&#8217;icone &#8216;export release build&#8217; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/000_export_release.png"><img class="alignnone size-full wp-image-5410" title="000_export_release" src="http://www.flashxpress.net/wp-content/uploads/2010/11/000_export_release.png" alt="" width="304" height="82" /></a></p>
<p>Laisser tel quel et cliquez sur &#8216;next&#8217; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/004_projet_AIR_release.png"><img class="alignnone size-full wp-image-5368" title="004_projet_AIR_release" src="http://www.flashxpress.net/wp-content/uploads/2010/11/004_projet_AIR_release.png" alt="" width="657" height="550" /></a></p>
<p>Cliquer sur &#8216;Create&#8230;&#8217; pour créer un certificat :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/005_projet_AIR_certificat.png"><img class="alignnone size-full wp-image-5369" title="005_projet_AIR_certificat" src="http://www.flashxpress.net/wp-content/uploads/2010/11/005_projet_AIR_certificat.png" alt="" width="657" height="550" /></a></p>
<p>Renseigner le certificat en indiquant votre nom, celui de votre organisation, le pays et taper un mot de passe.<br />
Puis choisir l&#8217;emplacement de sauvegarde de votre certificat (&#8216;Save as&#8217;). Pour ma part, j&#8217;ai créé un dossier &#8216;release&#8217; dans mon projet Flex.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/006_projet_AIR_certificat_2.png"><img class="alignnone size-full wp-image-5370" title="006_projet_AIR_certificat_2" src="http://www.flashxpress.net/wp-content/uploads/2010/11/006_projet_AIR_certificat_2.png" alt="" width="488" height="434" /></a></p>
<p>Pour générer le certificat, cliquez sur &#8216;Finish&#8217; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/007_projet_AIR_certificat_3.png"><img class="alignnone size-full wp-image-5371" title="007_projet_AIR_certificat_3" src="http://www.flashxpress.net/wp-content/uploads/2010/11/007_projet_AIR_certificat_3.png" alt="" width="657" height="550" /></a></p>
<p><strong>Courage, nous y sommes bientôt !</strong></p>
<h2>Fichiers de release</h2>
<p>Dernière étape avant la génération de notre appli Android, vérifiez que vous avez en votre possession tous les fichiers requis. Pour ma part, j&#8217;ai crée un dossier &#8216;release&#8217; dans lequel j&#8217;ai placé tous ces fichiers :</p>
<p>Au minimum, il vous faut :</p>
<ul id="internal-source-marker_0.7492338532393342">
<li>MonAppli.swf &gt; l’appli</li>
<li>MonAppli-app.xml &gt; le fichier descriptor de l’appli .air</li>
<li>monCertif.p12 &gt; certificat</li>
</ul>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/008_projet_AIR_release.png"><img class="alignnone size-full wp-image-5372" title="008_projet_AIR_release" src="http://www.flashxpress.net/wp-content/uploads/2010/11/008_projet_AIR_release.png" alt="" width="391" height="282" /></a></p>
<p>Voilà vous êtes prêts !</p>
<h2>Création du fichier .apk</h2>
<p>Dernière étape, il va nous falloir packager notre appli AIR dans un <strong>fichier .apk</strong> (le format des appli Android), qui n&#8217;est autre qu&#8217;un fichier .zip contenant pleins de fichiers ainsi que les fichiers de votre appli.</p>
<p>Pour packager, plusieurs options se présentent :</p>
<ul>
<li>Option <strong>NERD </strong>: ligne de commande&#8230;<br />
Voir <a href="http://polygeek.com/2958_flex_creating-your-first-air-app-for-android-using-flash-builder">http://polygeek.com/2958_flex_creating-your-first-air-app-for-android-using-flash-builder</a></li>
</ul>
<ul>
<li>Option <strong>GEEK </strong>: tache Ant<br />
Voir <a href="http://unitedmindset.com/jonbcampos/2010/07/19/android-mobile-development/">http://unitedmindset.com/jonbcampos/2010/07/19/android-mobile-development/</a></li>
</ul>
<ul>
<li>Option <strong>NOOB </strong>: package assistant pro de Serge Jespers<br />
<a href="http://www.webkitchen.be/package-assistant-pro/">http://www.webkitchen.be/package-assistant-pro/</a></li>
</ul>
<p>Etant allergique à la ligne de commande et pas assez flexeux pour utiliser Ant, j&#8217;ai choisi l&#8217;option Noob, une petite appli AIR crée par Serge Jespers, qui vous package automatiquement votre .apk.</p>
<p><span style="text-decoration: underline;"><strong>Serge, I Love You !</strong></span></p>
<p>Après installation de package assistant pro, lancer l&#8217;appli.</p>
<p>Première étape, les préférences :</p>
<p><strong>Where is JAVA.exe ?</strong><br />
Trouver le l&#8217;emplacement du fichier java.exe sur votre HDD.<br />
Sur windows, il devrait se trouver ici : <strong>C:\Program Files\Java\jre6\bin\java.exe</strong></p>
<p><strong>Where is ADT.jar for AIR 2.5 ?</strong><br />
En principe, vous le trouvez ici :<strong> C:\Program Files\Adobe\Adobe Flash Builder 4\sdks\AIR2.5\lib\adt.jar</strong></p>
<p><strong>Where is your certificate ? </strong><br />
Indiquez l&#8217;emplacement du certificat .p12 généré précédemment (chez moi, il se trouve dans le dossier &#8216;release&#8217; de mon projet FB4).</p>
<p>Cliquez ensuite sur &#8216;Save&#8217; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/009_packager_1.png"><img class="alignnone size-full wp-image-5373" title="009_packager_1" src="http://www.flashxpress.net/wp-content/uploads/2010/11/009_packager_1.png" alt="" width="420" height="480" /></a></p>
<p>Choisir Package APK :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_2.png"><img class="alignnone size-full wp-image-5374" title="010_packager_2" src="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_2.png" alt="" width="420" height="480" /></a></p>
<p><strong>1ere étape :</strong><br />
Indiquer l&#8217;emplacement de votre fichier descriptor (&#8216;PremierAppli-app.xml&#8217;) :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_3.png"><img class="alignnone size-full wp-image-5375" title="010_packager_3" src="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_3.png" alt="" width="420" height="480" /></a></p>
<p><strong>2e étape :</strong><br />
Vérifier que le fichier SWF indiqué dans le champ est bien le bon. Sinon, sélectionnez le bon fichier :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_4.png"><img class="alignnone size-full wp-image-5376" title="010_packager_4" src="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_4.png" alt="" width="420" height="480" /></a></p>
<p><strong>3e étape :</strong><br />
Ajouter les éventuels fichiers additionnels de votre appli (assets, fichiers de config&#8230;) :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_5.png"><img class="alignnone size-full wp-image-5377" title="010_packager_5" src="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_5.png" alt="" width="420" height="480" /></a></p>
<p><strong>4e étape :</strong><br />
Indiquer le mot de passe de votre certificat :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_6.png"><img class="alignnone size-full wp-image-5378" title="010_packager_6" src="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_6.png" alt="" width="420" height="480" /></a></p>
<p><strong>5e étape :</strong><br />
Indiquer l&#8217;emplacement de sauvegarde et le nom de votre fichier .apk.<br />
Puis cliquer sur &#8216;<strong>COMPILE</strong>&#8216; :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_7.png"><img class="alignnone size-full wp-image-5379" title="010_packager_7" src="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_7.png" alt="" width="420" height="480" /></a></p>
<p>Roulements de tambour&#8230;&#8230;&#8230;<br />
ça passe !</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_8.png"><img class="alignnone size-full wp-image-5380" title="010_packager_8" src="http://www.flashxpress.net/wp-content/uploads/2010/11/010_packager_8.png" alt="" width="420" height="480" /></a></p>
<p>Vous retrouverez votre fichier .apk à l&#8217;emplacement indiqué :</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/11/011_creation_apk.png"><img class="alignnone size-full wp-image-5381" title="011_creation_apk" src="http://www.flashxpress.net/wp-content/uploads/2010/11/011_creation_apk.png" alt="" width="394" height="208" /></a></p>
<p>OUF ! On a échappé à la ligne de commande ! Encore merci M. Jespers !</p>
<h2>Conclusion</h2>
<p>Comme vous le voyez, le process de création d&#8217;un .apk n&#8217;est pas d&#8217;une grande simplicité pour le moment&#8230; Souhaitons qu&#8217;Adobe fournisse très vite des outils intégrés à Flash Builder qui simplifient un peu tout ça.</p>
<p><strong>Prochaine étape de ce tutoriel très bientôt : tester votre appli .apk sur votre device Android. </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/creer-une-appli-android-avec-flash-builder-4/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>SWF partagé et RSL en AS3 avec FlashDevelop</title>
		<link>http://www.flashxpress.net/ressources-flash/swf-partage-et-rsl-en-as3-avec-flashdevelop/</link>
		<comments>http://www.flashxpress.net/ressources-flash/swf-partage-et-rsl-en-as3-avec-flashdevelop/#comments</comments>
		<pubDate>Tue, 25 May 2010 15:37:22 +0000</pubDate>
		<dc:creator>alama</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Develop]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[swc]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=5168</guid>
		<description><![CDATA[Auteur: Alama alias Alain Mazy Date: 25/05/2010 Environnement: Flashdevelop Min Player cible: 9.0 Ce tutorial a pour but d’expliquer comment faire une application AS3  utilisant une Runtime Shared Library (RSL) compilée avec FlashDevelop et le Flex SDK. L&#8217;avantage d&#8217;une RSL est le partage d&#8217;une même ressource de classes pour plusieurs applications ou modules SWF. L&#8217;application [...]]]></description>
			<content:encoded><![CDATA[<p>Auteur: Alama alias Alain Mazy<br />
Date: 25/05/2010<br />
Environnement: Flashdevelop<br />
Min Player cible: 9.0</p>
<p>Ce tutorial a pour but d’expliquer comment faire une application AS3  utilisant une <strong>Runtime Shared Library</strong> (<strong>RSL</strong>) compilée avec FlashDevelop et le Flex SDK.</p>
<p>L&#8217;avantage d&#8217;une RSL est le partage d&#8217;une même ressource de classes pour plusieurs applications ou modules SWF. L&#8217;application s&#8217;en trouve plus légère étant donné que la ressource est chargée dynamiquement au RunTime. Très utile aussi pour externaliser des Skins dans un SWF externe afin de pouvoir le changer sans recompiler l&#8217;application, simplement en changeant le SWF RSL.</p>
<p>Il est important de distinguer qu&#8217;il s&#8217;agit de classes chargées dynamiquement, donc, instanciables à volonté, par rapport à  simplement charger un SWF avec la classe Loader, car dans ce cas, seuls, les objets (instances) sont accessibles. Le chargement de SWF par <code>[Embed]</code> permets l&#8217;intsanciation à volonté, mais sera compilé avec l&#8217;application, donc non chargés dynamiquement au runtime.</p>
<p>Nous verrons également une alternative un peu plus contraignante mais n&#8217;utilisant pas le framework Flex exploitant les propriétés de linkage export/import d&#8217;origines de Flash.</p>
<h3>Préparer un SWF RSL avec FlashDevelop ( SWC)</h3>
<p>Afin de pouvoir utiliser une RSL sous FlashDevelop, il faut 2 fichiers! un SWF qui contient les classes qui seront chargées au runTime et son Clone sous forme de SWC qui fournira les références de ces classes à FlashDevelop afin qu&#8217;elles existent au moment du codage. (obligatoire pour l&#8217;intelliscence et le compilateur).</p>
<p>Nous verrons que le SWC nous fournit tout ça, étant donné qu&#8217;un SWC n&#8217;est rien d&#8217;autre qu&#8217;une archive (zip, rar, ..) contenant le SWF et un XML de références.</p>
<p>Sous FD, créez un nouveau &laquo;&nbsp;AS3 Empty Project&nbsp;&raquo;. Créez vos nouvelles classes publiques AS3 à l&#8217;aide de la commande &laquo;&nbsp;Add&nbsp;&raquo; du menu contextuel de la fenêtre Project, dans le répertoire src.</p>
<p>Pour l&#8217;exemple, je crée 2 classes, une MyRectangle et une MyRound qui sont de simples objets graphiques.</p>
<p>Exemple pour la classe MyRectancle:</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('p5168code17'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p516817"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p5168code17"><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: #3f5fbf;">/**
    * ...
    * @author Alama
    */</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MyRectangle <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;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MyRectangle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</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>0xFF0000<span style="color: #000000;">&#41;</span><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;">0</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: #000000; font-weight:bold;">150</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><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: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Une fois les classes terminées, il faut compiler le projet en SWC. Celà peut être fait simplement à l&#8217;aide du plugin SWC pour FD que l&#8217;on peut trouver ici: <a href="http://sourceforge.net/projects/exportswc/">http://sourceforge.net/projects/exportswc/</a></p>
<p>On peut également le faire manuellement à l&#8217;aide du compilateur du flex SDK compc. voir les commande ici:<br />
<a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_22.html">http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_22.html</a></p>
<h3>Préparer un SWF RSL avec Flash CS (création d&#8217;un SWC)</h3>
<p>Dans un nouveau projet Flash, créez un symbole par élément (classe) qui sera désiré dans votre fichier partagé.</p>
<p>Le SWC que nous allons créer doit contenir toutes les classes des objets créés en bibliothèque. Donc, pour chaque symbole de la bibliothèque, il faut les e<strong>xporter pour ActionScript</strong>. Il n&#8217;est pas obligatoire de les avoir sur la scène, uniquement en bibliothèque est suffisant. <strong>Mettez une majuscule à vos noms de symboles</strong>, car ce seront des classes.</p>
<p><a rel="attachment wp-att-255" href="http://www.flashxpress.net/?attachment_id=255"><img class="aligncenter size-full wp-image-255" src="http://www.covergraph.com/blog/wp-content/uploads/2010/05/flash01.jpg" alt="flash01" width="425" height="549" /></a></p>
<p>Une fois tous les symboles créés, il suffit de publier votre projet Flash en cochant la case &laquo;&nbsp;<strong>Exporter SWC</strong>&nbsp;&raquo; de l&#8217;onglet Flash des Paramètres de publication.</p>
<p><a rel="attachment wp-att-307" href="http://www.flashxpress.net/?attachment_id=307"><img class="aligncenter size-full wp-image-307" src="http://www.covergraph.com/blog/wp-content/uploads/2010/05/flash04.jpg" alt="flash04" width="449" height="656" /></a></p>
<h3>Préparer et configurer FlashDevelop pour l&#8217;utilisation de Runtime Shared Libraries</h3>
<p>Sous FD, créez un nouveau projet AS3.  <strong>Une des caractéristiques des RSLs est qu&#8217;elles ne sont normalement pas utilisables en AS3 pure!</strong> Du moins, à l&#8217;heure où ces lignes sont écrites, on peut supposer qu&#8217;Adobe changera ça prochainement. Il s&#8217;agit d&#8217;une fonctionnalité qui est prise en charge par Flex.  On peut contourner le problème en étendant notre Classe document en &laquo;&nbsp;<code>SimpleApplication</code>&nbsp;&raquo; Flex.</p>
<p>Pour ce faire, il est nécessaire d&#8217;utiliser la classe <code>SimpleApplication</code> de Flex. Il faut donc installer le fichier framework.swc dans notre projet (il se trouve dans le répertoire lib du framework Flex SDK). Je le place dans le répertoire &laquo;&nbsp;lib&nbsp;&raquo; mais ce n&#8217;est pas une obligation.</p>
<p>Ensuite, à l&#8217;aide du clic droit, il faut l&#8217;ajouter à la librairie de FD (&laquo;&nbsp;Add To Library&nbsp;&raquo;), comme représenté sur cette image:</p>
<p><a rel="attachment wp-att-304" href="http://www.flashxpress.net/?attachment_id=304"><img class="aligncenter size-full wp-image-304" src="http://www.covergraph.com/blog/wp-content/uploads/2010/05/fd011.jpg" alt="fd011" width="413" height="541" /></a></p>
<p>Ensuite, nous avons besoin d&#8217;installer notre SWC créé précédemment de la même manière que nous avons installé le framework.swc. Mais nous avons également besoin d&#8217;installer le SWF correspondant au SWC dans le répertoire où s&#8217;éxécutera notre application (runtime), en l&#8217;occurrence ici, le répertoire &laquo;&nbsp;bin&nbsp;&raquo;.</p>
<p>Nous avons vu plus haut ce que contenait un SWC (SWF + XML). Donc, il faut ouvrir le SWC à l&#8217;aide d&#8217;un programme d&#8217;archives tel que WinRar. Extraire une copie du SWF (normalement appelé &laquo;&nbsp;library.swf&nbsp;&raquo;) et placer cette copie dans le répertoire &laquo;&nbsp;bin&nbsp;&raquo; de notre projet. En ouvrant l&#8217;arborescence de nos fichiers SWF et SWC de notre fenêtre Project, on voit qu&#8217;ils contiennent identiquement les mêmes classes.</p>
<p>Le SWC ne nous sert que de référence, il ne doit pas être compilé et inclus dans notre application finale, puisque les classes en questions seront chargée dynamiquement au runtime depuis le SWF RSL.</p>
<p>Pour éviter que ce SWC soit compilé, il faut l&#8217;exclure de la manière suivante : Clic droit &gt;  Options &gt; External Library.</p>
<p><a rel="attachment wp-att-261" href="http://www.flashxpress.net/?attachment_id=261"><img class="aligncenter size-full wp-image-261" src="http://www.covergraph.com/blog/wp-content/uploads/2010/05/fd02.jpg" alt="fd02" width="330" height="306" /></a></p>
<p>On a presque fini! il ne nous reste plus qu&#8217;a informer le compilateur du fichier RSL à utiliser au runtime, grâce à cela, il ne cherchera pas les classes manquantes puisqu&#8217;on lui dit qu&#8217;elles seront chargées au runtime.</p>
<p>Pour ce faire, dans le menu principal de FalshDevelop il faut aller dans: Project &gt; Properties &gt; Compiler Options.</p>
<p>Dans &laquo;&nbsp;Additional Compiler Options&nbsp;&raquo;, cliquez le bouton à l&#8217;extrême droite.</p>
<p><a rel="attachment wp-att-262" href="http://www.flashxpress.net/?attachment_id=262"><img class="aligncenter size-full wp-image-262" src="http://www.covergraph.com/blog/wp-content/uploads/2010/05/fd03.jpg" alt="fd03" width="372" height="438" /></a></p>
<p>Dans la nouvelle fenêtre, il faut lui donner le chemin du fichier RSL. La 2 ème ligne sert a contourner une erreur de Sandox.  Comme ceci:</p>
<blockquote><p>-rsl library.swf<br />
-use-network=false</p>
</blockquote>
<p>Voilà, notre système RSL est mis en place, nous sommes prêt à programmer notre application.</p>
<p>Rappel d&#8217;une chose ! La classe document doit absolument étendre <code>SimpleApplication</code>, donc elle aura ce look 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('p5168code18'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p516818"><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
</pre></td><td class="code" id="p5168code18"><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.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.system</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=security%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:security.html"><span style="color: #004993;">Security</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>SimpleApplication<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> SimpleApplication
	<span style="color: #000000;">&#123;</span>
		<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>
&nbsp;
			<span style="color: #009900; font-style: italic;">// entry point</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">rect</span><span style="color: #000066; font-weight: bold;">:</span>MyRectangle = <span style="color: #0033ff; font-weight: bold;">new</span> MyRectangle<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">rect</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">rect</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">rect</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">round</span><span style="color: #000066; font-weight: bold;">:</span>MyRound = <span style="color: #0033ff; font-weight: bold;">new</span> MyRound<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">round</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">round</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">70</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">round</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: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>L&#8217;implémentation d&#8217;un système RSL sous FlashDevelop est terminée. <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>.</p>
<p>.</p>
<h2>Solution Alternative sans Flex</h2>
<p>Une autre solution sans utiliser le framework Flex ni l&#8217;obligation d&#8217;étendre la Classe Document en <code>SimpleApplication </code>consiste à utilsier le système classique de Flash CS, c&#8217;est à dire, l&#8217;export/import liking et de l&#8217;utiliser dans FlashDevelop à l&#8217;aide de la balise <code>[Embed]</code>.</p>
<p><strong>!!! Cette solution est intéressante, mais est plus contraignante car il nous faudra un couple de SWFs par Classe !!!</strong></p>
<p>Pour cela, nous avons absolument besoin de Flash. Nous devons créer 2 FLAs! Un pour l&#8217;Export qui sera le vrai Shared Library, car il contiendra les classes. Et un autre, qui servira de référence au premier par linkage. On pourrait tout faire dans le même FLA, mais par clarté, on en fait 2. Donc, Créons 2 répertoires, un appelé &laquo;&nbsp;<strong>share</strong>&nbsp;&raquo; et l&#8217;autre &laquo;&nbsp;<strong>links</strong>&laquo;&nbsp;</p>
<h3>Création des Shared SWFs</h3>
<p>Créez un FLA Sauvegardez le sous &laquo;&nbsp;share/shared_quelque_chose.fla&nbsp;&raquo;. Créez les symboles dont vous avez besoin.</p>
<p>Ensuite, nous devons  régler chaque symbole sur &laquo;&nbsp;<strong>Exporter</strong>..&nbsp;&raquo; . Dans la bibliothèque, clic droit sur chaque symbole &gt; &laquo;&nbsp;propriété&nbsp;&raquo; et cochez la case &laquo;&nbsp;<strong>Exporter pour le partage..</strong>&laquo;&nbsp;. L&#8217;URL n&#8217;est pas utile, si le nom de votre application se place automatiquement dedans, ça ne gênera pas. Comme ceci:</p>
<p><a rel="attachment wp-att-336" href="http://www.flashxpress.net/?attachment_id=336"><img class="aligncenter size-full wp-image-336" src="http://www.covergraph.com/blog/wp-content/uploads/2010/05/flash05.jpg" alt="flash05" width="425" height="549" /></a></p>
<p>Une fois terminé, il reste à exporter chaque symbole en <strong>SWF</strong> séparés dans le répertoire <strong>share</strong>. A nouveau clic droit sur chaque symbole comme cette image:</p>
<p><a rel="attachment wp-att-337" href="http://www.flashxpress.net/?attachment_id=337"><img class="aligncenter size-full wp-image-337" src="http://www.covergraph.com/blog/wp-content/uploads/2010/05/flash02.jpg" alt="flash02" width="402" height="407" /></a></p>
<p>Voilà, nos Shared SWFs sont à présent créés! (1 SWF par classe).</p>
<h3>Création des SWFs de références (linked)</h3>
<p>Tout en laissant ouvert le <strong>Shared..fla</strong> que nous venons de créer, créez un nouveau document et nommez le &laquo;&nbsp;<strong>Ref_links_quelque_chose.fla</strong>&laquo;&nbsp;, sauvegardez le dans le répertoire &laquo;&nbsp;<strong>links</strong>&nbsp;&raquo; Copier tous les symboles de la bibliothèque du FLA <strong>Share </strong>dans la bibliothèque du FLA <strong>links </strong>par la commande &laquo;&nbsp;copier/coller&nbsp;&raquo;.</p>
<p>Nous devons cette fois, régler les propriétés de chaque symbole de ce nouveau FLA sur &laquo;&nbsp;<strong>Importer pour le partage..</strong>&laquo;&nbsp;</p>
<p><strong>Attention!!</strong> <strong>ici, dans le champs</strong> &laquo;&nbsp;<strong>URL:</strong>&nbsp;&raquo; <strong>il faut impérativement donner le chemin du SHARED SWF auquel ce symbole sera lié!!</strong></p>
<p><strong></strong> Donc, en mettant les mêmes noms que le SWF qui contient réellement les classes. comme ceci:</p>
<p><a rel="attachment wp-att-342" href="http://www.flashxpress.net/?attachment_id=342"><img class="aligncenter size-full wp-image-342" src="http://www.covergraph.com/blog/wp-content/uploads/2010/05/flash03.jpg" alt="flash03" width="425" height="549" /></a></p>
<p>Pour terminer, exportez tous les symboles en SWF dans le répertoire &laquo;&nbsp;<strong>links</strong>&laquo;&nbsp;.</p>
<h3>Utilisation des SWFs sous FlashDevelop</h3>
<p>Créez un nouveau Project AS3, placez tous les SWFs du répertoire &laquo;&nbsp;<strong>links</strong>&nbsp;&raquo; dans le répertoire &laquo;&nbsp;<strong>lib</strong>&nbsp;&raquo; du projet et tous les SWFs du répertoire &laquo;&nbsp;<strong>share</strong>&nbsp;&raquo; dans le répertoire &laquo;&nbsp;<strong>bin</strong>&nbsp;&raquo; du projet.</p>
<p>Ajouter tous les SWFs de &laquo;&nbsp;<strong>lib</strong>&nbsp;&raquo; à la librairie de FD. (Clic droit &gt; add to library). Ce n&#8217;est pas obligé dans ce cas ci, mais c&#8217;est mieux pour l&#8217;auto complétion.</p>
<p>A présent, vous pouvez Embeder vos SWF link (ceux du répertoire lib) dans votre code.   Vous pouvez cliquer droit dessus et faire &laquo;&nbsp;Insert Into Document&nbsp;&raquo;.</p>
<p>Une fois les swf embarqués et déclarés en tant que <code>Class</code>, vous pouvez les instancier comme n&#8217;importe quelle autre classe.</p>
<p>Voici un exemple d&#8217;utilisation:</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('p5168code19'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p516819"><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
</pre></td><td class="code" id="p5168code19"><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=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a><span style="color: #000066; font-weight: bold;">;</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>
&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: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span> = <span style="color: #990000;">'../lib/btn.swf'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">public</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=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</span></a><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span> = <span style="color: #990000;">'../lib/round.swf'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> Round<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</span></a><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span> = <span style="color: #990000;">'../lib/ovale.swf'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> Ovale<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</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: #6699cc; font-weight: bold;">var</span> btn<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> Btn<span style="color: #000000;">&#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;">x</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span> btn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">50</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>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">round</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> Round<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">round</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">round</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">150</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">round</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> ovale<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> Ovale<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			ovale<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span> ovale<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">250</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>ovale<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: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<blockquote><p>this.tutorial.terminate( <img src='http://www.flashxpress.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  );</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/swf-partage-et-rsl-en-as3-avec-flashdevelop/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Preloader d&#8217;images en AS3</title>
		<link>http://www.flashxpress.net/ressources-flash/preloader-dimages-en-as3/</link>
		<comments>http://www.flashxpress.net/ressources-flash/preloader-dimages-en-as3/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 10:51:16 +0000</pubDate>
		<dc:creator>Muriel Charon</dc:creator>
				<category><![CDATA[Flash ActionScript]]></category>
		<category><![CDATA[Tutoriels Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[preload]]></category>

		<guid isPermaLink="false">http://www.flashxpress.net/?p=4622</guid>
		<description><![CDATA[Comment créer un preloader d&#8217;image avec barre de progression et pourcentage ? La réponse ici ! 1 – Préparation du document −    Créer un nouveau document AS3 (Ctrl + N). −    Créer 1 calque et nommez le : Actions 2 &#8211; Création des éléments graphiques du preloader. −    Créez 2 symboles de type clip (Ctrl [...]]]></description>
			<content:encoded><![CDATA[<p>
<object width="620" height="400">
<param name="movie" value="http://www.flashxpress.net/wp-content/uploads/2010/01/as3_preloader.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="620" height="400" src="http://www.flashxpress.net/wp-content/uploads/2010/01/as3_preloader.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" allowFullScreen="true" ></embed>
</object>
</p>
<p>Comment créer un preloader d&#8217;image avec barre de progression et pourcentage ? La réponse ici !</p>
<h1>1 – Préparation du document</h1>
<p>−    Créer un nouveau document AS3 (Ctrl + N).</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/01/image001.gif"><img class="alignnone size-full wp-image-4625" title="image001" src="http://www.flashxpress.net/wp-content/uploads/2010/01/image001.gif" alt="" width="313" height="268" /></a></p>
<p>−    Créer 1 calque et nommez le : Actions</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/01/image002.gif"><img class="alignnone size-full wp-image-4626" title="image002" src="http://www.flashxpress.net/wp-content/uploads/2010/01/image002.gif" alt="" width="242" height="169" /></a></p>
<h1>2 &#8211; Création des éléments graphiques du preloader.</h1>
<p>−    Créez 2 symboles de type clip (Ctrl + F8) et nommez les : <strong>preloader </strong>et <strong>barre</strong>.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/01/image003.gif"><img class="alignnone size-full wp-image-4627" title="image003" src="http://www.flashxpress.net/wp-content/uploads/2010/01/image003.gif" alt="" width="280" height="323" /></a></p>
<p>Nous avons maintenant deux clips dans la bibliothèque : <strong>preloader </strong>et <strong>barre</strong>.</p>
<p>−    Double-clickez sur le clip <strong>barre </strong>pour accéder à son interface graphique et dessiner la barre de chargement  avec l&#8217;outil rectangle.</p>
<p>−    Double-clickez sur le clip <strong>preloader </strong>et insérer le clip barre.</p>
<p>Pour pouvoir contrôler dynamiquement par la suite l’échelle (largeur en pourcentage) de votre clip barre, nous devons lui donner un nom d’occurrence : <strong>barreDeChargement_mc</strong>.</p>
<p>−    Sélectionnez le clip barre sur la scène et écrivez “barreDeChargement_mc” dans le champ &lt;nom d’occurrence&gt; de l’inspecteur de propriétés.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/01/image004.gif"><img class="alignnone size-full wp-image-4628" title="image004" src="http://www.flashxpress.net/wp-content/uploads/2010/01/image004.gif" alt="" width="285" height="207" /></a></p>
<p>Pour afficher le taux de chargement, nous avons besoin d&#8217;un champs texte dynamique instancié.</p>
<p>−    Sur un deuxième calque, créez un champs de texte dynamique à l&#8217;aide de l&#8217;outil Texte et et écrivez “<strong>pourcentage_txt</strong>” dans le champ &lt;nom d’occurrence&gt; de l’inspecteur de propriétés.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/01/image005.gif"><img class="alignnone size-full wp-image-4629" title="image005" src="http://www.flashxpress.net/wp-content/uploads/2010/01/image005.gif" alt="" width="280" height="179" /></a></p>
<p>Le clip <strong>preloader </strong>est prêt à l&#8217;emploi.</p>
<h1>3 – Exportation pour ActionScript du clip preloader.</h1>
<p>Pour créer dynamiquement ce clip sur la scène, nous devons l&#8217;exporter pour ActionScript.</p>
<p>−    Utilisez la boîte de dialogue Propriétés du panneau Bibliothèque.</p>
<p>1. Sélectionnez le clip <strong>preloader </strong>dans le panneau Bibliothèque.<br />
2. Dans le menu contextuel du panneau Bibliothèque, choisissez <strong>Propriétés</strong>&#8230;.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/01/image006.gif"><img class="alignnone size-full wp-image-4630" title="image006" src="http://www.flashxpress.net/wp-content/uploads/2010/01/image006.gif" alt="" width="432" height="342" /></a></p>
<p>3. La boîte de dialogue Propriétés du symbole apparaît.</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/01/image007.png"><img class="alignnone size-full wp-image-4631" title="image007" src="http://www.flashxpress.net/wp-content/uploads/2010/01/image007.png" alt="" width="419" height="329" /></a></p>
<p>4. Dans la boîte de dialogue Liaison, activez l&#8217;option Exporter pour ActionScript.<br />
Les champs Classe et Classe de base sont alors activés.<br />
Par défaut, le champ Classe de base a la valeur flash.display.MovieClip</p>
<p>5. Cliquez sur OK.</p>
<h1>﻿Code AS3</h1>
<p>−    Sur le calque Actions, Frame 1, ouvrez le panneau Actions et ajoutez le code suivant :</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('p4622code21'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p462221"><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
</pre></td><td class="code" id="p4622code21"><pre class="actionscript3" style="font-family:monospace;">	<span style="color: #3f5fbf;">/**
	 * @subject Preloader AS3
	 * @author Muriel Charon
	 * @date Janvier 2010
	 */</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//Variables Preloader et Loader</span>
<span style="color: #6699cc; font-weight: bold;">var</span> preloader<span style="color: #000066; font-weight: bold;">:</span>Preloader<span style="color: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//Instanciation de l'objet preloader</span>
preloader = <span style="color: #0033ff; font-weight: bold;">new</span> Preloader<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;">//Centre le preloader sur la scène</span>
preloader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">-</span> preloader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
preloader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">-</span> preloader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//affichage du preloader avec la méthode addChild()</span>
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>preloader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//Instanciation de l'objet chargeur</span>
chargeur = <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;">//L’écoute des différents événements propres au chargement se fait auprès de l’objet LoaderInfo accessible par la propriété contentLoaderInfo de l’objet Loader</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//ProgressEvent.PROGRESS : diffusé lorsque le chargement est en cours. Informe sur le nombre d’octets chargés et totaux. Sa fréquence de diffusion est liée à la vitesse de téléchargement de l’élément</span>
chargeur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</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=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> chargement<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//Event.COMPLETE : diffusé lorsque le chargement est terminé</span>
chargeur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</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=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> finChargement<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//IOErrorEvent.IO_ERROR : diffusé lorsque le chargement échoue</span>
chargeur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</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=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> onIOError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//Chargement de l'image externe avec la methode load(). L'objet URLRequest contient l'adresse de l'élément à charger</span>
chargeur<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;la_gare.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> chargement<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: #009900; font-style: italic;">//bytesLoaded et bytesTotal sont des propriétés qui renvoient le nombre d'octets de contenu chargé</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> ratio<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = pEvt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesLoaded</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: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//Affichage du taux de chargement dans le champs texte dynamique</span>
	preloader<span style="color: #000066; font-weight: bold;">.</span>pourcentage_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>ratio<span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot; %&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//Mise à l'echelle de la barre de progression proportionnellement au taux de chargement</span>
	preloader<span style="color: #000066; font-weight: bold;">.</span>barreDeChargement_mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleX</span> = ratio<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> finChargement<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: #009900; font-style: italic;">//suppression de l'objet preloader</span>
	<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>preloader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//suppression des références vers l'objet preloader pour qu'il puisse être supprimé de la mémoire</span>
	preloader<span style="color: #000066; font-weight: bold;">.</span>pourcentage_txt = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
	preloader<span style="color: #000066; font-weight: bold;">.</span>barreDeChargement_mc = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//affichage du chargeur avec la méthode addChild()</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: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> onIOError<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: #009900; font-style: italic;">//indique la nature de l'erreur</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>pEvt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//**FIN DU SCRIPT</span></pre></td></tr></table></div>

<p>Et voilà, votre preloader est prêt à l&#8217;emploi !</p>
<p><a href="http://www.flashxpress.net/wp-content/uploads/2010/01/preloader_AS3_src.zip">Télécharger les sources : preloader_AS3_src.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashxpress.net/ressources-flash/preloader-dimages-en-as3/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

