<?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>Les bases de l'ActionScript 3 &#187; Les images</title>
	<atom:link href="http://www.bases-as3.fr/category/images/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bases-as3.fr</link>
	<description>Appréhender facilement la programmation en ActionScript 3.</description>
	<lastBuildDate>Thu, 28 Jul 2011 11:38:00 +0000</lastBuildDate>
	<language>fr</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>La géométrie dans Flash</title>
		<link>http://www.bases-as3.fr/la-geometrie-dans-flash</link>
		<comments>http://www.bases-as3.fr/la-geometrie-dans-flash#comments</comments>
		<pubDate>Tue, 15 Jul 2008 12:37:56 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Les dessins]]></category>
		<category><![CDATA[Les images]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/index.php/2008/07/15/la-geometrie-dans-flash</guid>
		<description><![CDATA[Utilisation de la géométrie en ActionScript 3 (AS3) Le but de cet article est d'étudier les différentes fonctionnalités en rapport avec la géométrie dans Flash. Le package flash.geom contient des...]]></description>
			<content:encoded><![CDATA[<h3>Utilisation de la géométrie en ActionScript 3 (AS3)</h3>
<p>Le but de cet article est d'étudier les différentes fonctionnalités en rapport avec la géométrie dans Flash.<br />
Le package flash.geom contient des classes qui définissent des objets géométriques, tels que des points, des rectangles et des matrices de transformation. Ces classes ne fournissent pas nécessairement de fonctionnalité par elles-mêmes ; néanmoins, elles sont utilisées pour définir les propriétés des objets utilisés dans d'autres classes.</p>
<p><span id="more-68"></span></p>
<p>Toutes les classes de géométrie se basent sur la notion selon laquelle les emplacements à l'écran sont représentés comme un plan en deux dimensions. L'écran est traité comme un graphique plat avec un axe horizontal (x) et un axe vertical (y). Tout emplacement (ou point) à l'écran peut être représenté sous la forme d'une paire de valeurs x et y, appelées coordonnées de cet emplacement.</p>
<p>Le point d'origine, coordonnées 0, 0, de la scène de travail est le coin haut gauche de la séquence.</p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/07/image11.png" alt="image11.png" /></p>
<p>Les valeurs sur l'axe x augmentent en allant vers la droite et diminuent en allant vers la gauche. Néanmoins, contrairement aux systèmes de coordonnées classiques, dans ActionScript, les valeurs sur l'axe y augmentent en allant vers le bas et diminuent en allant vers le haut de l'écran.</p>
<h4>Utilisation de la classe Point</h4>
<p>Un objet Point définit une paire de coordonnées cartésiennes. Il représente un emplacement dans un système de coordonnées à deux dimensions, dans lequel x est l'axe horizontal et y l'axe vertical.</p>
<p>Le constructeur de la classe Point prend en paramètres la valeur de la coordonnée x et la valeur de la coordonnée y.</p>
<div class="igBar"><span id="lactionscript-8"><a href="#" onclick="javascript:showPlainTxt('actionscript-8'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-8">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> point1:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span>, <span style="color: #cc66cc;color:#800000;">60</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>On rencontre très souvent des scripts dans lesquels nous avons besoin de mémoriser les coordonnées de départ d'un objet d'affichage. Classiquement, les développeurs vont créés 2 variables numériques et stocker les valeurs d'origine de notre objet.</p>
<p>Il pourrait être plus judicieux de mémoriser ces coordonnées dans un seul objet, un objet de type Point.</p>
<p>Les coordonnées sont ensuite accessibles avec les propriétés x et y de la classe Point.</p>
<div class="igBar"><span id="lactionscript-9"><a href="#" onclick="javascript:showPlainTxt('actionscript-9'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-9">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> origineCarreBleu:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>carreBleu.<span style="color: #006600;">x</span>, carreBleu.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//coordonnées d'origine du carré bleu</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>origineCarreBleu.<span style="color: #006600;">x</span>, origineCarreBleu.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Calculer la distance entre 2 points</h5>
<p>La méthode distance() de la classe Point va nous permettre de calculer la distance entre 2 points dans un espace de coordonnées. Cette méthode est une méthode statique, c'est-à-dire que c'est une méthode qui s'applique à la classe et non à une instance de classe.</p>
<p>Cette méthode attend 2 objets Point en paramètres et renvoie une valeur numérique.</p>
<div class="igBar"><span id="lactionscript-10"><a href="#" onclick="javascript:showPlainTxt('actionscript-10'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-10">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Distance entre le carre rouge et le carre vert</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> coordonneesRouge:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>carreRouge.<span style="color: #006600;">x</span>, carreRouge.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//coordonnées du carré rouge</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> coordonneesVert:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>carreVert.<span style="color: #006600;">x</span>, carreVert.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//coordonnées du carré vert</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> distanceRougeVert:<span style="color: #0066CC;">Number</span> = Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>coordonneesRouge, coordonneesVert<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>distanceRougeVert<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Le cas des espaces de coordonnées différents</h5>
<p>Dans le cas où deux objets se trouvent dans deux conteneurs d'affichage différents, ils n'utiliseront pas le même espace de coordonnées. Nous devrons donc convertir les coordonnées locales en coordonnées globales en utilisant la méthode localToGlobal() de la classe DisplayObject.</p>
<p>Dans l'exemple suivant, nous allons créer 2 champs de texte, le premier sera ajouté à la scène et le second sera ajouté dans un conteneur Sprite. Le premier champ de texte sera donc dans l'espace de coordonnées global alors que le second sera lui dans l'espace de coordonnées local au Sprite.</p>
<p>Pour calculer la distance entre les 2 champs de texte, nous utiliserons la méthode localToGlobal() sur le 2<sup>ème</sup> champ de texte afin de convertir l'objet point des coordonnées de ce texte (locales) vers les coordonnées de la scène (globales).</p>
<p>Cette méthode attend en paramètres un objet Point correspondant aux coordonnées à convertir.</p>
<div class="igBar"><span id="lactionscript-11"><a href="#" onclick="javascript:showPlainTxt('actionscript-11'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-11">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Conversion de coordonnées locales en coordonnées globales</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> texte1:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 1er champ de texte</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">texte1.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">"1er texte"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">addChild<span style="color: #66cc66;">&#40;</span>texte1<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// le texte est ajouté à la scène</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">texte1.<span style="color: #006600;">x</span> = texte1.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">50</span>; <span style="color: #808080; font-style: italic;">// le texte est positionné aux coordonnées 50,50 par rapport à la scène</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> texte2:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 2ème champ de texte</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">texte2.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">"2ème texte"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">sprite</span>:<span style="color: #0066CC;">Sprite</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sprite</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// le conteneur du 2ème champ de texte</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">sprite</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>texte2<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// le texte 2 est ajouté dans le sprite</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">sprite</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// le conteneur est ajouté à la scène</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">sprite</span>.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">sprite</span>.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">200</span>; <span style="color: #808080; font-style: italic;">//le conteneur est positionné aux coordonnées 200,200 par rapport à la scène</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> pointTexte1:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>texte1.<span style="color: #006600;">x</span>, texte1.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Coordonnées globales du texte 1</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> pointTexte2:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>texte2.<span style="color: #006600;">x</span>, texte2.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Coordonnées locales du texte 2 par rapport à son parent</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>pointTexte2.<span style="color: #006600;">x</span>, pointTexte2.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//affichage de 0, 0</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pointTexte2 = texte2.<span style="color: #0066CC;">localToGlobal</span><span style="color: #66cc66;">&#40;</span>pointTexte2<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Conversion des coordonnées locales en coordonnées globales</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>pointTexte2.<span style="color: #006600;">x</span>, pointTexte2.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//affichage de 200, 200</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> distanceTexte:<span style="color: #0066CC;">Number</span> = Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>pointTexte1, pointTexte2<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>distanceTexte<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Autres utilisations</h5>
<p>La classe Point pourra être aussi utilisée dans les méthodes des classes suivantes :</p>
<ul class="unIndentedList">
<li> DisplayObjectContainer</li>
<li> BitmapData</li>
<li> Matrix</li>
<li> Rectangle</li>
</ul>
<h4>Utilisation de la classe Rectangle</h4>
<p>Un objet Rectangle définit une zone rectangulaire. Un objet Rectangle a une position définie par les coordonnées x et y de son angle supérieur gauche, une propriété width définissant sa largeur et une propriété height  définissant sa hauteur.</p>
<p>Le constructeur prend en paramètres ces 4 valeurs.</p>
<div class="igBar"><span id="lactionscript-12"><a href="#" onclick="javascript:showPlainTxt('actionscript-12'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-12">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> zone1:Rectangle = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">50</span>, <span style="color: #cc66cc;color:#800000;">50</span>, <span style="color: #cc66cc;color:#800000;">220</span>, <span style="color: #cc66cc;color:#800000;">110</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//zone rectangulaire de 220 pixels de large, 110 pixels de haut, positionnée aux coordonnées 50, 50 </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Cas d'utilisation</h5>
<h6>Recouvrement de 2 objets</h6>
<p>La méthode intersects() de la classe Rectangle va vous permettre de savoir si 2 rectangles se recouvrent. Cette méthode peut-être utilisée pour savoir si 2 objets d'affichage (clip, sprite, image...) se recouvrent.</p>
<p>En effet, la méthode getBounds() de la classe DisplayObject renvoie un objet de type Rectangle correspondant à la délimitation rectangulaire de l'objet d'affichage. En récupérant la délimitation de 2 objets, on peut ensuite savoir s'ils se recouvrent en utilisant la méthode intersects() de la classe DisplayObject.</p>
<p>La méthode intersects() renvoie un booléen (true ou false).</p>
<p>Nous allons utiliser ces méthodes avec trois carrés dont 2 (le bleu et le vert) qui se recouvrent.</p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/07/image21.png" alt="image21.png" /></p>
<div class="igBar"><span id="lactionscript-13"><a href="#" onclick="javascript:showPlainTxt('actionscript-13'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-13">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Cas d'utilisation</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> delimitationBleu:Rectangle = carreBleu.<span style="color: #0066CC;">getBounds</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// delimitation rectangulaire du carré bleu</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>delimitationBleu.<span style="color: #006600;">x</span>, delimitationBleu.<span style="color: #006600;">y</span>, delimitationBleu.<span style="color: #0066CC;">width</span>, delimitationBleu.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> delimitationRouge:Rectangle = carreRouge.<span style="color: #0066CC;">getBounds</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// delimitation rectangulaire du carré rouge</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Est-ce que le carré bleu recouvre le carré rouge ? Réponse : "</span> + delimitationBleu.<span style="color: #006600;">intersects</span><span style="color: #66cc66;">&#40;</span>delimitationRouge<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> delimitationVert:Rectangle = carreVert.<span style="color: #0066CC;">getBounds</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// delimitation rectangulaire du carré vert</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Est-ce que le carré bleu recouvre le carré vert? Réponse : "</span> + delimitationBleu.<span style="color: #006600;">intersects</span><span style="color: #66cc66;">&#40;</span>delimitationVert<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h6>Copie d'une zone d'une image</h6>
<p>Les classes rectangle et Point sont aussi utilisées lors de la copie d'une zone d'une image. En effet, la méthode copyPixels() de la classe BitmapData prend notamment  en paramètres un objet Rectangle et un objet Point.</p>
<p>L'objet Rectangle correspond à la zone rectangulaire de pixels qui sera copiées. Cet objet Rectangle définira les coordonnées x et y du point d'origine de la copie par rapport à l'image initiale et la largeur et hauteur de la zone copiée.</p>
<p>L'objet Point correspond au point d'origine dans la copie à partir duquel seront copiés les pixels.</p>
<div class="igBar"><span id="lactionscript-14"><a href="#" onclick="javascript:showPlainTxt('actionscript-14'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-14">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Cas d'utilisation : copie de pixels</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> pixelsDisney:Disney = <span style="color: #000000; font-weight: bold;">new</span> Disney<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">300</span>, <span style="color: #cc66cc;color:#800000;">201</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//La classe Disney correspond à la classe auto-générée depuis l'image cars.jpg de la bibliothèque</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> imageDisney:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>pixelsDisney<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Objet d'affichage des pixels</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">addChild<span style="color: #66cc66;">&#40;</span>imageDisney<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//affichage de l'image dans la scène</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> copiePixelsDisney:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">142</span>, <span style="color: #cc66cc;color:#800000;">105</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// objet de 142 pixels de large et de 105 pixels de hauteur dans lequel les pixels seront copiés</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> zoneImage:Rectangle = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">158</span>, <span style="color: #cc66cc;color:#800000;">96</span>, copiePixelsDisney.<span style="color: #0066CC;">width</span>, copiePixelsDisney.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Cette zone rectangulaire est une zone de 142 pixels de large, 105 pixels de haut et la copie des pixels sera effectué à partir des coordonnées 158, 96 par rapport au coin haut gauche de l'image.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> pointCollage:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>,<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Les pixels seront collés au point de coordonnées 0,0 de l'objet BitmapData</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">copiePixelsDisney.<span style="color: #006600;">copyPixels</span><span style="color: #66cc66;">&#40;</span>pixelsDisney, zoneImage, pointCollage<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//copie d'une zone de pixels.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> newDisney:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>copiePixelsDisney<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// objet d'affichage de la copie des pixels</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">newDisney.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">220</span>; <span style="color: #808080; font-style: italic;">//positionnement de la copie sous l'image d'origine</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">addChild<span style="color: #66cc66;">&#40;</span>newDisney<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//affichage de la copie </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Autres utilisations</h5>
<p>La classe Rectangle pourra être aussi utilisée dans les méthodes des classes suivantes :</p>
<ul class="unIndentedList">
<li> DisplayObject</li>
<li> BitmapData</li>
<li> PrintJob</li>
<li> Sprite</li>
<li> TextField</li>
<li> Transform</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/la-geometrie-dans-flash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Liaison avec une image de la bibliothèque et gestion du mouvement au dessus d&#8217;un objet d&#8217;affichage</title>
		<link>http://www.bases-as3.fr/liaison-avec-une-image-de-la-bibliotheque-et-gestion-du-mouvement-au-dessus-dun-objet-daffichage</link>
		<comments>http://www.bases-as3.fr/liaison-avec-une-image-de-la-bibliotheque-et-gestion-du-mouvement-au-dessus-dun-objet-daffichage#comments</comments>
		<pubDate>Fri, 23 May 2008 05:49:44 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les événements]]></category>
		<category><![CDATA[Les images]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/index.php/2008/05/23/liaison-avec-une-image-de-la-bibliotheque-et-gestion-du-mouvement-au-dessus-dun-objet-daffichage</guid>
		<description><![CDATA[Lier une image de la bibliothèque et utiliser l'événement MOUSE_MOVE en ActionScript 3 (AS3). Dans cet exemple, nous allons utiliser une image de la bibliothèque et détecter le mouvement de...]]></description>
			<content:encoded><![CDATA[<h3>Lier une image de la bibliothèque et utiliser l'événement MOUSE_MOVE en ActionScript 3 (AS3).</h3>
<p>Dans cet exemple, nous allons utiliser une image de la bibliothèque et détecter le mouvement de la souris au dessus de cette image.</p>
<h4>Liaison avec une image de la bibliothèque</h4>
<p>Pour utiliser un élément de la bibliothèque en ActionScript 3, nous allons devoir, comme les autres objets graphiques, l'instancier avec le mot clé new. Il faut cependant définir la classe de notre objet dans ces propriétés de liaisons. Cette classe sera auto-générée lors de la compilation.</p>
<p><span id="more-51"></span></p>
<p>Nous allons donc importer une image d'un toucan dans la bibliothèque et réaliser un clic-droit sur celle-ci puis choisir Liaisons.</p>
<p>Nous allons cocher l'option Exporter pour ActionScript afin de rendre éditable les champs Classe et Classe de base.</p>
<p>Dans les propriétés de liaisons de ce bitmap, nous allons définir sa classe. En l'occurrence ici nous utiliserons comme nom de classe : Toucan. La classe de base de ce bitmap est la classe BitmapData. La classe Toucan sera auto-générée lors de la compilation.</p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/05/image1.png" alt="Liaison bibliothèque" /></p>
<h4>Création de l'objet de type Toucan</h4>
<p>L'image possède une largeur de 1024 pixels et une hauteur de 768 pixels. Nous préciserons ces dimensions dans le constructeur de la classe Toucan.</p>
<div class="igBar"><span id="lactionscript-22"><a href="#" onclick="javascript:showPlainTxt('actionscript-22'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-22">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> dataToucan:Toucan = <span style="color: #000000; font-weight: bold;">new</span> Toucan<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">1024</span>, <span style="color: #cc66cc;color:#800000;">768</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Création de l'objet de type Bitmap</h4>
<p>La classe BitmapData dont hérite notre classe Toucan, est une classe qui ne contient que les données de l'image. On peut imaginer ces données sous la forme d'une grille de pixels. Un objet de type BitmapData ne peut être affiché à l'écran.</p>
<p>Pour afficher ces données, on va donc devoir utiliser une classe qui représente visuellement les données bitmap. Cette classe est la classe Bitmap.</p>
<p>La classe Bitmap est une classe qui peut être affichée à l'écran. Elle hérite de la classe DisplayObject. Le constructeur Bitmap() vous permet de créer un objet Bitmap contenant une référence à un objet BitmapData.</p>
<p>Nous allons donc passer l'objet dataToucan en tant que paramètre d'un objet de type Bitmap.</p>
<div class="igBar"><span id="lactionscript-23"><a href="#" onclick="javascript:showPlainTxt('actionscript-23'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-23">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> imgToucan:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>dataToucan<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Création de l'objet Sprite</h4>
<p>Cependant, un objet de type Bitmap ne possède pas d'événements de souris car la classe Bitmap n'hérite pas de la classe InteractiveObject. Nous allons donc afficher l'objet imgToucan dans un objet de type Sprite. L'objet de type Sprite est conteneur d'objets d'affichage notamment d'objets images, sur lequel on peut définir des événements de souris.</p>
<div class="igBar"><span id="lactionscript-24"><a href="#" onclick="javascript:showPlainTxt('actionscript-24'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-24">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> leToucan:<span style="color: #0066CC;">Sprite</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sprite</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">leToucan.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imgToucan<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Réduire l'image et l'afficher</h4>
<p>Nous allons ensuite réduire l'image à 50% de sa taille d'origine. Nous utiliserons pour cela les propriétés scaleX et scaleY héritées de la classe DisplayObject. Pour ces 2 propriétés, une valeur spécifiée à 1 correspond à 100% de la taille d'origine.</p>
<div class="igBar"><span id="lactionscript-25"><a href="#" onclick="javascript:showPlainTxt('actionscript-25'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-25">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">leToucan.<span style="color: #006600;">scaleX</span> = leToucan.<span style="color: #006600;">scaleY</span> = .<span style="color: #cc66cc;color:#800000;">5</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">addChild<span style="color: #66cc66;">&#40;</span>leToucan<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Nous remarquons que nous avons utilisé la forme courte au niveau de la valeur. On aurait pu l'écrire 0.5. Ces 2 formes sont équivalentes.</p>
<h3>L'événement MOUSE_MOVE en ActionScript 3.</h3>
<p>L'événement MouseEvent.MOUSE_MOVE permet de détecter le mouvement au dessus d'un objet. Contrairement à l'ActionScript 2, l'événement est déclenché uniquement quand la souris bouge au dessus d'un objet et non plus dès que la souris bouge sur la scène.</p>
<h4>Création de l'événement MOUSE_MOVE sur l'objet leToucan</h4>
<p>L'image étant maintenant affichée, nous allons lui ajouter un événement MOUSE_MOVE afin de détecter le déplacement de la souris sur celle-ci.</p>
<p>Nous allons afficher dans la fenêtre de sortie, un message, à chaque fois que la souris se déplacera au-dessus de l'image.</p>
<div class="igBar"><span id="lactionscript-26"><a href="#" onclick="javascript:showPlainTxt('actionscript-26'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-26">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> bougeSurToucan<span style="color: #66cc66;">&#40;</span>evt:<span style="color: #0066CC;">MouseEvent</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Le pointeur bouge sur l'image"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">leToucan.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">MouseEvent</span>.<span style="color: #006600;">MOUSE_MOVE</span>, bougeSurToucan<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Les propriétés de l'objet MouseEvent</h4>
<p>Lorsqu'un événement est diffusé, un objet de type Event ou d'une des classes dérivées, est envoyé en paramètre à la fonction de réponse de l'événement.</p>
<p>Cet objet contient des informations, liées à l'événement en cours de diffusion, accessibles à travers des propriétés de l'objet.</p>
<p>Dans notre exemple, nous utilisons un événement MOUSE_MOVE de la classe MouseEvent. Cette classe possède notamment 4 propriétés, localX, localY, stageX, stageY, que nous allons présenter.</p>
<ul>
<li>La propriété localX contient la coordonnée horizontale à laquelle l'événement s'est produit par rapport à l'image.</li>
<li>La propriété localY contient la coordonnée verticale à laquelle l'événement s'est produit par rapport à l'image.</li>
<li>La propriété stageX contient la coordonnée horizontale à laquelle l'événement s'est produit par rapport à la scène.</li>
<li>La propriété stageY contient la coordonnée verticale à laquelle l'événement s'est produit par rapport à l'image.</li>
</ul>
<p>Nous allons afficher ces différentes valeurs lors du survol de l'image.</p>
<div class="igBar"><span id="lactionscript-27"><a href="#" onclick="javascript:showPlainTxt('actionscript-27'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-27">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> bougeSurToucan<span style="color: #66cc66;">&#40;</span>evt:<span style="color: #0066CC;">MouseEvent</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Coordonnée X par rapport à l'image : "</span> + evt.<span style="color: #006600;">localX</span> + <span style="color: #ff0000;">" - "</span>, <span style="color: #ff0000;">"Coordonnée Y par rapport à l'image : "</span> + evt.<span style="color: #006600;">localY</span> + <span style="color: #ff0000;">" - "</span>+ <span style="color: #ff0000;">" - "</span>, <span style="color: #ff0000;">"Coordonnée X par rapport à la scène : "</span> + evt.<span style="color: #006600;">stageX</span> + <span style="color: #ff0000;">" - "</span>, <span style="color: #ff0000;">"Coordonnée Y par rapport à la scène : "</span> + evt.<span style="color: #006600;">stageY</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Le script complet</h4>
<div class="igBar"><span id="lactionscript-28"><a href="#" onclick="javascript:showPlainTxt('actionscript-28'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-28">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> dataToucan:Toucan = <span style="color: #000000; font-weight: bold;">new</span> Toucan<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">1024</span>, <span style="color: #cc66cc;color:#800000;">768</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> imgToucan:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>dataToucan<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> leToucan:<span style="color: #0066CC;">Sprite</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sprite</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">leToucan.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imgToucan<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">leToucan.<span style="color: #006600;">scaleX</span> = leToucan.<span style="color: #006600;">scaleY</span> = .<span style="color: #cc66cc;color:#800000;">5</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">addChild<span style="color: #66cc66;">&#40;</span>leToucan<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> bougeSurToucan<span style="color: #66cc66;">&#40;</span>evt:<span style="color: #0066CC;">MouseEvent</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Coordonnée X par rapport à l'image : "</span> + evt.<span style="color: #006600;">localX</span> + <span style="color: #ff0000;">" - "</span>, <span style="color: #ff0000;">"Coordonnée Y par rapport à l'image : "</span> + evt.<span style="color: #006600;">localY</span> + <span style="color: #ff0000;">" - "</span>+ <span style="color: #ff0000;">" - "</span>, <span style="color: #ff0000;">"Coordonnée X par rapport à la scène : "</span> + evt.<span style="color: #006600;">stageX</span> + <span style="color: #ff0000;">" - "</span>, <span style="color: #ff0000;">"Coordonnée Y par rapport à la scène : "</span> + evt.<span style="color: #006600;">stageY</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">leToucan.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">MouseEvent</span>.<span style="color: #006600;">MOUSE_MOVE</span>, bougeSurToucan<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p class="MsoNormal"><span lang="EN-US"><o:p></o:p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/liaison-avec-une-image-de-la-bibliotheque-et-gestion-du-mouvement-au-dessus-dun-objet-daffichage/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chargement d&#8217;une image et affichage en fondu</title>
		<link>http://www.bases-as3.fr/25-chargement-affichage-fondu-image</link>
		<comments>http://www.bases-as3.fr/25-chargement-affichage-fondu-image#comments</comments>
		<pubDate>Thu, 04 Jan 2007 17:46:52 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les images]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=20</guid>
		<description><![CDATA[<h4>Charger une image et l'afficher en fondu en ActionScript 3 (AS3)</h4> <p>Le chargement de l'image et son affichage, une fois le chargement terminé, sont expliqués dans ces 2 billets :<br />
<a href="http://www.bases-as3.fr/index.php/2006/07/26/12-le-chargement-d-images">Le chargement d'images</a><br />
<a href="http://www.bases-as3.fr/index.php/2006/07/27/13-les-evenements-progress-et-complete-de-la-classe-loaderinfo">Gérer la progression et la fin du chargement d'une image</a></p>]]></description>
			<content:encoded><![CDATA[<h4>Charger une image et l'afficher en fondu en ActionScript 3 (AS3)</h4>
<p>Le chargement de l'image et son affichage, une fois le chargement terminé, sont expliqués dans ces 2 billets :<br />
<a href="http://www.bases-as3.fr/index.php/2006/07/26/12-le-chargement-d-images">Le chargement d'images</a><br />
<a href="http://www.bases-as3.fr/index.php/2006/07/27/13-les-evenements-progress-et-complete-de-la-classe-loaderinfo">Gérer la progression et la fin du chargement d'une image</a></p>
<p><span id="more-20"></span></p>
<h5>Chargement de l'image</h5>
<div class="igBar"><span id="lactionscript-29"><a href="#" onclick="javascript:showPlainTxt('actionscript-29'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-29">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// création du conteneur de l'image </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> conteneurImage:<span style="color: #0066CC;">Loader</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Loader</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// url de l'image à charger </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> image:<span style="color: #0066CC;">URLRequest</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">URLRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"http://www.mozbot.fr/theme/menthe/www.mozbot.fr/logo.gif"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Le chargement est terminé </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> onComplete<span style="color: #66cc66;">&#40;</span>evt:<span style="color: #0066CC;">Event</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;conteneurImage.<span style="color: #006600;">alpha</span> = <span style="color: #cc66cc;color:#800000;">0</span>; <span style="color: #808080; font-style: italic;">//le conteneur est transparent</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;addChild<span style="color: #66cc66;">&#40;</span>conteneurImage<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// affichage du conteneur</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;myTimer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//démarrage du timer</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Evénement complete </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">conteneurImage.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Event</span>.<span style="color: #006600;">COMPLETE</span>, onComplete<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>La gestion de l'affichage en fondu</h5>
<p>Nous allons utilisé un objet Timer qui va nous permettre d'augmenter de 10% l'alpha du conteneur toutes les 200 millisecondes. L'objet Timer possède 2 arguments. Le premier permet d'indiquer la fréquence à laquelle on veut exécuter une action. Le second permet d'indiquer le nombre de fois où l'on veut exécuter cette action.<br />
On évoquera l'événement TIMER de la classe TimerEvent afin d'exécuter en réponse la fonction onAlpha</p>
<div class="igBar"><span id="lactionscript-30"><a href="#" onclick="javascript:showPlainTxt('actionscript-30'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-30">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// on crée un objet Timer avec en paramètres le délai puis le nombre d'événements diffusés </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> myTimer:Timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">10</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//on souhaite exécuter une action toutes les 200 millisecondes et ce, 10 fois de suite </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// A chaque appel du Timer (toutes les 200 millisecondes), </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> onAlpha<span style="color: #66cc66;">&#40;</span> pEvt:TimerEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;conteneurImage.<span style="color: #006600;">alpha</span> += <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">1</span>; <span style="color: #808080; font-style: italic;">//l'alpha augmente</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">myTimer.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span> TimerEvent.<span style="color: #006600;">TIMER</span>, onAlpha <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Toutes les 200 millisecondes, le timer exécute l'événement TIMER et donc en réponse, la fonction onAlpha est exécutée. </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// chargement de l'image dans le conteneur </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">conteneurImage.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>image<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Le timer ne démarre pas automatiquement, c'est pourquoi on utilise la méthode start du timer dans la fonction onComplete</h5>
<p>;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/25-chargement-affichage-fondu-image/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Les événements progress et complete de la classe LoaderInfo</title>
		<link>http://www.bases-as3.fr/13-les-evenements-progress-et-complete-de-la-classe-loaderinfo</link>
		<comments>http://www.bases-as3.fr/13-les-evenements-progress-et-complete-de-la-classe-loaderinfo#comments</comments>
		<pubDate>Thu, 27 Jul 2006 22:51:46 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les images]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=19</guid>
		<description><![CDATA[<h4>Gérer la progression et la fin du chargement d'une image ou d'un swf en ActionScript 3 (AS3)</h4> <p>Le chargement est explique dans le billet&#160;: <a href="http://www.bases-as3.fr/index.php/2006/07/26/12-le-chargement-d-images" hreflang="fr">Le chargement d'images ou de swf</a></p> <p>La classe LoaderInfo fournit des informations sur les fichiers swf chargés et sur les images chargées. Les informations fournies inclues une progression de chargement, les url du chargeur et du contenu chargé, le nombre total de bits pour le média, et la largeur/hauteur du média.</p>]]></description>
			<content:encoded><![CDATA[<h4>Gérer la progression et la fin du chargement d'une image ou d'un swf en ActionScript 3 (AS3)</h4>
<p>Le chargement est explique dans le billet : <a href="http://www.bases-as3.fr/index.php/2006/07/26/12-le-chargement-d-images" hreflang="fr">Le chargement d'images ou de swf</a></p>
<p>La classe LoaderInfo fournit des informations sur les fichiers swf chargés et sur les images chargées. Les informations fournies inclues une progression de chargement, les url du chargeur et du contenu chargé, le nombre total de bits pour le média, et la largeur/hauteur du média.</p>
<p><span id="more-19"></span></p>
<p>On accède aux objets LoaderInfo grâce à la propriété contentLoaderInfo de l'objet Loader.<br />
Les événements progress et complete sont des événements de la classe LoaderInfo et non de la classe Loader. Il faut donc ajouter la méthode addEventListener() à Loader.contentLoaderInfo et non à Loader directement.</p>
<p>L'événement progress est évoqué régulièrement durant le chargement de l'image. L'événement complete est évoqué lorsque le chargement a réussi.</p>
<div class="igBar"><span id="lactionscript-31"><a href="#" onclick="javascript:showPlainTxt('actionscript-31'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-31">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// création du conteneur de l'image </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> conteneurImage:<span style="color: #0066CC;">Loader</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Loader</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// url de l'image à charger </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> image:<span style="color: #0066CC;">URLRequest</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">URLRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"images/madagascar.jpg"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Le chargement est terminé </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> onComplete<span style="color: #66cc66;">&#40;</span>evt:<span style="color: #0066CC;">Event</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// affichage du conteneur</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>conteneurImage<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Progression du chargement </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> onProgress<span style="color: #66cc66;">&#40;</span>evt:<span style="color: #0066CC;">ProgressEvent</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> p:<span style="color: #0066CC;">Number</span>=<span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">bytesLoaded</span>*<span style="color: #cc66cc;color:#800000;">100</span><span style="color: #66cc66;">&#41;</span>/evt.<span style="color: #0066CC;">bytesTotal</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Evénement progress </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">conteneurImage.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">ProgressEvent</span>.<span style="color: #006600;">PROGRESS</span>, onProgress<span style="color: #66cc66;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Evénement complete </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">conteneurImage.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Event</span>.<span style="color: #006600;">COMPLETE</span>, onComplete<span style="color: #66cc66;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// chargement de l'image dans le conteneur </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">conteneurImage.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>image<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/13-les-evenements-progress-et-complete-de-la-classe-loaderinfo/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Le chargement d&#8217;images ou de swf</title>
		<link>http://www.bases-as3.fr/12-le-chargement-d-images</link>
		<comments>http://www.bases-as3.fr/12-le-chargement-d-images#comments</comments>
		<pubDate>Wed, 26 Jul 2006 23:58:57 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les images]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=18</guid>
		<description><![CDATA[<h4>Charger des images gif, jpeg, png ou des swf en ActionScript 3 (AS3)</h4> <p>Le chargement d'images ou de swf dans Flash va se faire grâce à deux nouvelles classes&#160;: Loader et URLRequest.<br />
La classe Loader va nous permettre de créer un conteneur de chargement. La classe URLRequest va nous permettre de définir l'url absolue ou relative du fichier à charger.<br /></p>]]></description>
			<content:encoded><![CDATA[<h4>Charger des images gif, jpeg, png ou des swf en ActionScript 3 (AS3)</h4>
<p>Le chargement d'images ou de swf dans Flash va se faire grâce à deux nouvelles classes : Loader et URLRequest.<br />
La classe Loader va nous permettre de créer un conteneur de chargement. La classe URLRequest va nous permettre de définir l'url absolue ou relative du fichier à charger.</p>
<p><span id="more-18"></span></p>
<p>Le chargement se fera grâce à la méthode load() de l'objet loader. L'affichage de l'image ou du swf se fera grâce à la méthode addChil().</p>
<div class="igBar"><span id="lactionscript-32"><a href="#" onclick="javascript:showPlainTxt('actionscript-32'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-32">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// création du conteneur de l'image ou du swf</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> conteneurImage:<span style="color: #0066CC;">Loader</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Loader</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// url de l'image ou du swf à charger</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> image:<span style="color: #0066CC;">URLRequest</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">URLRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"images/tannoy.gif"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// chargement de l'image ou du swf dans le conteneur</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">conteneurImage.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>image<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// affichage du conteneur</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>conteneurImage<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
L'image utilisée est celle-ci : <img src="/images/tannoy.gif" alt="" /></p>
<p>;-)</p>
<p>A suivre un billet sur les événements liés au chargement d'images ou de swf :</p>
<p><a href="http://www.bases-as3.fr/13-les-evenements-progress-et-complete-de-la-classe-loaderinfo">http://www.bases-as3.fr/13-les-evenements-progress-et-complete-de-la-classe-loaderinfo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/12-le-chargement-d-images/feed</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
	</channel>
</rss>

