[AS3] écouteur clavier ne fonctionnepas

Résolu
carton99 Messages postés 103 Date d'inscription vendredi 29 janvier 2010 Statut Membre Dernière intervention 18 mars 2012 - 10 mai 2010 à 19:46
carton99 Messages postés 103 Date d'inscription vendredi 29 janvier 2010 Statut Membre Dernière intervention 18 mars 2012 - 10 mai 2010 à 21:06
Bonjour,
je débute en AS3.

dans le code suivant ,je ne comprend pas pourquoi l'écouteur clavier ne marche pas alors que l'écouteur enterframe fonctionne très bien.

package { 
import flash.display.MovieClip;
import flash.events.*;
import flash.ui.Keyboard;

public class Vaisseau extends MovieClip{ 
 

public function Vaisseau(x1:Number,y1:Number) { 
this.x=x1;
this.y=y1;
this.addEventListener(KeyboardEvent.KEY_DOWN, deplacement);
this.addEventListener(Event.ENTER_FRAME, masterLoop);
} 
   	
public function masterLoop(e:Event):void {
trace(50);
this.x+=1;
}

public function deplacement(evt:KeyboardEvent):void
{
trace(252);

}

  	}
}


Le trace(252) , ne fonctionne pas quand j'appusi une touche clavier.

2 réponses

carton99 Messages postés 103 Date d'inscription vendredi 29 janvier 2010 Statut Membre Dernière intervention 18 mars 2012
10 mai 2010 à 21:06
ok la réponse vien d'ici.


public function Character(mc) {
this.MC = mc;
this.speed = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}

SA marche mais je comprend pas pk .
3
carton99 Messages postés 103 Date d'inscription vendredi 29 janvier 2010 Statut Membre Dernière intervention 18 mars 2012
10 mai 2010 à 21:01
Je comprend pas ,car je vien de tester le "event" clic ,est sa marche .
Pourquoi le clavier ne répond pas.
0
Rejoignez-nous