I’m making a game with my beginners knowledge.
and i was wondering why my code doesn’t work.
i want it so that when you press the key c it will go to (and play)
frame 15
here’s my code
c.onKeyDown = function() {
gotoAndPlay(15);
};
why doesn’t it work?
is it case sensative? if so that’s what the problem is…
//create object
keyListener = new Object();
//use onKeyDown function
keyListener.onKeyDown = function() {
//get the Ascii code
keypressed = Key.getAscii();
//trace the returned value of the letter pressed
trace(keypressed);
//if the letter press is 99 ("c")
if (keypressed == 99) {
//trace that you pressed "c"
trace("you pressed the right key");
}
};
//add listener to keys for this to work
Key.addListener(keyListener);
That should work (untested) to help you understand how it works. Actually, it should help me understand how it works as well considering I never worked with it before :-\
PS: This is case sensitive since the code for lowercase “c” is 99 and the code for the uppercase “C” is 67.
[edit]I checked the code and it actually works![/edit]
And if you want it to work on either uppercase or lowercase “c” change the if statement to look like this…
if (keypressed == 99 or keypressed == 67) {
trace("you pressed the right key");
}
Sorry if I am being annoying, but I just figured all this out now too and I am trying to figure out how it works and such by experimenting with my original code.