Key down

hey I cant figure out why this isnt working I have only frame which I put this code into

if (Key.isDown(Key.RIGHT)){
trace(“key down”);
}

nothing happens, whats happening?

better to use a listener object, did you have a look at the flash help & reference files?

no, why doesnt that work. And how would a listener work to accomplish this?

It doesn’t work because that condition is checked only once as the movie starts.
So if you hold the ‘right’ key and run the movie, it will detect the keypress.

As eyezberg suggested, you have to make the Key object continuously listen to your keypresses. Something like this:

this.onKeyDown = function() {
	if (Key.isDown(Key.RIGHT)) {
		trace("key down");
	}
};
Key.addListener(this);

Thanks

Welcome

claudio is too helpfull sometimes… :slight_smile:
let people code their own, your detailed intro should’ve been enough
(“It doesn’t work because that condition is checked only once as the movie starts.
So if you hold the ‘right’ key and run the movie, it will detect the keypress…you have to make the Key object continuously listen to your keypresses”)
else they’ll never learn :wink: