<?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 événements</title>
	<atom:link href="http://www.bases-as3.fr/category/evenements/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>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-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> 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-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> 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-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: #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-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;">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-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;">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-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: #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-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: #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>Gérer le mouvement au dessus d&#8217;un objet d&#8217;affichage</title>
		<link>http://www.bases-as3.fr/gerer-le-mouvement-au-dessus-dun-objet-daffichage</link>
		<comments>http://www.bases-as3.fr/gerer-le-mouvement-au-dessus-dun-objet-daffichage#comments</comments>
		<pubDate>Wed, 02 Apr 2008 00:01:12 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les événements]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/index.php/2008/04/02/gerer-le-mouvement-au-dessus-dun-objet-daffichage</guid>
		<description><![CDATA[L'événement MOUSE_MOVE en ActionScript 3. 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...]]></description>
			<content:encoded><![CDATA[<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>
<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>
<p><span id="more-46"></span></p>
<p>Dans l'article  <a href="http://www.bases-as3.fr/index.php/2006/08/31/19-liaison-avec-un-clip-de-la-bibliotheque">Liaison avec un clip de la bibliothèque</a>, nous avons vu comment il était possible d'utiliser un objet de la bibliothèque en ActionScript 3.</p>
<p>Nous allons donc importer une image d'un toucan dans la bibliothèque et dans les propriétés de ce bitmap, nous allons définir sa classe, en l'occurence ici nous utiliserons comme nom de classe : Toucan. La classe de base de ce bitmap est la classe BitmapData.</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-20"><a href="#" onclick="javascript:showPlainTxt('actionscript-20'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-20">
<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. Pour afficher ces données, on va passer l'objet dataToucan en tant que paramètre d'un objet de type Bitmap. La classe Bitmap est une classe qui peut être affichée à l'écran, elle hérite de la classe DisplayObject.</p>
<div class="igBar"><span id="lactionscript-21"><a href="#" onclick="javascript:showPlainTxt('actionscript-21'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-21">
<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.</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> 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.</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;">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>
<h4>Création de l'événement MOUSE_MOVE sur l'objet leToucan</h4>
<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-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;">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>Le fichier d'exemple</h4>
<p><a href="http://www.bases-as3.fr/wp-content/uploads/2008/04/mouse-move.fla" title="Exemple de l’événement MOUSE_MOVE">Téléchargez le fichier d'exemple</a><a href="http://www.bases-as3.fr/wp-content/uploads/2008/04/mouse-move.fla" title="Exemple de l’événement MOUSE_MOVE"> de l’événement MOUSE_MOVE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/gerer-le-mouvement-au-dessus-dun-objet-daffichage/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>L&#8217;événement doubleClick</title>
		<link>http://www.bases-as3.fr/11-l-evenement-doubleclick</link>
		<comments>http://www.bases-as3.fr/11-l-evenement-doubleclick#comments</comments>
		<pubDate>Thu, 31 Aug 2006 11:55:24 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les événements]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=17</guid>
		<description><![CDATA[<h4>Gérer l'événement doubleClick en  ActionScript 3 (AS3)</h4> <p>Je vous conseille de relire l'article sur <a href="http://www.bases-as3.fr/index.php/2006/07/23/9-l-evenement-click" hreflang="fr">l'événement click</a> pour comprendre le modèle d'événements.</p>]]></description>
			<content:encoded><![CDATA[<h4>Gérer l'événement doubleClick en  ActionScript 3 (AS3)</h4>
<p>Je vous conseille de relire l'article sur <a href="http://www.bases-as3.fr/index.php/2006/07/23/9-l-evenement-click" hreflang="fr">l'événement click</a> pour comprendre le modèle d'événements.</p>
<p><span id="more-17"></span></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;"><span style="color: #808080; font-style: italic;">// rectangle 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: #000000; font-weight: bold;">var</span> rectangle:<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-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;">rectangle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x0000FF<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;">rectangle.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</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 rectangle peut recevoir l'événement doubleClic </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangle.<span style="color: #006600;">doubleClickEnabled</span>=<span style="color: #000000; font-weight: bold;">true</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 click du clip contenant le rectangle </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> doubleClicRectangle<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-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: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Evénement de type : "</span>+evt.<span style="color: #0066CC;">type</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: #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 click du rectangle est défini </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;">rectangle.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">MouseEvent</span>.<span style="color: #006600;">DOUBLE_CLICK</span>, doubleClicRectangle<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: #808080; font-style: italic;">// Le rectangle est ajouté à la séquence </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;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangle<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/11-l-evenement-doubleclick/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>L&#8217;événement click</title>
		<link>http://www.bases-as3.fr/9-l-evenement-click</link>
		<comments>http://www.bases-as3.fr/9-l-evenement-click#comments</comments>
		<pubDate>Sun, 23 Jul 2006 22:10:02 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les événements]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=16</guid>
		<description><![CDATA[<h4>Gérer l'évenement click en ActionScript 3 (AS3)</h4> <p>L'ActionScript 3 intègre un nouveau modèle d'événements basé sur le Document Object Model (DOM) Level 3 Events Specification.<br />
Cette nouvelle version de l'ActionScript introduit un unique gestionnaire d'événements qui remplace les différents mécanismes des versions précédentes du langage.<br />
Pour ajouter un événement en AS3, on utilise la méthode addEventListener(). Une fonction sera éxécutée en réponse à l'événement.</p>]]></description>
			<content:encoded><![CDATA[<h4>Gérer l'évenement click en ActionScript 3 (AS3)</h4>
<p>L'ActionScript 3 intègre un nouveau modèle d'événements basé sur le Document Object Model (DOM) Level 3 Events Specification.<br />
Cette nouvelle version de l'ActionScript introduit un unique gestionnaire d'événements qui remplace les différents mécanismes des versions précédentes du langage.<br />
Pour ajouter un événement en AS3, on utilise la méthode addEventListener(). Une fonction sera éxécutée en réponse à l'événement.</p>
<p><span id="more-16"></span></p>
<p>Un objet event est passé en tant qu'argument à la fonction. Cet objet event peut-être une instance des différentes classes du package flash.events, telles que MouseEvent, KeyboardEvent, FocusEvent...</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: #808080; font-style: italic;">// clip vide </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> monClip:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">MovieClip</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;">// rectangle 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: #000000; font-weight: bold;">var</span> rectangle:<span style="color: #0066CC;">Shape</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Shape</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;">rectangle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x0000FF<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;">rectangle.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</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 rectangle est ajouté dans le clip </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">monClip.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangle<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 click du clip contenant le rectangle </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> clicRectangle<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-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: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Evénement de type : "</span>+evt.<span style="color: #0066CC;">type</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: #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 click du clip est défini </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;">monClip.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">MouseEvent</span>.<span style="color: #006600;">CLICK</span>, clicRectangle<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: #808080; font-style: italic;">// Le clip est ajouté à la séquence </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;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>monClip<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
2 articles très complets sur les événements Flash : <a href="http://starmonkey.free.fr/blog/index.php/?2006/07/25/16-modele-evenementiel" hreflang="fr">L'article de starmonkey</a> et <a href="http://www.ekameleon.net/blog/index.php?2006/07/25/39--as3-event-as3" hreflang="fr">L'article de ekameleon</a></p>
<p>;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/9-l-evenement-click/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

