Sound Control

Sound in Flash
Flash can accept AIFF, WAV and MP3. If filesize is not a concern, use AIFF (mac) or WAV (windows).

Double clicking the icon of the sound file in the library will bring up more detailed sound properties. Assign it a linkage > class name. This is the name you will need to use in your script. In this example I have made it "kitchen_sound".





 // SOUND

import flash.media.Sound;			// import the sound playing function import flash.media.SoundChannel;			// import the sound channel function

var clickitySound:kitchen_sound;			// give kitchen_sound a name var kitchenSoundChannel:SoundChannel;		// create a new sound channel clickitySound=new kitchen_sound;		// create a new kitchen_sound object kitchenSoundChannel=clickitySound.play; 	// play the sound on the channel!

// playing options

kitchenSoundChannel=clickitySound.play(10,5);   	 // the sound will play from the 10th sec onwards and then loop 5 times

//To mute

import flash.media.SoundMixer;					// import the soundmixer var kitchenTransform:SoundTransform=new SoundTransform;	// create a soundTransform kitchenTransform.volume=0;					// create a muted Transform state it by setting volume to 0 flash.media.SoundMixer.soundTransform=kitchenTransform;		// assign the mute volume state to the mixer!

//To unmute

kitchenTransform.volume=1;					// set volume to full which is 1 flash.media.SoundMixer.soundTransform=kitchenTransform;		// assign the mute volume state to the mixer!



An alternative is to import the sound from outside flash

 import flash.media.Sound;			// import the sound playing function import flash.media.SoundChannel;		// import the sound channel function import flash.net.URLRequest;

var kitchenSound:Sound = new Sound(new URLRequest("kitchen.mp3")); var kitchenSoundChannel:SoundChannel;	       // create a new sound channel kitchenSoundChannel=kitchenSound.play; 	// play the sound on the channel! 

Sound Quality / Publish Settings
Under Publish Settings, you can edit the sound settings and export at a higher quality, as by default Flash will set the sound quality very low (16kbps) to keep the file size nice and small. You can turn up the quality to a maximum of 160kbps, so if you imported in audio in AIFF or WAV format, the quality will still be undiminished when you publish the file.



Sound effects - sources

 * Free/Public Domain Sounds: http://www.partnersinrhyme.com/
 * Creative Commons Sound: http://www.freesound.org/
 * Audacity: Free Sound editor: http://audacity.sourceforge.net/