<?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; General</title>
	<atom:link href="http://www.bases-as3.fr/category/general/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>Mise à jour du Flash Player</title>
		<link>http://www.bases-as3.fr/38-mise-jour-flash-player</link>
		<comments>http://www.bases-as3.fr/38-mise-jour-flash-player#comments</comments>
		<pubDate>Thu, 20 Dec 2007 07:51:33 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=8</guid>
		<description><![CDATA[Adobe a annoncé au début du mois la mise à disposition de Flash Player 9 Update 3. Les améliorations : Support des standards, H.264 et HE-AAC, pour l'audio/vidéo HD Vidéo...]]></description>
			<content:encoded><![CDATA[<h4>Adobe a annoncé au début du mois la mise à disposition de Flash Player 9 Update 3.</h4>
<h5>Les améliorations :</h5>
<ul>
<li> Support des standards, H.264 et HE-AAC, pour l'audio/vidéo HD</li>
<li>Vidéo plein écran pour la majorité des navigateurs et des OS</li>
<li>Support du multi-core pour améliorer les rendus</li>
<li>Support de l'accélératio matériel</li>
</ul>
<p>Téléchargez <a href="http://www.adobe.com/fr/products/flashplayer/" title="Flash Player 9">Flash Player 9 Update 3</a></p>
<p>;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/38-mise-jour-flash-player/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe Flash Player 10, codename &quot;Astro&quot;</title>
		<link>http://www.bases-as3.fr/36-flash-player-10-astro</link>
		<comments>http://www.bases-as3.fr/36-flash-player-10-astro#comments</comments>
		<pubDate>Fri, 12 Oct 2007 11:21:09 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=7</guid>
		<description><![CDATA[<h4>La prochaine version majeure de Flash Player, nom de code "Astro", a pu être aperçue lors de l'Adobe Max 2007</h4>]]></description>
			<content:encoded><![CDATA[<h4>La prochaine version majeure de Flash Player, nom de code "Astro", a pu être aperçue lors de l'Adobe Max 2007</h4>
<p><span id="more-7"></span></p>
<h5>Les nouvelles fonctionnalités :</h5>
<ul>
<li>Gestion avancée du texte :<br />
Prise en charge des langages bi-directionnels (Hébreu, Arabe...), présentation du texte sur plusieurs colonnes...</li>
<li>Effets 3D</li>
<li>Filtres et effets personnalisés</li>
</ul>
<p>Retrouvez Astro sur les labs d'Adobe :<br />
<a href="http://labs.adobe.com/wiki/index.php/Astro" hreflang="fr">Adobe Flash Player 10 : Astro</a></p>
<p>;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/36-flash-player-10-astro/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Affichage de la date et de l&#8217;heure</title>
		<link>http://www.bases-as3.fr/33-affichage-date-heure</link>
		<comments>http://www.bases-as3.fr/33-affichage-date-heure#comments</comments>
		<pubDate>Thu, 05 Apr 2007 22:05:49 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=6</guid>
		<description><![CDATA[<h4>Afficher la date et l'heure en ActionScript 3 (AS3)</h4> <p>La date et l'heure que calcule ActionScript sont basées sur le paramétrage de la date et l'heure de l'ordinateur du client.<br />
Nous allons utiliser la classe Date pour récupérer la date et l'heure.</p>]]></description>
			<content:encoded><![CDATA[<h4>Afficher la date et l'heure en ActionScript 3 (AS3)</h4>
<p>La date et l'heure que calcule ActionScript sont basées sur le paramétrage de la date et l'heure de l'ordinateur du client.<br />
Nous allons utiliser la classe Date pour récupérer la date et l'heure.</p>
<p><span id="more-6"></span></p>
<p>Nous utiliserons ensuites les propriétés de la classe Date pour récupérer l'année, le mois, le jour, l'heure, les minutes et les secondes. Cependant, le mois et le jour sont renvoyés en tant que valeurs numériques. Nous utiliserons donc des tableaux pour stockés les mois et les jours en tant que chaînes de caractères.</p>
<div class="igBar"><span id="lactionscript-15"><a href="#" onclick="javascript:showPlainTxt('actionscript-15'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-15">
<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;">const</span> MOIS:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Janvier"</span>, <span style="color: #ff0000;">"Février"</span>, <span style="color: #ff0000;">"Mars"</span>, <span style="color: #ff0000;">"Avril"</span>, <span style="color: #ff0000;">"Mai"</span>, <span style="color: #ff0000;">"Juin"</span>, <span style="color: #ff0000;">"Juillet"</span>, <span style="color: #ff0000;">"Août"</span>, <span style="color: #ff0000;">"Septembre"</span>, <span style="color: #ff0000;">"Octobre"</span>, <span style="color: #ff0000;">"Novembre"</span>, <span style="color: #ff0000;">"Décembre"</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;">const</span> JOURS:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Dimanche"</span>, <span style="color: #ff0000;">"Lundi"</span>, <span style="color: #ff0000;">"Mardi"</span>, <span style="color: #ff0000;">"Mercredi"</span>, <span style="color: #ff0000;">"Jeudi"</span>, <span style="color: #ff0000;">"Vendredi"</span>, <span style="color: #ff0000;">"Samedi"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
L'affichage se fera dans deux champs de texte dynamiques.</p>
<div class="igBar"><span id="lactionscript-16"><a href="#" onclick="javascript:showPlainTxt('actionscript-16'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-16">
<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> date_txt:<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>;</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>date_txt<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> heure_txt:<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>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">heure_txt.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">100</span>; addChild<span style="color: #66cc66;">&#40;</span>heure_txt<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Nous utiliserons un Timer pour mettre à jour l'affichage toutes les secondes. Une instance de la classe Date sera créée.<br />
Nous récupérerons l'année grâce à la propriété fullYear.<br />
Nous récupérerons le mois grâce à la propriété month. Cependant, cette propriété renvoie un nombre entre 0 (janvier) et 11 (décembre). Nous utiliserons donc ce nombre pour récupérer l'index correspondant dans le tableau des mois.<br />
Nous récupérerons le jour dans le mois grâce à la propriété date.<br />
Nous récupérerons le jour dans la semaine grâce à la propriété day. Cependant, cette propriété renvoie un nombre entre 0 (dimanche) et 6 (samedi). Nous utiliserons donc ce nombre pour récupérer l'index correspondant dans le tableau des jours.</p>
<div class="igBar"><span id="lactionscript-17"><a href="#" onclick="javascript:showPlainTxt('actionscript-17'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-17">
<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;">1000</span>, <span style="color: #cc66cc;color:#800000;">0</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//on souhaite exécuter une action toutes les 1000 millisecondes.</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 1000 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> onAffichage<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;<span style="color: #000000; font-weight: bold;">var</span> temps:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//création de l'instance de la classe Date</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: #000000; font-weight: bold;">var</span> annee:uint = temps.<span style="color: #006600;">fullYear</span>; <span style="color: #808080; font-style: italic;">//récupération de l'année</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> mois:<span style="color: #0066CC;">String</span> = MOIS<span style="color: #66cc66;">&#91;</span>temps.<span style="color: #006600;">month</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">//récupération du nom du mois dans le tableau MOIS</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: #000000; font-weight: bold;">var</span> numJour:uint = temps.<span style="color: #0066CC;">date</span>; <span style="color: #808080; font-style: italic;">//récupération du numéro du jour dans le mois</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> jour:<span style="color: #0066CC;">String</span> = JOURS<span style="color: #66cc66;">&#91;</span>temps.<span style="color: #006600;">day</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">//récupération du nom du jour dans le tableau JOURS</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;date_txt.<span style="color: #0066CC;">text</span> = jour + <span style="color: #ff0000;">" "</span> + numJour + <span style="color: #ff0000;">" "</span> + mois + <span style="color: #ff0000;">" "</span> + annee; <span style="color: #808080; font-style: italic;">//affichage du calendrier dans le champ de 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: #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;">myTimer.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span> TimerEvent.<span style="color: #006600;">TIMER</span>, onAffichage <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Toutes les 1000 millisecondes, le timer exécute l'événement TIMER et donc en réponse, la fonction onAffichage est exécutée.</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;">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>
</ol>
</div>
</div>
</div>
<p>
Afin d'avoir un affichage cohérent, nous allons devoir ajouter un 0 devant les heures, minutes et secondes inférieures à 10. Nous allons pour cela créer une fonction, qui retournera sous forme de chaîne de caractères l'affichage correct des heures, minutes et secondes.</p>
<div class="igBar"><span id="lactionscript-18"><a href="#" onclick="javascript:showPlainTxt('actionscript-18'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-18">
<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> reglage<span style="color: #66cc66;">&#40;</span> valeur:uint <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</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;">&nbsp;&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> retour:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">""</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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>valeur&lt;<span style="color: #cc66cc;color:#800000;">10</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;">&nbsp; &nbsp; &nbsp; &nbsp; <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;&nbsp; &nbsp;retour = <span style="color: #ff0000;">"0"</span>+valeur;</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: #66cc66;">&#125;</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: #b1b100;">else</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: #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;&nbsp; &nbsp;retour = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>valeur<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;">&nbsp;&nbsp; &nbsp;<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;">&nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">return</span> retour;</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>
</ol>
</div>
</div>
</div>
<p>
Dans la fonction onAffichage, nous récupérerons les heures grâce à la propriété hours.<br />
Nous récupérerons les minutes grâce à la propriété minutes.<br />
Nous récupérerons les secondes grâce à la propriété seconds.</p>
<div class="igBar"><span id="lactionscript-19"><a href="#" onclick="javascript:showPlainTxt('actionscript-19'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-19">
<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;">1000</span>, <span style="color: #cc66cc;color:#800000;">0</span> <span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//on souhaite exécuter une action toutes les 1000 millisecondes.</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 1000 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> onAffichage<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;<span style="color: #000000; font-weight: bold;">var</span> temps:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//création de l'instance de la classe Date</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: #000000; font-weight: bold;">var</span> annee:uint = temps.<span style="color: #006600;">fullYear</span>; <span style="color: #808080; font-style: italic;">//récupération de l'année</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> mois:<span style="color: #0066CC;">String</span> = MOIS<span style="color: #66cc66;">&#91;</span>temps.<span style="color: #006600;">month</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">//récupération du nom du mois dans le tableau MOIS</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: #000000; font-weight: bold;">var</span> numJour:uint = temps.<span style="color: #0066CC;">date</span>; <span style="color: #808080; font-style: italic;">//récupération du numéro du jour dans le mois</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> jour:<span style="color: #0066CC;">String</span> = JOURS<span style="color: #66cc66;">&#91;</span>temps.<span style="color: #006600;">day</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">//récupération du nom du jour dans le tableau JOURS</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;date_txt.<span style="color: #0066CC;">text</span> = jour + <span style="color: #ff0000;">" "</span> + numJour + <span style="color: #ff0000;">" "</span> + mois + <span style="color: #ff0000;">" "</span> + annee; <span style="color: #808080; font-style: italic;">//affichage du calendrier dans le champ de texte</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> heure:<span style="color: #0066CC;">String</span> = reglage<span style="color: #66cc66;">&#40;</span> temps.<span style="color: #006600;">hours</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//récupération et transformation éventuelle des heures</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: #000000; font-weight: bold;">var</span> minute:<span style="color: #0066CC;">String</span> = reglage<span style="color: #66cc66;">&#40;</span> temps.<span style="color: #006600;">minutes</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//récupération et transformation éventuelle des minutes</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> seconde:<span style="color: #0066CC;">String</span> = reglage<span style="color: #66cc66;">&#40;</span> temps.<span style="color: #006600;">seconds</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//récupération et transformation éventuelle des secondes &nbsp; &nbsp; heure_txt.texte = heure + &quot;:&quot; + minute + &quot;:&quot; + seconde;</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>, onAffichage <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Toutes les 1000 millisecondes, le timer exécute l'événement TIMER et donc en réponse, la fonction onAffichage 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;">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>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Le script complet :</h5>
<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;">const</span> MOIS:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Janvier"</span>, <span style="color: #ff0000;">"Février"</span>, <span style="color: #ff0000;">"Mars"</span>, <span style="color: #ff0000;">"Avril"</span>, <span style="color: #ff0000;">"Mai"</span>, <span style="color: #ff0000;">"Juin"</span>, <span style="color: #ff0000;">"Juillet"</span>, <span style="color: #ff0000;">"Août"</span>, <span style="color: #ff0000;">"Septembre"</span>, <span style="color: #ff0000;">"Octobre"</span>, <span style="color: #ff0000;">"Novembre"</span>, <span style="color: #ff0000;">"Décembre"</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;">const</span> JOURS:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Dimanche"</span>, <span style="color: #ff0000;">"Lundi"</span>, <span style="color: #ff0000;">"Mardi"</span>, <span style="color: #ff0000;">"Mercredi"</span>, <span style="color: #ff0000;">"Jeudi"</span>, <span style="color: #ff0000;">"Vendredi"</span>, <span style="color: #ff0000;">"Samedi"</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: #000000; font-weight: bold;">var</span> date_txt:<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>; addChild<span style="color: #66cc66;">&#40;</span>date_txt<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> heure_txt:<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>;</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;">heure_txt.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">100</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>heure_txt<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> reglage<span style="color: #66cc66;">&#40;</span> valeur:uint <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</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;">&nbsp;&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> retour:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">""</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: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>valeur&lt;<span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span> <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;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;retour = <span style="color: #ff0000;">"0"</span>+valeur;</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: #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;">&nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">else</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: #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;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;retour = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>valeur<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;">&nbsp;&nbsp; &nbsp;<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;">&nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">return</span> retour;</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;">&nbsp;<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;">1000</span>, <span style="color: #cc66cc;color:#800000;">0</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//on souhaite exécuter une action toutes les 1000 millisecondes. </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 1000 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> onAffichage<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;<span style="color: #000000; font-weight: bold;">var</span> temps:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//création de l'instance de la classe Date</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: #000000; font-weight: bold;">var</span> annee:uint = temps.<span style="color: #006600;">fullYear</span>; <span style="color: #808080; font-style: italic;">//récupération de l'année</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> mois:<span style="color: #0066CC;">String</span> = MOIS<span style="color: #66cc66;">&#91;</span>temps.<span style="color: #006600;">month</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">//récupération du nom du mois dans le tableau MOIS</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: #000000; font-weight: bold;">var</span> numJour:uint = temps.<span style="color: #0066CC;">date</span>; <span style="color: #808080; font-style: italic;">//récupération du numéro du jour dans le mois</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> jour:<span style="color: #0066CC;">String</span> = JOURS<span style="color: #66cc66;">&#91;</span>temps.<span style="color: #006600;">day</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">//récupération du nom du jour dans le tableau JOURS</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;date_txt.<span style="color: #0066CC;">text</span> = jour + <span style="color: #ff0000;">" "</span> + numJour + <span style="color: #ff0000;">" "</span> + mois + <span style="color: #ff0000;">" "</span> + annee; <span style="color: #808080; font-style: italic;">//affichage du calendrier dans le champ de texte</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> heure:<span style="color: #0066CC;">String</span> = reglage<span style="color: #66cc66;">&#40;</span> temps.<span style="color: #006600;">hours</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//récupération et transformation éventuelle des heures</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: #000000; font-weight: bold;">var</span> minute:<span style="color: #0066CC;">String</span> = reglage<span style="color: #66cc66;">&#40;</span> temps.<span style="color: #006600;">minutes</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//récupération et transformation éventuelle des minutes</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> seconde:<span style="color: #0066CC;">String</span> = reglage<span style="color: #66cc66;">&#40;</span> temps.<span style="color: #006600;">seconds</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//récupération et transformation éventuelle des secondes</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;heure_txt.<span style="color: #0066CC;">text</span> = heure + <span style="color: #ff0000;">":"</span> + minute + <span style="color: #ff0000;">":"</span> + seconde;</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;">myTimer.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span> TimerEvent.<span style="color: #006600;">TIMER</span>, onAffichage <span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Toutes les 1000 millisecondes, le timer exécute l'événement TIMER et donc en réponse, la fonction onAffichage est exécutée.</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;">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>
</ol>
</div>
</div>
</div>
<p>
;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/33-affichage-date-heure/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Déplacement d&#8217;un visuel avec les flèches du clavier</title>
		<link>http://www.bases-as3.fr/18-deplacement-d-un-visuel-avec-les-fleches-du-clavier</link>
		<comments>http://www.bases-as3.fr/18-deplacement-d-un-visuel-avec-les-fleches-du-clavier#comments</comments>
		<pubDate>Thu, 31 Aug 2006 12:07:23 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=4</guid>
		<description><![CDATA[<h4>Déplacer un dessin avec les flèches du clavier en ActionScript 3 (AS3)</h4> <p>Nous allons utiliser pour gérer le déplacement d'un objet, la classe KeyboardEvent. Nous verrons ici l'événement keyDown (l'appui sur une touche).<br />
Dans la fonction qui sera exécutée en réponse de l'événement, nous allons tester le code de la touche du clavier afin de définir les différentes interactions à réaliser.</p>]]></description>
			<content:encoded><![CDATA[<h4>Déplacer un dessin avec les flèches du clavier en ActionScript 3 (AS3)</h4>
<p>Nous allons utiliser pour gérer le déplacement d'un objet, la classe KeyboardEvent. Nous verrons ici l'événement keyDown (l'appui sur une touche).<br />
Dans la fonction qui sera exécutée en réponse de l'événement, nous allons tester le code de la touche du clavier afin de définir les différentes interactions à réaliser.</p>
<p><span id="more-4"></span></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: #808080; font-style: italic;">// Objet de dessin </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;"><span style="color: #808080; font-style: italic;">// Remplissage du rectangle avec du bleu </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: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x0000FF<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;">// Dessin du rectangle </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;">50</span>, <span style="color: #cc66cc;color:#800000;">200</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;">// Déplacement du rectangle à la souris </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> deplacement<span style="color: #66cc66;">&#40;</span>evt:<span style="color: #0066CC;">KeyboardEvent</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;">// Test de la touche utilisé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;">&nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span>evt.<span style="color: #006600;">keyCode</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;">&nbsp;&nbsp; &nbsp;<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;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// déplacement vers la gauche</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">case</span> Keyboard.<span style="color: #0066CC;">LEFT</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;&nbsp; &nbsp;&nbsp; &nbsp;evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</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;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">break</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;&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// déplacement vers le haut</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">case</span> Keyboard.<span style="color: #0066CC;">UP</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;&nbsp; &nbsp;&nbsp; &nbsp;evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</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;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">break</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;&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// déplacement vers la droite</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">case</span> Keyboard.<span style="color: #0066CC;">RIGHT</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;&nbsp; &nbsp;&nbsp; &nbsp;evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</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;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">break</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;&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// déplacement vers le bas</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">case</span> Keyboard.<span style="color: #0066CC;">DOWN</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;&nbsp; &nbsp;&nbsp; &nbsp;evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</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;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #b1b100;">break</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;&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// pas de déplacement</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">default</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;&nbsp; &nbsp;&nbsp; &nbsp;evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span>+=<span style="color: #cc66cc;color:#800000;">0</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: #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: #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;">// Affichage du rectangle </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>
<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;">// Focus sur le rectangle pour qu'il puisse être actif </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;">stage</span>.<span style="color: #006600;">stageFocusRect</span> = <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Le rectangle jaune du focus est supprimé pour tous les objets </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;">stage</span>.<span style="color: #006600;">focus</span> = rectangle; </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;">// Ecouteur de l'événement keyDown sur le rectangle </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: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">KeyboardEvent</span>.<span style="color: #006600;">KEY_DOWN</span>, deplacement<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/18-deplacement-d-un-visuel-avec-les-fleches-du-clavier/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

