views:

238

answers:

2

I have a movieclip called keyCButton that I want to add a keyboardEvent ("C" Key) to. This will play an animation from frames 2-30 with a sound. I have watched a few tutorials but still haven't gotten the correct information to make it work. The following is my code.

stage.addEventListener(KeyboardEvent.KEY_DOWN, cNote);
function cNote(event:KeyboardEvent):void
{

if (event.keyCode == Keyboard.C)
{
keyCButton.gotoAndPlay(2)
}
}

at frame 30 the code tells it to stop and then go back to frame 1

This works for the MouseEvent.CLICK but the KeyboardEvent does nothing. It returns this error for the if condition

1119: Access of possibly undefined property C through a reference with static type Class.

When I try it with the SPACE instead of C i don't get errors but it still doesn't work

Current Project Link

A: 
isa
i got the spacebar to work now. I had to add this code beforehand import flash.events.KeyboardEvent; var spacekey:uint = 32; and replace the keyCode"67" with spacekey however it doesn't recognize my keyboard letters and therefore wont trace it and give me an output when testing
psy-sci
it works with the other keys now, i just had to test it outside of flash and get the keycodes from the internet
psy-sci
A: 

This may help flash to recognize your keyboard. When you Publish preview with shift+enter, go to the options in the flash player, under the control tab, and then disable keyboard shortcuts. This makes sure that Flash CS4 (or whatever you use) sends the shortcuts to the player instead of trying to hotkey the tools. Hope it helps.

-Solarcloud

Solarcloud7
thank you for this tip. This will help in the future :)
psy-sci