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 />

Dans l'exemple suivant, une fonction qui envoie <strong>du</strong> texte vers le panneau <strong>de</strong> sortie est définie<br />

pour le gestionnaire onKeyDown handler. Créez un bouton intitulé my_btn sur la scène et<br />

entrez le co<strong>de</strong> <strong>ActionScript</strong> suivant dans une image <strong>du</strong> scénario :<br />

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

trace("onKeyDown: "+this._name+" (Key: "+getKeyPressed()+")");<br />

};<br />

my_btn.onKeyUp = function() {<br />

trace("onKeyUp: "+this._name+" (Key: "+getKeyPressed()+")");<br />

};<br />

function getKeyPressed():String {<br />

var theKey:String;<br />

switch (Key.getAscii()) {<br />

case Key.BACKSPACE :<br />

theKey = "BACKSPACE";<br />

break;<br />

case Key.SPACE :<br />

theKey = "SPACE";<br />

break;<br />

<strong>de</strong>fault :<br />

theKey = chr(Key.getAscii());<br />

}<br />

return theKey;<br />

}<br />

Appuyez sur Ctrl+Entrée pour tester le fichier SWF. Assurez-vous <strong>de</strong> sélectionner Contrôle ><br />

Désactivez les raccourcis clavier dans l'environnement <strong>de</strong> test. Ensuite, appuyez sur la touche<br />

Tab jusqu'à ce que le bouton ait le focus (un rectangle jaune entoure l'occurrence my_btn) et<br />

commencez à appuyer sur les touches <strong>de</strong> votre clavier. Lorsque vous appuyez sur les touches,<br />

elles s'affichent dans le panneau <strong>de</strong> sortie.<br />

Voir également<br />

onKeyDown (gestionnaire Button.onKeyDown), getAscii (métho<strong>de</strong> Key.getAscii),<br />

getCo<strong>de</strong> (métho<strong>de</strong> Key.getCo<strong>de</strong>)<br />

onKillFocus (gestionnaire Button.onKillFocus)<br />

onKillFocus = function(newFocus:Object) {}<br />

Invoqué lorsqu'un bouton perd le focus clavier. La gestionnaire onKillFocus reçoit un<br />

paramètre, newFocus : il s'agit d'un objet représentant le nouvel objet recevant le focus. Si<br />

aucun objet ne reçoit le focus, newFocus contient la valeur null.<br />

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

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

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

Saved successfully!

Ooh no, something went wrong!