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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Exemple<br />

L'exemple suivant crée un nouvel objet écouteur et définit une fonction pour onKeyDown. La<br />

<strong>de</strong>rnière ligne utilise la métho<strong>de</strong> addListener() pour enregistrer l'écouteur auprès <strong>de</strong> l'objet<br />

Key afin qu'il puisse recevoir <strong>de</strong>s notifications émanant <strong>de</strong> l'événement <strong>de</strong> touche enfoncée.<br />

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

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

if (Key.isDown(Key.CAPSLOCK)) {<br />

trace("you pressed the Caps Lock key.");<br />

trace("\tCaps Lock == "+Key.isToggled(Key.CAPSLOCK));<br />

}<br />

};<br />

Key.addListener(keyListener);<br />

Les informations s'affichent dans le panneau <strong>de</strong> sortie lorsque vous appuyez sur la touche Verr<br />

Maj. Le panneau <strong>de</strong> sortie affiche la valeur true ou false selon l'activation, ou non, <strong>de</strong> la<br />

touche Verr Maj à l'ai<strong>de</strong> <strong>de</strong> la métho<strong>de</strong> isToggled.<br />

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

statique publique CONTROL : Number<br />

La valeur <strong>de</strong> co<strong>de</strong> correspondant à la touche Ctrl (17).<br />

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

Exemple<br />

L'exemple suivant affecte le raccourci clavier Ctrl+7 à un bouton dont le nom d'occurrence est<br />

my_btnet rend les informations sur le raccourci clavier disponibles pour les logiciels <strong>de</strong> lecture<br />

d'écran (consultez _accProps). Dans cet exemple, lorsque vous appuyez sur Ctrl+7, la<br />

fonction myOnPress affiche le texte hello dans le panneau <strong>de</strong> sortie.<br />

function myOnPress() {<br />

trace("hello");<br />

}<br />

function myOnKeyDown() {<br />

// 55 is key co<strong>de</strong> for 7<br />

if (Key.isDown(Key.CONTROL) && Key.getCo<strong>de</strong>() == 55) {<br />

Selection.setFocus(my_btn);<br />

my_btn.onPress();<br />

}<br />

}<br />

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

myListener.onKeyDown = myOnKeyDown;<br />

Key.addListener(myListener);<br />

my_btn.onPress = myOnPress;<br />

my_btn._accProps.shortcut = "Ctrl+7";<br />

Accessibility.updateProperties();<br />

696 Chapitre 2: Classes <strong>ActionScript</strong>

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

Saved successfully!

Ooh no, something went wrong!