The Team Jackulator Forums Help With Pranks, Soundboards, Programs....
Pages: 1
Assigning sounds to a key? By: Nevermore Date: May 29, 2013, 09:35:42 am
I'm currently making a Karl Pilkington SB, and it's currently got over 300 sounds, so I'm wondering in there's a way to assign sounds to key presses? For eg. pressing 'o' and the soundboard says "okay". (I'm using Macromedia Flash cool  I'm quite new to this, so I apologise if this is a nooby question.

Thanks
Re: Assigning sounds to a key? By: StuckInTheDitch Date: May 30, 2013, 04:47:24 pm
why hello there, I thought we weren't receiving new members  T_Shock3 oh well, glad to have you onboard!

As your doctor, I recommend you take a look at this topic;

http://www.jackulator.com/smf/index.php?board=106.0
this is a program Jack created to make soundboards really easily. If you also want to learn how to use flash, there's tons of topcis here to look through.

why you're in luck! Just now I was able to find a txt file I saved for myself years ago with lots of action scripts ready to just copy/paste into flash  smiley [attached]

unfortunately I don't have written down exactly what everything does, hopefully you can figure it out.  cheesy I'm afraid it's been so long I don't remember how it works but Jack could tell you probably.
Re: Assigning sounds to a key? By: Nevermore Date: June 01, 2013, 03:14:17 pm
Cheers for the help, man. I'm sure this'll come in handy.
Re: Assigning sounds to a key? By: jackulator Date: June 20, 2014, 05:18:14 am
you have to use a key listener -- although I'm not sure how efficient it'll be to do this because ultimately you can only say as many things as there are keys on the keyboard

but it would be something like this:

Code:
keylistener = new Object();
keylistener.onKeyUp = function() {
if (Key.getCode() == Key.SHIFT) {
trace("you just pressed the SHIFT key!");
}
};
Key.addListener(keylistener);

and so if you wanted to code a specific sound to play you would have to create a sound object first like:

Code:
sound = new Sound();
keylistener = new Object();
keylistener.onKeyUp = function() {
if (Key.getCode() == Key.SHIFT) {
sound.loadSound("theSoundYouWantToPlayWhenYouPushTheShiftKey.mp3", true);
}else if(Key.getCode() == Key.SPACE){
sound.loadSound("theSoundYouWantToPlayWhenYouPushTheSPACEKey.mp3", true);
}
};
Key.addListener(keylistener);

and there's a list of all the various key codes for the keys: http://people.uncw.edu/tompkinsj/112/flashactionscript/keycodes.htm

so you could go:

Code:
sound = new Sound();
keylistener = new Object();
keylistener.onKeyUp = function() {
if (Key.getCode() == 48) {
sound.loadSound("theSoundYouWantToPlayWhenYouPushThe0Key.mp3", true);
} else if (Key.getCode() == 49) {
sound.loadSound("theSoundYouWantToPlayWhenYouPushThe1Key.mp3", true);
} else if (Key.getCode() == 50) {
sound.loadSound("theSoundYouWantToPlayWhenYouPushThe2Key.mp3", true);
}//et cetera...
};
Key.addListener(keylistener);

and in order for the sound object you created to play you have to make sure the mp3s are in the same folder as the SWF file

otherwise you have to specify the location with like:

Code:
sound.loadSound("someFolder/theNameOfTheMP3.mp3", true);