Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning A Key To A Sound

Status
Not open for further replies.

MonkeyBeard

Technical User
Joined
Dec 9, 2004
Messages
23
Location
US
I have buttons in Flash that each play a different sounds, but I want to set it up so I can assign a key to each button. For example, I press "w" on the keyboard, and it plays the "whistle" sound. I am completely Flash retarded, so detailed explanations please. Thanks ahead of time!

- John
 
Hope this helps...
Here is code I am currently using on a button in one of my demos.
What is happening in this case is I have the left arrow keyboard key playing a button instance called "_down" so when the user presses the left key on their keyboard the left key in my movie also presses.

Go into your Flash Help and look up 'Key.Down' for more help and 'Keyboard Keys and Key Code Values' for a complete list of keys and key codes.
Code:
onClipEvent (enterFrame) { 
if (Key.isDown(Key.LEFT)) {
	gotoAndPlay("_down");
	} 
}

Below is some actionscript you will find there to capture key code values and ASCII key code values using a SWF file and key presses.
Code:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
    trace("DOWN -> Code: " + Key.getCode() + "\tACSII: " + Key.getAscii() + "\tKey: " + chr(Key.getAscii()));
};
Key.addListener(keyListener);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top