View Full Version : Help with keyboard press
keke
August 10th, 2006, 11:05 AM
This is stupid of me to ask but how do i make it so that when i push a letter on the keyboard it goes to the next frame? In this case my first letter is K.
I thought maybe i had to use some sort of code but then i got all confused then my code changed lots and now its just 2 lines and doesn't work.
If anyone could help me i'd really appreciate it.
on (keyPress(Key.getCode(75)))
{
gotoAndStop (2);}
*waits to be told how stupid and n00by i am*
blazes
August 10th, 2006, 12:27 PM
onClipEvent(enterFrame){
if(Key.isDown(Key.getCode(75)))
{
gotoAndStop (2);
}}
Joppe
August 10th, 2006, 12:46 PM
Or
key = new Object();
key.onKeyDown = function() {
if (Key.getCode() == 75) {
gotoAndStop(2);
trace('w');
} else {
null;
}
};
Key.addListener(key);
keke
August 10th, 2006, 04:40 PM
hey thanks so much the first code works. the second one doesn't but maybe that's because i'm using flash 5 but thanks anyway. i am confused though, even though it works i get this error message when i do test movie:
Symbol=climber, Layer=button, Frame=1: Line 1: Key code identifier expected
on (keyPress(Key.getCode(75)))
Symbol=climber, Layer=button, Frame=1: Line 2: Statement must appear within on handler
{
any ideas why?
Lord Rahl
August 10th, 2006, 04:54 PM
Well I noticed it has one to many "(" showing up in the code from the error message. So I think you should check to make sure it ends with only 2 of them.
EDIT: Also, my guess is this is in a movieclip or button, so you should put this within a handler which is why I think it is saying it needs the "{". It goes after the second "(".
keke
August 10th, 2006, 06:41 PM
ok.
what's a handler? lol
also as it is now when i push any keyboard key it moves to the next frame instead of the specific one i said needs to be pushed. :huh:
i'm an idiot...
SacrificialLamb
August 10th, 2006, 07:51 PM
can you up lode your file? would make it simpler to help
keke
August 10th, 2006, 10:03 PM
can you up lode your file? would make it simpler to help
yeah. basically its for a game where you climb up a glacier and you type a letter and he moves up a bit. if you double click the climber (its a very layered movie clip) then look in the bottom layer and the word "press" is the movie clip that i put the code in that changes on each keyframe.
don't know why it won't work :(
SacrificialLamb
August 10th, 2006, 10:27 PM
From what I can tell it’s coz you have all these buttons with code like
on (keyPress(Key.getCode(75)){
gotoAndStop (2);
}
And that’s just not button code and that’s why it dose not work for me. but I have Flash 8 and you where saying you have Flash 5 and there is likely to have been some change in between our two versions :P
Also (for me at lest) it should be
if(Key.isDown(77))
And not
if(Key.isDown(Key.getCode(77)))
Coz I can just holed any key down to get him moving
keke
August 10th, 2006, 10:52 PM
yeah i took that button code out after i put it up.
forgot it was still there.
EDIT: just tried what you said and it works!!!
its just if(Key.isDown(77))
thank you so much!!
i'll post the finished thing here when its done.
thanks again!
KIERIOSHIMOTO
August 11th, 2006, 06:16 AM
what are you making?
keke
February 22nd, 2007, 10:59 PM
sorry never posted this. it's part of an amazing race game i'm making. it's the climb the glacier roadblock. here it is:
http://img458.imageshack.us/my.php?image=clue14roadblockje3.swf
i get that it's long for just typing letters but when it's in the full game where every second would count, well then trying to type it fast is much more entertaining....possibly...
oh and ignore the "post the score" bit. that was just coz i put it on a forum somewhere and was seeing who was fastest. though by all means post your scores here.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.