03.07.2013 Views

Guide de reference du langage ActionScript 2.0 - PowWeb

Guide de reference du langage ActionScript 2.0 - PowWeb

Guide de reference du langage ActionScript 2.0 - PowWeb

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Renvoie<br />

Boolean - Si listener a été supprimé avec succès, la métho<strong>de</strong> renvoie true. Si listener n'a<br />

pas été supprimé avec succès (par exemple, parce que listener ne figurait pas dans la liste <strong>de</strong>s<br />

écouteurs <strong>de</strong> l'objet Key), la métho<strong>de</strong> renvoie false.<br />

Exemple<br />

L'exemple suivant déplace un clip intitulé car_mc à l'ai<strong>de</strong> <strong>de</strong>s flèches gauche et droite.<br />

L'écouteur est supprimé lorsque vous appuyez sur Echap et car_mc ne se déplace plus.<br />

var keyListener:Object = new Object();<br />

keyListener.onKeyDown = function() {<br />

switch (Key.getCo<strong>de</strong>()) {<br />

case Key.LEFT :<br />

car_mc._x -= 10;<br />

break;<br />

case Key.RIGHT :<br />

car_mc._x += 10;<br />

break;<br />

case Key.ESCAPE :<br />

Key.removeListener(keyListener);<br />

}<br />

};<br />

Key.addListener(keyListener);<br />

RIGHT (propriété Key.RIGHT)<br />

statique publique RIGHT : Number<br />

La valeur <strong>de</strong> co<strong>de</strong> correspondant à la flèche Droite (39).<br />

Disponibilité : <strong>ActionScript</strong> 1.0 ; Flash Player 5<br />

Exemple<br />

L'exemple suivant déplace un clip intitulé car_mc selon une distance constante (10) lorsque<br />

vous appuyez sur les touches fléchées. Un son est lu lorsque vous appuyez sur la barre d'espace.<br />

Pour cet exemple, affectez l'i<strong>de</strong>ntificateur <strong>de</strong> liaisonhorn_id à un son figurant dans la<br />

bibliothèque.<br />

var DISTANCE:Number = 10;<br />

var horn_sound:Sound = new Sound();<br />

horn_sound.attachSound("horn_id");<br />

var keyListener_obj:Object = new Object();<br />

keyListener_obj.onKeyDown = function() {<br />

switch (Key.getCo<strong>de</strong>()) {<br />

case Key.SPACE :<br />

horn_sound.start();<br />

break;<br />

Key 711

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!