<?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 dessins</title>
	<atom:link href="http://www.bases-as3.fr/category/dessins/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>L’API de dessin : les formes</title>
		<link>http://www.bases-as3.fr/api-dessin-forme</link>
		<comments>http://www.bases-as3.fr/api-dessin-forme#comments</comments>
		<pubDate>Mon, 07 Jul 2008 12:55:33 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les dessins]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/index.php/2008/07/07/api-dessin-forme</guid>
		<description><![CDATA[Dessiner des formes (rectangles, cercles, carrés...) en ActionScript 3 (AS3) L'ActionScript permet la création de dessin vectoriel. Contrairement à l'ActionScript 2, l'AS3 permet, en plus des lignes et des courbes,...]]></description>
			<content:encoded><![CDATA[<h4>Dessiner des formes (rectangles, cercles, carrés...) en ActionScript 3 (AS3)</h4>
<p>L'ActionScript permet la création de dessin vectoriel. Contrairement à l'ActionScript 2, l'AS3 permet, en plus des lignes et des courbes, de créer des formes (carré, rectangle, ellipse, cercle...) via des fonctionnalitées intégrées.Ces fonctionnalités sont appelées API de dessin et permettent de créer des dessins vectoriels.</p>
<p>Grâce à cette API de dessin, il vous sera possible de dessiner dynamiquement la forme de vos boutons, de présenter facilement des données numériques sous forme de graphiques...</p>
<p>L'ActionScript 3, à travers son lot de nouvelles classes, va vous permettre de séparer correctement les différents travaux de dessin que vous aurez à réaliser.</p>
<p><span id="more-60"></span></p>
<h5>La classe Graphics</h5>
<p>La classe de base du dessin vectoriel est la classe Graphics. Elle comporte des méthodes et des propriétés permettant de tracer des lignes, des remplissages et des formes.</p>
<p>Il est impossible d'instancier directement la classe Graphics. On utilisera la propriété graphics des objets d'affichage qui prennent en charge le dessin. Ces objets seront des objets de type Shape, Sprite ou des classes dérivées.</p>
<h4>La classe Shape</h4>
<p>La classe Shape sert à créer des formes simples via l'API de dessin. Cette classe comprend donc une propriété graphics qui vous permet d'accéder aux méthodes de dessin de la classe Graphics.</p>
<p>La classe Shape hérite de la classe DisplayObject, ce qui signifie qu'on ne pourra dessiner qu'une seule forme dans un objet de ce type. D'autre part, cette classe n'hérite pas de la classe InteractiveObject, ce qui signifie qu'il ne sera pas possible de définir des événements de souris ou de clavier sur ces objets.</p>
<h4>Dessiner un rectangle uni</h4>
<p>Le dessin d'un rectangle en ActionScript 3 va être réalisé en différentes étapes :</p>
<ol>
<li> Création d'une instance de type Shape</li>
<li> Définition du style de remplissage (couleur et opacité)</li>
<li> Dessin du rectangle</li>
<li> Affichage</li>
</ol>
<p>Les classes Shape et Graphics vont nous permettre de créer du dessin vectoriel en ActionScript.</p>
<h5>Création d'une instance de type Shape</h5>
<p>La classe Shape possède un constructeur qui ne prend aucun paramètre.</p>
<div class="igBar"><span id="lactionscript-30"><a href="#" onclick="javascript:showPlainTxt('actionscript-30'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-30">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> droite:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Définition du style de remplissage</h5>
<p>Avant de dessiner le rectangle, vous devez d'abord définir le style du remplissage (couleur, opacité...). C'est la méthode beginFill() de la classe Graphics qui va vous permettre de le faire.</p>
<p>1 seul paramètre de cette méthode est obligatoire, c'est la couleur du remplissage au format hexadécimal.</p>
<p>Nous allons définir un remplissage de couleur bleu clair et opaque. Nous appelerons la méthode beginFill() au travers de la propriété graphics de notre objet Shape.</p>
<div class="igBar"><span id="lactionscript-31"><a href="#" onclick="javascript:showPlainTxt('actionscript-31'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-31">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> rectangleUni:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleUni.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x86B1FB<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de bleu </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Dessin du rectangle</h5>
<p>Pour dessiner le rectangle, nous allons utiliser la méthode drawRect() de la classe Graphics. Cette méthode attend 4 paramètres (x, y, width, height) :</p>
<ul>
<li> x:Number - Nombre indiquant la position horizontale par rapport au point d'alignement de l'objet d'affichage parent (en pixels).</li>
<li>y:Number - Nombre indiquant la position verticale par rapport au point d'alignement de l'objet d'affichage parent (en pixels).</li>
<li>width:Number - Largeur du rectangle (en pixels).</li>
<li>height:Number - Hauteur du rectangle (en pixels).</li>
</ul>
<p>Nous allons dessiner un rectangle de 100 pixels de large par 30 pixels de haut, positionné en haut à gauche (0, 0) du shape.</p>
<div class="igBar"><span id="lactionscript-32"><a href="#" onclick="javascript:showPlainTxt('actionscript-32'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-32">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> rectangleUni:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleUni.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x86B1FB<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de 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;">rectangleUni.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height) </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Positionnement et affichage du rectangle dans la scène</h5>
<p>Comme tous les objets d'affichage, nous positionnerons notre rectangle avec les propriétés x et y et nous l'afficherons avec la méthode addChild() .</p>
<div class="igBar"><span id="lactionscript-33"><a href="#" onclick="javascript:showPlainTxt('actionscript-33'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-33">
<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> rectangleUni:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleUni.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x86B1FB<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de 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;">rectangleUni.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans 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;">rectangleUni.<span style="color: #006600;">x</span> = rectangleUni.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">50</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>rectangleUni<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/07/image1.png" alt="image1.png" /></p>
<h4>Dessiner un rectangle uni avec un contour</h4>
<p>Pour ajouter un contour à notre rectangle, nous allons utiliser la la méthode lineStyle() de la classe Graphics.</p>
<ul>
<li>1 seul paramètre de cette méthode est obligatoire, c'est la largeur du trait. Elle sera exprimée par un entier qui indique l'épaisseur de la ligne en points. Les valeurs possibles varient entre 0 et 255.</li>
<li>Le second paramètre, qui lui est facultatif, permet de définir la couleur de la ligne au format héxadécimal. Si aucune valeur n'est indiquée, la valeur par défaut est le noir (0x000000).</li>
<li>Le troisième paramètre, lui aussi facultatif, permet de définir l'opacité de la couleur de la ligne. Les valeurs varient entre 0 (transparent) et 1 (opaque). La valeur par défaut est 1.</li>
</ul>
<p>Nous allons définir un trait d'une épaisseur de 2 points, de couleur marine et opaque. Nous appelerons la méthode lineStyle() au travers de la propriété graphics de notre objet Shape.</p>
<div class="igBar"><span id="lactionscript-34"><a href="#" onclick="javascript:showPlainTxt('actionscript-34'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-34">
<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> rectangleUniContour:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleUniContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x86B1FB<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de 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;">rectangleUniContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>, 0x0040C4<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Un contour de 2 pixels et de couleur marine est utilisé</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleUniContour.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans la séquence</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleUniContour.<span style="color: #006600;">x</span> = rectangleUniContour.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">100</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>rectangleUniContour<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Dessiner un rectangle aux coins arrondis</h4>
<p>Pour dessiner un rectangle aux coins arrondis, on utilisera la méthode drawRoundRect() de la classe graphics à la place de la méthode drawRect().</p>
<p>Cette méthode prend 2 paramètres en plus : la largeur de l'arrondi et la hauteur de l'arrondi. Si la hauteur n'est pas spécifiée, elle prend la même valeur que la largeur.</p>
<p>Nous allons définir un arrondi d'angle homothétique de 30.</p>
<div class="igBar"><span id="lactionscript-35"><a href="#" onclick="javascript:showPlainTxt('actionscript-35'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-35">
<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> rectangleArrondi:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x86B1FB<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de 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;">rectangleArrondi.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>, 0x0040C4<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Un contour de 2 pixels et de couleur marine est utilisé</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans la séquence</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;color:#800000;">50</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;">rectangleArrondi.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">150</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>rectangleArrondi<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<img src="http://www.bases-as3.fr/wp-content/uploads/2008/07/image2.png" alt="image2.png" /><br />
En modifiant les 2 paramètres de l'arrondi, on peut créer différentes variantes.</p>
<div class="igBar"><span id="lactionscript-36"><a href="#" onclick="javascript:showPlainTxt('actionscript-36'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-36">
<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> rectangleArrondi:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x86B1FB<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de 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;">rectangleArrondi.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>, 0x0040C4<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Un contour de 2 pixels et de couleur marine est utilisé</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans la séquence</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;color:#800000;">50</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;">rectangleArrondi.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">150</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>rectangleArrondi<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;</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> rectangleArrondi2:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</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;">rectangleArrondi2.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x86B1FB<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de bleu</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi2.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>, 0x0040C4<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Un contour de 2 pixels et de couleur marine est utilisé</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;">rectangleArrondi2.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">10</span>, <span style="color: #cc66cc;color:#800000;">60</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans 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;">rectangleArrondi2.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;color:#800000;">50</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi2.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">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;">addChild<span style="color: #66cc66;">&#40;</span>rectangleArrondi2<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;</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> rectangleArrondi3:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi3.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x86B1FB<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de 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;">rectangleArrondi3.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>, 0x0040C4<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Un contour de 2 pixels et de couleur marine est utilisé</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi3.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">10</span>, <span style="color: #cc66cc;color:#800000;">20</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans la séquence</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleArrondi3.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;color:#800000;">50</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;">rectangleArrondi3.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">250</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>rectangleArrondi3<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<img src="http://www.bases-as3.fr/wp-content/uploads/2008/07/image3.png" alt="image3.png" /></p>
<h4>Dessiner un cercle</h4>
<p>Pour dessiner un cercle, on utilisera la méthode drawCircle() de la classe Graphics. Cette méthode attend 3 paramètres(x, y, radius) :</p>
<ul>
<li> x:Number - Coordonnée x du centre du cercle par rapport au point d'alignement de l'objet d'affichage parent (en pixels).</li>
<li> y:Number - Coordonnée y du centre du cercle par rapport au point d'alignement de l'objet d'affichage parent (en pixels).</li>
<li> radius:Number - Rayon du cercle (en pixels).</li>
</ul>
<p>Nous allons créer un cercle rouge transparent à 50%.</p>
<div class="igBar"><span id="lactionscript-37"><a href="#" onclick="javascript:showPlainTxt('actionscript-37'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-37">
<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> cercle:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cercle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xCF0903, <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">5</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Le cercle sera rempli de rouge, transparent à 50%</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;">cercle.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">25</span>, <span style="color: #cc66cc;color:#800000;">25</span>, <span style="color: #cc66cc;color:#800000;">25</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//dessin du cercle avec la méthode drawCircle(x, y, rayon)</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;">// Positionnement et affichage du cercle dans 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;">cercle.<span style="color: #006600;">x</span> = cercle.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">70</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>cercle<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Dessiner une ellipse</h4>
<p>Pour dessiner une ellipse, on utilisera la méthode drawEllipse() de la classe Graphics. Cette méthode attend 4 paramètres(x, y, width, height) :</p>
<ul>
<li> x:Number - Coordonnée x du centre de l'ovale par rapport au point d'alignement de l'objet d'affichage parent (en pixels).</li>
<li> y:Number - Coordonnée x du centre de l'ovale par rapport au point d'alignement de l'objet d'affichage parent (en pixels)</li>
<li> width:Number - Largeur de l'ellipse (en pixels)</li>
<li> height:Number - Hauteur de l'ellipse (en pixels)</li>
</ul>
<div class="igBar"><span id="lactionscript-38"><a href="#" onclick="javascript:showPlainTxt('actionscript-38'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-38">
<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> ellipse:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ellipse.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x46B504, <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">75</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//L'ellipse sera rempli de vert, transparent à 75%</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;">ellipse.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawEllipse</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">25</span>, <span style="color: #cc66cc;color:#800000;">25</span>, <span style="color: #cc66cc;color:#800000;">25</span>, <span style="color: #cc66cc;color:#800000;">40</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//dessin de l'ellipse avec la méthode drawEllipse(x, y, width, height)</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;">// Positionnement et affichage de l'ellipse dans 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;">ellipse.<span style="color: #006600;">x</span> = ellipse.<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>ellipse<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Dessiner une forme plus complexe</h4>
<p>Pour dessiner une forme plus complexe, nous allons créer une succession de droite ou de courbes.</p>
<p>http://wiki.mediabox.fr/tutoriaux/flash/api/courbes_droites</p>
<p>Nous allons créer un triangle avec un remplissage uni et un contour.</p>
<div class="igBar"><span id="lactionscript-39"><a href="#" onclick="javascript:showPlainTxt('actionscript-39'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-39">
<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> triangle:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">triangle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFFCC00<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Le triangle sera rempli de orange</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;">triangle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>, 0xCF0903<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Contour rouge de 2 pixels</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">triangle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">25</span>, <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Sommet du triangle</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;">triangle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><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: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//point bas droite</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">triangle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">50</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//point bas gauche</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;">triangle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">25</span>, <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//fermeture du tracé sur le point de départ</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;">// Positionnement et affichage du triangle dans 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;">triangle.<span style="color: #006600;">x</span> = triangle.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">150</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>triangle<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Utiliser un remplissage dégradé</h4>
<p>Jusqu'à présent, nous avons créé des remplissages utilisant des couleurs unies. La classe Graphics permet aussi de créer des dégradés.<br />
Nous allons pour cela utiliser la méthode beginGradientFill().<br />
La méthode beginGradientFill() reçoit 4 paramètres obligatoires : type, couleur, alpha et ratio des couleurs.</p>
<ul>
<li> Le premier paramètre spécifie le type de dégradé à créer. Les 2 valeurs possibles sont des constantes de la classe GradientType :  GradientType.LINEAR pour un dégradé linéaire et GradientType.RADIAL pour un dégradé radial.</li>
<li>Le second paramètre indique le tableau de valeurs colorimétriques à utiliser. Dans un dégradé linéaire, les couleurs sont organisées de gauche à droite. Dans un dégradé radial, les couleurs sont organisées de l'intérieur à l'extérieur. L'ordre des couleurs dans le tableau représente l'ordre dans lequel elles sont tracées dans le dégradé.</li>
<li>Le troisième paramètre indique les valeurs de transparence alpha pour les couleurs du tableau des couleurs.</li>
<li>Le quatrième paramètre spécifie les rapports, c'est-à-dire l'importance de chaque couleur dans le dégradé. La plage de valeurs possible va de 0 à 255. Ces valeurs représentent la position au sein du dégradé : 0 représente le début du dégradé, et 255 la fin. Cette plage de rapports doit augmenter séquentiellement et comporter le même nombre d'éléments que les tableaux des couleurs et des valeurs alpha spécifiés comme second et troisième paramètres.</li>
</ul>
<p>Nous allons créer un dégradé linéaire de trois couleurs : rouge au début (0xCF0903), orange au milieu (0xFFCC00) et vert à la fin (0x46B504).<br />
Les trois couleurs seront opaques : [1, 1, 1].</p>
<p>Les couleurs ne seront pas réparties de façon uniforme, le vert sera la couleur dominante. Le rouge démarrera à gauche (0), le vert sera à droite du dégradé (255) et le orange sera au ¼ du dégradé (100). [0, 100, 255]</p>
<div class="igBar"><span id="lactionscript-40"><a href="#" onclick="javascript:showPlainTxt('actionscript-40'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-40">
<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> rectangleDegrade:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginGradientFill</span><span style="color: #66cc66;">&#40;</span>GradientType.<span style="color: #006600;">LINEAR</span>, <span style="color: #66cc66;">&#91;</span>0xCF0903, 0xFFCC00, 0x46B504<span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">255</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli avec un dégradé</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;">rectangleDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans 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;">rectangleDegrade.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;color:#800000;">200</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleDegrade.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">50</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>rectangleDegrade<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/07/image4.png" alt="image4.png" /></p>
<p>Nous remarquons que par défaut le dégradé n'est pas étiré sur la largeur de la ligne. Pour remédier à ce problème, nous allons définir le 5ème paramètre de la méthode.</p>
<p>Ce paramètre défini une matrice de transformation du dégradé et accepte une instance de la classe Matrix.</p>
<h5>Création d'un objet de type Matrix pour le dégradé</h5>
<p>La classe Matrix représente une matrice de transformation que l'on peut utiliser pour appliquer diverses transformations graphiques à un objet d'affichage.</p>
<div class="igBar"><span id="lactionscript-41"><a href="#" onclick="javascript:showPlainTxt('actionscript-41'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-41">
<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> matrice :Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> ;<span style="color: #808080; font-style: italic;">//matrice de transformation du dégradé </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Nous allons ensuite utiliser la méthode createGradientBox() de la classe Matrix pour définir la largeur et la hauteur du dégradé. Nous allons définir la largeur du dégradé sur 100, valeur correspondant à la largeur du rectangle et la hauteur sur 30, valeur correspondant à la hauteur du rectangle.</p>
<div class="igBar"><span id="lactionscript-42"><a href="#" onclick="javascript:showPlainTxt('actionscript-42'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-42">
<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;">matrice.<span style="color: #006600;">createGradientBox</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//largeur et épaisseur du dégradé </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>L'objet de type Matrix est ensuite passé en tant que 5ème paramètre de la méthode beginGradientFill().</p>
<div class="igBar"><span id="lactionscript-43"><a href="#" onclick="javascript:showPlainTxt('actionscript-43'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-43">
<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> rectangleDegrade:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</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> matrice:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Matrice de transformation du dégradé</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;">matrice.<span style="color: #006600;">createGradientBox</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//largeur et épaisseur du dégradé</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginGradientFill</span><span style="color: #66cc66;">&#40;</span>GradientType.<span style="color: #006600;">LINEAR</span>, <span style="color: #66cc66;">&#91;</span>0xCF0903, 0xFFCC00, 0x46B504<span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">255</span><span style="color: #66cc66;">&#93;</span>, matrice<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli avec un dégradé</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;">rectangleDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans 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;">rectangleDegrade.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;color:#800000;">200</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleDegrade.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">50</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>rectangleDegrade<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/07/image5.png" alt="image5.png" /></p>
<p>Nous pouvons contrôler l'angle du dégradé grâce au troisième paramètre de la méthode createGradientBox().</p>
<div class="igBar"><span id="lactionscript-44"><a href="#" onclick="javascript:showPlainTxt('actionscript-44'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-44">
<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> rectangleDegrade:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</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> matrice:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Matrice de transformation du dégradé</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;">matrice.<span style="color: #006600;">createGradientBox</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">45</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//largeur et épaisseur du dégradé</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginGradientFill</span><span style="color: #66cc66;">&#40;</span>GradientType.<span style="color: #006600;">LINEAR</span>, <span style="color: #66cc66;">&#91;</span>0xCF0903, 0xFFCC00, 0x46B504<span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">255</span><span style="color: #66cc66;">&#93;</span>, matrice<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Le rectangle sera rempli avec un dégradé</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;">rectangleDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><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: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// dessin du rectangle avec la méthode drawRect(x, y, width, height)</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;">// Positionnement et affichage du rectangle dans 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;">rectangleDegrade.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;color:#800000;">200</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleDegrade.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">50</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>rectangleDegrade<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/07/image6.png" alt="image6.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/api-dessin-forme/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>L’API de dessin : les droites et les courbes</title>
		<link>http://www.bases-as3.fr/api-dessin-droites-courbes</link>
		<comments>http://www.bases-as3.fr/api-dessin-droites-courbes#comments</comments>
		<pubDate>Wed, 11 Jun 2008 00:38:57 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les dessins]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/index.php/2008/06/11/api-dessin-droites-courbes</guid>
		<description><![CDATA[Dessiner des droites et des courbes avec l'API de dessin en ActionScript 3 (AS3). L'ActionScript permet la création de dessin vectoriel. Contrairement à l'ActionScript 2, l'AS3 permet, en plus des...]]></description>
			<content:encoded><![CDATA[<h3>Dessiner des droites et des courbes avec l'API de dessin en ActionScript 3 (AS3).</h3>
<p>L'ActionScript permet la création de dessin vectoriel. Contrairement à l'ActionScript 2, l'AS3 permet, en plus des lignes et des courbes, de créer des formes (carré, rectangle, ellipse, cercle...) via des fonctionnalitées intégrées.</p>
<p>Ces fonctionnalités sont appelées API de dessin et permettent de créer des dessins vectoriels.</p>
<p>Grâce à cette API de dessin, il vous sera possible de dessiner dynamiquement la forme de vos boutons, de présenter facilement des données numériques sous forme de graphiques...</p>
<p>L'ActionScript 3, à travers son lot de nouvelles classes, va vous permettre de séparer correctement les différents travaux de dessin que vous aurez à réaliser.</p>
<p><span id="more-53"></span></p>
<h4>La classe Graphics</h4>
<p>La classe de base du dessin vectoriel est la classe Graphics. Elle comporte des méthodes et des propriétés permettant de tracer des lignes, des remplissages et des formes.</p>
<p>Il est impossible d'instancier directement la classe Graphics. On utilisera la propriété graphics des objets d'affichage qui prennent en charge le dessin. Ces objets seront des objets de type Shape, Sprite ou des classes dérivées.</p>
<h4>La classe Shape</h4>
<p>La classe Shape sert à créer des formes simples via l'API de dessin. Cette classe comprend donc une propriété graphics qui vous permet d'accéder aux méthodes de dessin de la classe Graphics.</p>
<p>La classe Shape hérite de la classe DisplayObject, ce qui signifie qu'on ne pourra dessiner qu'une seule forme dans un objet de ce type. D'autre part, cette classe n'hérite pas de la classe InteractiveObject, ce qui signifie qu'il ne sera pas possible de définir des événements de souris ou de clavier sur ces objets.</p>
<h4>Dessiner un droite</h4>
<p>Le dessin d'une droite en ActionScript 3 va être réalisé en différentes étapes :</p>
<ul>
<li>Création d'une instance de type Shape</li>
<li>Définition du style de trait (épaisseur de ligne, couleur de ligne et opacité)</li>
<li>Déplacement de la position de dessin vers les coordonnées initiales de la droite</li>
<li>Dessin de la droite entre la position initiale et la position finale</li>
</ul>
<p>Les classes Shape et Graphics vont nous permettre de créer du dessin vectoriel en ActionScript.</p>
<h5>Création d'une instance de type Shape</h5>
<p>La classe Shape possède un constructeur qui ne prend aucun paramètre.</p>
<div class="igBar"><span id="lactionscript-57"><a href="#" onclick="javascript:showPlainTxt('actionscript-57'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-57">
<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> droite:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Définition du style de trait</h5>
<p>Avant de dessiner la droite, vous devez d'abord définir le style du trait (épaisseur, couleur, opacité...).</p>
<p>C'est la méthode lineStyle() de la classe Graphics qui va vous permettre de le faire.</p>
<ul>
<li>1 seul paramètre de cette méthode est obligatoire, c'est la largeur du trait. Elle sera exprimée par un entier qui indique l'épaisseur de la ligne en points. Les valeurs possibles varient entre 0 et 255.</li>
<li>Le second paramètre, qui lui est facultatif, permet de définir la couleur de la ligne au format héxadécimal. Si aucune valeur n'est indiquée, la valeur par défaut est le noir (0x000000).</li>
<li>Le troisième paramètre, lui aussi facultatif, permet de définir l'opacité de la couleur de la ligne. Les valeurs varient entre 0 (transparent) et 1 (opaque). La valeur par défaut est 1.</li>
</ul>
<p>Nous allons définir un trait d'une épaisseur de 20 points, de couleur rouge et opaque.</p>
<p>Nous appelerons la méthode lineStyle() au travers de la propriété graphics de notre objet Shape.</p>
<div class="igBar"><span id="lactionscript-58"><a href="#" onclick="javascript:showPlainTxt('actionscript-58'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-58">
<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> droite:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span>, 0xFF0000<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Déplacement de la position de dessin vers les coordonnées initiales de la droite</h5>
<p>Nous allons déplacer la position de dessin en utilisant la méthode moveTo() de la classe Graphics.</p>
<p>Cette méthode prend paramètres 2 nombres indiquant la position horizontale et verticale par rapport au point d'alignement de l'objet d'affichage parent.</p>
<div class="igBar"><span id="lactionscript-59"><a href="#" onclick="javascript:showPlainTxt('actionscript-59'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-59">
<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> droite:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span>, 0xFF0000<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait</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;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><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;">// Coordonnées initiales de la droite par rapport au point d'alignement de l'objet d'affichage </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Dessin de la droite entre la position initiale et la position finale</h5>
<p>Pour dessiner la droite, nous allons utiliser la méthode lineTo() de la classe Graphics.</p>
<p>Cette méthode trace une ligne entre la position de dessin actuelle (dans notre cas, définie par la méthode moveTo) et la position (x, y), passée en paramètre de cette méthode.  Une fois la ligne tracée, la position de dessin actuelle est réglée sur les coordonnées passées en paramètres.</p>
<div class="igBar"><span id="lactionscript-60"><a href="#" onclick="javascript:showPlainTxt('actionscript-60'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-60">
<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> droite:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span>, 0xFF0000<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait</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;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><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;">// Coordonnées initiales de la droite par rapport au point d'alignement de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Coordonnées finales de la droite par rapport au point d'alignement de l'objet d'affichage </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Positionnement et affichage de la droite dans la scène</h5>
<p>Comme tous les objets d'affichage, nous positionnerons notre droite avec les propriétés x et y et nous l'afficherons avec la méthode addChild() .</p>
<div class="igBar"><span id="lactionscript-61"><a href="#" onclick="javascript:showPlainTxt('actionscript-61'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-61">
<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> droite:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span>, 0xFF0000<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait</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;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><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;">// Coordonnées initiales de la droite par rapport au point d'alignement de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Coordonnées finales de la droite par rapport au point d'alignement de l'objet d'affichage</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;">droite.<span style="color: #006600;">x</span> = droite.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">20</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>droite<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/06/image1.png" alt="image1.png" /></p>
<h4>Extrémité des lignes</h4>
<p>On remarque que par défaut les extrémités de la droite sont arrondies.</p>
<p>Grâce au paramètre caps (6<sup>ème</sup> paramètre) de la méthode lineStyle(), nous allons pouvoir contrôler les extrémités de la droite.</p>
<p>Nous allons utiliser la classe CapsStyle pour définir le style des extrémités. Cette classe est une énumération de valeurs constantes qui spécifient le style d'extrémité à utiliser pour tracer les lignes.</p>
<p>Ces constantes sont utilisées en tant que valeurs du paramètre caps dans la méthode lineStyle().</p>
<p>Vous pouvez spécifier les trois types d'extrémités suivants :</p>
<ul>
<li>CapsStyle.NONE : aucunes extrémités</li>
<li>CapsStyle.ROUND : extrémités rondes</li>
<li>CapsStyle.SQUARE : extrémités carrées</li>
</ul>
<p>Le 4<sup>ème</sup> et 5<sup>ème</sup> paramètre ne vont pas nous concernés par l'instant, nous allons donc utiliser leur valeur par défaut.  Nous allons définir pour notre droite des extrémités carrées.</p>
<div class="igBar"><span id="lactionscript-62"><a href="#" onclick="javascript:showPlainTxt('actionscript-62'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-62">
<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;">droite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span>, 0xFF0000, <span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #000000; font-weight: bold;">false</span>, LineScaleMode.<span style="color: #006600;">NORMAL</span>, CapsStyle.<span style="color: #006600;">SQUARE</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Dessiner une courbe</h4>
<p>Nous avons vu que la méthode lineStyle() permettait de dessiner une droite. Dès lors que vous allez vouloir dessiner une courbe, vous devrez utiliser la méthode curveTo() de la classe Graphics.</p>
<p>La méthode curveTo() dessine une courbe de Bézier. Elle trace un arc entre deux points (appelés points d'ancrage) courbé en direction d'un troisième point (appelé point de contrôle).</p>
<p>Le premier point d'ancrage est défini par la position actuelle du dessin. Le point de contrôle et le second point d'ancrage sont définis en tant que paramètres de la méthode curveTo().</p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/06/image2.png" alt="image2.png" /></p>
<div class="igBar"><span id="lactionscript-63"><a href="#" onclick="javascript:showPlainTxt('actionscript-63'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-63">
<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> courbe:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">courbe.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span>, 0x34ABE4, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait</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;">courbe.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><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;">// Coordonnées initiales de la courbe par rapport au point d'alignement de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">courbe.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">curveTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">50</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Coordonnées du point de contrôle et du second point d'ancrage</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;">courbe.<span style="color: #006600;">x</span> = courbe.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">70</span>;<span style="color: #808080; font-style: italic;">//Positionnement de la courbe</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>courbe<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// affichage de la courbe </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>Dessiner une ligne dégradée</h4>
<p>Jusqu'à présent, nous avons créé des lignes ou des courbes en utilisant des couleurs unies. La classe Graphics permet aussi de créer des dégradés.</p>
<p>Nous allons pour cela utiliser la lineGradientStyle() après la méthode lineStyle(). En effet, la méthode lineGradientStyle() ne défini pas l'épaisseur du trait, c'est la méthode lineStyle() qui le gère.</p>
<p>La méthode lineGradientStyle() reçoit 4 paramètres obligatoires : type, couleur, alpha et ratio des couleurs.</p>
<ul>
<li>Le premier paramètre spécifie le type de dégradé à créer. Les 2 valeurs possibles sont des constantes de la classe GradientType :  GradientType.LINEAR pour un dégradé linéaire et GradientType.RADIAL pour un dégradé radial.</li>
<li>Le second paramètre indique le tableau de valeurs colorimétriques à utiliser. Dans un dégradé linéaire, les couleurs sont organisées de gauche à droite. Dans un dégradé radial, les couleurs sont organisées de l'intérieur à l'extérieur. L'ordre des couleurs dans le tableau représente l'ordre dans lequel elles sont tracées dans le dégradé.</li>
<li>Le troisième paramètre indique les valeurs de transparence alpha pour les couleurs du tableau des couleurs.</li>
<li>Le quatrième paramètre spécifie les rapports, c'est-à-dire l'importance de chaque couleur dans le dégradé. La plage de valeurs possible va de 0 à 255. Ces valeurs représentent la position au sein du dégradé : 0 représente le début du dégradé, et 255 la fin. Cette plage de rapports doit augmenter séquentiellement et comporter le même nombre d'éléments que les tableaux des couleurs et des valeurs alpha spécifiés comme second et troisième paramètres.</li>
</ul>
<p>Nous allons créer un dégradé linéaire de trois couleurs : vert au début (0x00FF00), blanc au milieu (0xFFFFFF) et bleu marine à la fin (0x000088).</p>
<p>Le vert et le bleu seront opaque et le blanc aura une transparence de 50% : [1, 0.5, 1].</p>
<p>Les couleurs ne seront pas réparties de façon uniforme, le vert sera la couleur dominante. Le vert démarrera à gauche (0), le bleu sera à droite du dégradé (255) et le blanc sera au ¾ du dégradé (190). [0, 190, 255]</p>
<div class="igBar"><span id="lactionscript-64"><a href="#" onclick="javascript:showPlainTxt('actionscript-64'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-64">
<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> droiteDegrade:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait</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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">lineGradientStyle</span><span style="color: #66cc66;">&#40;</span>GradientType.<span style="color: #006600;">LINEAR</span>, <span style="color: #66cc66;">&#91;</span>0x00FF00, 0xFFFFFF, 0x000088<span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">190</span>, <span style="color: #cc66cc;color:#800000;">255</span><span style="color: #66cc66;">&#93;</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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><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;">// Coordonnées initiales de la droite par rapport au point d'alignement de l'objet d'affichage</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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">50</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Coordonnées finales de la droite par rapport au point d'alignement de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droiteDegrade.<span style="color: #006600;">x</span> = droiteDegrade.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">30</span>;<span style="color: #808080; font-style: italic;">//Positionnement de la droite</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>droiteDegrade<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// affichage de la droite </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/06/image3.png" alt="image3.png" /></p>
<p>Nous remarquons que par défaut le dégradé n'est pas étiré sur la largeur de la ligne. Pour remédier à ce problème, nous allons définir le 5<sup>ème</sup> paramètre de la méthode.</p>
<p>Ce paramètre défini une matrice de transformation du dégradé et accepte une instance de la classe Matrix.</p>
<h4>Création d'un objet de type Matrix pour le dégradé</h4>
<p>La classe Matrix représente une matrice de transformation que l'on peut utiliser pour appliquer diverses transformations graphiques à un objet d'affichage.</p>
<div class="igBar"><span id="lactionscript-65"><a href="#" onclick="javascript:showPlainTxt('actionscript-65'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-65">
<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> matrice :Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> ;<span style="color: #808080; font-style: italic;">//matrice de transformation du dégradé </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Nous allons ensuite utiliser la méthode createGradientBox() de la classe Matrix pour définir la largeur et la hauteur du dégradé.</p>
<p>Nous allons définir la largeur du dégradé sur 200, valeur correspondant à la largeur de la ligne et la hauteur sur 20, valeur correspondant à l'épaisseur de la ligne.</p>
<div class="igBar"><span id="lactionscript-66"><a href="#" onclick="javascript:showPlainTxt('actionscript-66'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-66">
<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;">matrice.<span style="color: #006600;">createGradientBox</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">20</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//largeur et épaisseur du dégradé </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>L'objet de type Matrix est ensuite passé en tant que 5<sup>ème</sup> paramètre de la méthode lineGradientStyle().</p>
<div class="igBar"><span id="lactionscript-67"><a href="#" onclick="javascript:showPlainTxt('actionscript-67'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-67">
<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> droiteDegrade:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait</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> matrice:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Matrice de transformation du dégradé</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">matrice.<span style="color: #006600;">createGradientBox</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">20</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//largeur et épaisseur du dégradé</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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">lineGradientStyle</span><span style="color: #66cc66;">&#40;</span>GradientType.<span style="color: #006600;">LINEAR</span>, <span style="color: #66cc66;">&#91;</span>0x00FF00, 0xFFFFFF, 0x000088<span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">190</span>, <span style="color: #cc66cc;color:#800000;">255</span><span style="color: #66cc66;">&#93;</span>, matrice<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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><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;">// Coordonnées initiales de la droite par rapport au point d'alignement de l'objet d'affichage</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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">50</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Coordonnées finales de la droite par rapport au point d'alignement de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droiteDegrade.<span style="color: #006600;">x</span> = droiteDegrade.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">30</span>;<span style="color: #808080; font-style: italic;">//Positionnement de la droite</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>droiteDegrade<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// affichage de la droite </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/06/image4.png" alt="image4.png" /></p>
<p>Nous pouvons contrôler l'angle du dégradé grâce au troisième paramètre de la méthode createGradientBox().</p>
<div class="igBar"><span id="lactionscript-68"><a href="#" onclick="javascript:showPlainTxt('actionscript-68'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-68">
<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> droiteDegrade:<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>;<span style="color: #808080; font-style: italic;">// Instance de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">20</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// Style du trait</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> matrice:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Matrice de transformation du dégradé</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">matrice.<span style="color: #006600;">createGradientBox</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">20</span>, <span style="color: #cc66cc;color:#800000;">45</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//largeur et épaisseur du dégradé</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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">lineGradientStyle</span><span style="color: #66cc66;">&#40;</span>GradientType.<span style="color: #006600;">LINEAR</span>, <span style="color: #66cc66;">&#91;</span>0x00FF00, 0xFFFFFF, 0x000088<span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">190</span>, <span style="color: #cc66cc;color:#800000;">255</span><span style="color: #66cc66;">&#93;</span>, matrice<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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><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;">// Coordonnées initiales de la droite par rapport au point d'alignement de l'objet d'affichage</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;">droiteDegrade.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #cc66cc;color:#800000;">50</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Coordonnées finales de la droite par rapport au point d'alignement de l'objet d'affichage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">droiteDegrade.<span style="color: #006600;">x</span> = droiteDegrade.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">30</span>;<span style="color: #808080; font-style: italic;">//Positionnement de la droite</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>droiteDegrade<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// affichage de la droite </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><img src="http://www.bases-as3.fr/wp-content/uploads/2008/06/image5.png" alt="image5.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/api-dessin-droites-courbes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>La classe Sprite</title>
		<link>http://www.bases-as3.fr/20-la-classe-shape</link>
		<comments>http://www.bases-as3.fr/20-la-classe-shape#comments</comments>
		<pubDate>Thu, 31 Aug 2006 11:24:52 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les dessins]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=31</guid>
		<description><![CDATA[<h4>Créer un conteneur d'objets visuels</h4> <p>Nous avons vu dans un billet précédent l'utilisation des classes Shape et Graphics pour faire du dessin vectoriel.<br />
La classe Sprite va nous permettre de réaliser la même chose à la différence qu'un objet de type Sprite pourra contenir plusieurs dessins de type Shape. En effet, cette classe est similaire à la classe MovieClip mais elle ne possède pas de timeline.<br />
D'autre part, contrairement à la classe Shape, la classe Sprite possède des événements utilisateurs (souris, clavier...)</p>]]></description>
			<content:encoded><![CDATA[<h4>Créer un conteneur d'objets visuels</h4>
<p>Nous avons vu dans un billet précédent l'utilisation des classes Shape et Graphics pour faire du dessin vectoriel.<br />
La classe Sprite va nous permettre de réaliser la même chose à la différence qu'un objet de type Sprite pourra contenir plusieurs dessins de type Shape. En effet, cette classe est similaire à la classe MovieClip mais elle ne possède pas de timeline.<br />
D'autre part, contrairement à la classe Shape, la classe Sprite possède des événements utilisateurs (souris, clavier...)</p>
<p><span id="more-31"></span></p>
<div class="igBar"><span id="lactionscript-69"><a href="#" onclick="javascript:showPlainTxt('actionscript-69'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-69">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// création de l'instance du 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> rectangleBleu:<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;"><span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de bleu </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleBleu.<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 avec la méthode drawRect(x, y, width, height) </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleBleu.<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;">30</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;">// création de l'instance du carré rouge </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> carreRouge:<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;"><span style="color: #808080; font-style: italic;">// Le carre sera rempli de rouge </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">carreRouge.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFF0000<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 avec la méthode drawRect(x, y, width, height) </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">carreRouge.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">120</span>, <span style="color: #cc66cc;color:#800000;">50</span>, <span style="color: #cc66cc;color:#800000;">50</span>, <span style="color: #cc66cc;color:#800000;">50</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;">/* Ces 2 formes seront assemblées pour ne former qu'un seul visuel, on va donc créer le conteneur */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> logo:<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;">// Ajout des formes dans le logo </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">logo.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangleBleu<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;">logo.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>carreRouge<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;">// Evénement click du logo </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> clicLogo<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;">&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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Evénement survol du logo </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> survolLogo<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 logo 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;">logo.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">MouseEvent</span>.<span style="color: #006600;">CLICK</span>, clicLogo<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;">// Evénement survol du logo 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;">logo.<span style="color: #0066CC;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">MouseEvent</span>.<span style="color: #006600;">MOUSE_OVER</span>, survolLogo<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;">// affichage du logo dans 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>logo<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/20-la-classe-shape/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Les méthodes de dessin de la classe Graphics</title>
		<link>http://www.bases-as3.fr/8-les-methodes-de-dessin-de-la-classe-graphics</link>
		<comments>http://www.bases-as3.fr/8-les-methodes-de-dessin-de-la-classe-graphics#comments</comments>
		<pubDate>Thu, 20 Jul 2006 15:04:37 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les dessins]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=30</guid>
		<description><![CDATA[<h4>Créer des dessins vectoriels dans Flash en ActionScript 3 (AS3)</h4> <p>Nous allons étudier les différentes méthodes de la classe Graphics afin de créer en AS3, des rectangles, des carrés, des ellipses. On affectera à ces dessins, un remplissage ou un contour.</p>]]></description>
			<content:encoded><![CDATA[<h4>Créer des dessins vectoriels dans Flash en ActionScript 3 (AS3)</h4>
<p>Nous allons étudier les différentes méthodes de la classe Graphics afin de créer en AS3, des rectangles, des carrés, des ellipses. On affectera à ces dessins, un remplissage ou un contour.</p>
<p><span id="more-30"></span></p>
<p>N'hésitez par à relire l'article sur les classes <a href="http://www.bases-as3.fr/index.php/2006/07/11/4-shape-et-graphics" hreflang="fr">Shape et Graphics</a>.</p>
<p>Pour créer un rectangle, nous utilisons la méthode drawRect().<br />
Pour créer un rectangle aux coins arrondis, nous utilisons la méthode drawRoundRect().<br />
Pour créer un cercle, nous utilisons la méthode drawCircle().<br />
Pour créer une ellipse, nous utilisons la méthode drawEllipse().</p>
<h5>Dessins avec un remplissage</h5>
<p>Le remplissage se fait avec ma méthode beginFill().</p>
<div class="igBar"><span id="lactionscript-70"><a href="#" onclick="javascript:showPlainTxt('actionscript-70'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-70">
<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;">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: #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;">// rectangle bleu aux coins arrondis </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> rectangleRond:<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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleRond.<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;">rectangleRond.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">40</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">30</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangleRond<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;">// cercle 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> cercle:<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;">cercle.<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;">cercle.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">55</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">25</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>cercle<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;">// ellipse bleue </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> ellipse:<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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ellipse.<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;">ellipse.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawEllipse</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">5</span>, <span style="color: #cc66cc;color:#800000;">130</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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>ellipse<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;">// carre 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> carre:<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;">carre.<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;">carre.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">165</span>, <span style="color: #cc66cc;color:#800000;">50</span>, <span style="color: #cc66cc;color:#800000;">50</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>carre<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Dessins avec un remplissage et un contour</h5>
<p>Le remplissage se fait avec ma méthode beginFill() et le contour avec la méthode lineStyle().</p>
<div class="igBar"><span id="lactionscript-71"><a href="#" onclick="javascript:showPlainTxt('actionscript-71'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-71">
<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 jaune avec un contour rouge </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> rectangleContour:<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;">rectangleContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFFFF00<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;">rectangleContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0XFF0000<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;">rectangleContour.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">150</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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangleContour<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 jaune aux coins arrondis avec un contour rouge </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> rectangleRondContour:<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;">rectangleRondContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFFFF00<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;">rectangleRondContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0XFF0000<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;">rectangleRondContour.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">150</span>, <span style="color: #cc66cc;color:#800000;">40</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">30</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangleRondContour<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;">// cercle jaune avec un contour rouge </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> cercleContour:<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;">cercleContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFFFF00<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;">cercleContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0XFF0000<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;">cercleContour.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">205</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">25</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>cercleContour<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;">// ellipse jaune avec un contour rouge </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> ellipseContour:<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;">ellipseContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFFFF00<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;">ellipseContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0XFF0000<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;">ellipseContour.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawEllipse</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">150</span>, <span style="color: #cc66cc;color:#800000;">130</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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>ellipseContour<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;">// carre jaune avec un contour rouge </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> carreContour:<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;">carreContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFFFF00<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;">carreContour.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0XFF0000<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;">carreContour.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">175</span>, <span style="color: #cc66cc;color:#800000;">165</span>, <span style="color: #cc66cc;color:#800000;">50</span>, <span style="color: #cc66cc;color:#800000;">50</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>carreContour<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h5>Dessins avec un contour</h5>
<div class="igBar"><span id="lactionscript-72"><a href="#" onclick="javascript:showPlainTxt('actionscript-72'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-72">
<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 avec un contour 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> rectangleContourVert:<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;">rectangleContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0x00FF00<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;">rectangleContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">300</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangleContourVert<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;">// rectangle aux coins arrondis avec un contour 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: #000000; font-weight: bold;">var</span> rectangleRondContourVert:<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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rectangleRondContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0x00FF00<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;">rectangleRondContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">300</span>, <span style="color: #cc66cc;color:#800000;">40</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">30</span>, <span style="color: #cc66cc;color:#800000;">30</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangleRondContourVert<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;">// cercle avec un contour 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> cercleContourVert:<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;">cercleContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0x00FF00<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;">cercleContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">355</span>, <span style="color: #cc66cc;color:#800000;">100</span>, <span style="color: #cc66cc;color:#800000;">25</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>cercleContourVert<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;">// ellipse avec un contour 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: #000000; font-weight: bold;">var</span> ellipseContourVert:<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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ellipseContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0x00FF00<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;">ellipseContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawEllipse</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">300</span>, <span style="color: #cc66cc;color:#800000;">130</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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>ellipseContourVert<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;">// carre avec un contour 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> carreContourVert:<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;">carreContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span>,0x00FF00<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;">carreContourVert.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">325</span>, <span style="color: #cc66cc;color:#800000;">165</span>, <span style="color: #cc66cc;color:#800000;">50</span>, <span style="color: #cc66cc;color:#800000;">50</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: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>carreContourVert<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/8-les-methodes-de-dessin-de-la-classe-graphics/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Shape et Graphics</title>
		<link>http://www.bases-as3.fr/4-shape-et-graphics</link>
		<comments>http://www.bases-as3.fr/4-shape-et-graphics#comments</comments>
		<pubDate>Tue, 11 Jul 2006 10:04:29 +0000</pubDate>
		<dc:creator>tannoy</dc:creator>
				<category><![CDATA[Les dessins]]></category>

		<guid isPermaLink="false">http://www.bases-as3.fr/v2/?p=29</guid>
		<description><![CDATA[<h4>Créer un dessin vectoriel en ActionScript 3 (AS3)</h4> <p>Bonjour,</p> <p>Les classes Shape et Graphics vont nous permettre de créer du dessin vectoriel en ActionScript.</p> <p>La classe Shape est utilisée pour créer des formes simples.</p> <p>La classe Graphics ne possède pas de constructeur. C'est un ensemble de méthodes de dessin. Les méthodes de la classe Graphics seront appelées dans la propriété graphics de la classe Shape.</p>]]></description>
			<content:encoded><![CDATA[<h4>Créer un dessin vectoriel en ActionScript 3 (AS3)</h4>
<p>Bonjour,</p>
<p>Les classes Shape et Graphics vont nous permettre de créer du dessin vectoriel en ActionScript.</p>
<p>La classe Shape est utilisée pour créer des formes simples.</p>
<p>La classe Graphics ne possède pas de constructeur. C'est un ensemble de méthodes de dessin. Les méthodes de la classe Graphics seront appelées dans la propriété graphics de la classe Shape.</p>
<p><span id="more-29"></span></p>
<p>L'exemple suivant va nous permettre de dessiner un rectangle bleu nommé rectangle, positionné en x à 50 pixels, en y à 200 pixels, d'une largeur de 100 pixels et d'une hauteur de 30 pixels. Le positionnement se fait par rapport à l'élément parent dans lequel on affiche le rectangle via la méthode addChild.</p>
<div class="igBar"><span id="lactionscript-73"><a href="#" onclick="javascript:showPlainTxt('actionscript-73'); return false;">COPIER-COLLER</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-73">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// création de l'instance du 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;">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;"><span style="color: #808080; font-style: italic;">// Le rectangle sera rempli de 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 avec la méthode drawRect(x, y, width, height) </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;">// affichage du rectangle dans la séquence </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>rectangle<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bases-as3.fr/4-shape-et-graphics/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

