Jonwiz Media - Websites + Graphics

Home / WizTextTyper / Tutorials / HOW-TO: Typing Sounds

About Tutorial

This tutorial explains how to use typing sounds when the letters are typed. In addition it will also show how to use sounds for spacebar and enter keys!

   
  1. Import the soundfile.
    Download keypress.mp3
    Download spacebar.mp3
    Download return.mp3
  2. Give it a Linkage Identifier in the Library. (Right click on the sound in the library and select "Linkage") That's the string you will use in the typingSound.attachSound("linkage goes here"); code.
  3. Place the component on the stage, give it an instance name. (myTyper is used in the code below)

Put the following code on the _root timeilne.
Be sure to replace "myTyper" with the real instancename of your WizTyper Component Instance.

CODE

//add sounds
typingSound = new Sound();
typingSound.attachSound("keypress");
spacebarSound = new Sound();
spacebarSound.attachSound("tick");
returnSound = new Sound();
returnSound.attachSound("return");
//define onTyping callback listener
_root.onTyping = function(finished, n, nTotal, curChar) {
	typing = true;
	if (curChar != " ") {
		//dont make sounds while parsing tags
		if (prevChar == "<") {
			skipMode = true;
		}
		if (prevChar == ">" && curChar != "<") {
			skipMode = false;
		}
		//make an ENTER key sound when it types a linebreak
		if (prevChar == "<" && curChar == "b") {
			returnSound.start(0, 0);
		}
		//only play while not in skipMode
		if (!skipMode) {
			//play the sound each time a letter is typed
			_root.typingSound.start(0, 0);
		}
	} else {
		//current character is a space
		spacebarSound.start(0, 0);
	}
	prevChar = curChar;
};
//add the listener
myTyper.addListener(this);
myTyper.setSentence("type this sentence with keypress sound! wooohooooo!",true);

That's all folks! Now you've got a sweet typing sound like a futuristic spaceship console.
Remember: You can use your own click sound, it will work with .wav or .mp3 files. But just make sure they're very short.
My sound keypress.mp3 is a mere 1 millisecond!
So it's very important that you make it that short if you synthesize your own click sound. Otherwise it will get all jumbled up when the component types letters.
Download Tutorial Code (zipped actionscript file)


  Contact

Email jonwiz at jonwiz dot com

Phone 647-405-4070

Location Toronto, ON, CA

Websites & Graphics

by Jonathan Wiznuk