Hi,
I am umbilical cord new to flash cs4 (as3) and I want to know how I can make a a keyboard event enable a button to be pressed. Specifically, I am making a soundboard in which you click on a button and a sound is played. I want to make it so when you press a SPECIFIC key on the keyboard, the button is pressed so then the sound is played.
P.S. I would really just like a straightforward answer and possibly a code I could copy and paste.
I am using Flash CS4 with Actionscript 3.0
Thank you! ![]()
Just use a
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
function keyPressed(event:KeyboardEvent):void {
//trace(event.keyCode);
if(event.keyCode == ???){
// play the sound
}
}
Where I show the "???" you would replace with the keyCode for the key you want pressed for that sound. To determine the keyCode you can use the trace line that I have commented out.
Note that when testing in Flash you often need to disable the keyboard shortcuts in the Flash Player in order to be able to use alot of the keys. You will find this option in the Control menu options in the player.
North America
Europe, Middle East and Africa
Asia Pacific