AS3 Scripting OnClick Play Sound

This is the most common scripting found for playing sound in ActionScript 3.0. In ActionScript 3.0 they have this Sound Channel which represent a sound object, with it you can have a MUCH BETTER sound control in Flash.

Today’s tutorial in we going to create a simple movieClip , attach an click event listener on it and it triggers the function to play a sound object from the library.

You may download the sample here.

Download Here



import flash.media.Sound;
import flash.media.SoundChannel;
 
//Declare a BeepSnd sound object that loads a library sound.
//Please check the library & make sure is attached to actionscript
//ClassName BeepSound
var BeepSnd:BeepSound = new BeepSound();
 
somebutton.addEventListener(MouseEvent.CLICK,playNoises);
 
function playNoises(event:Event){
	playSound(BeepSnd);
}
 
function playSound(soundObject:Object) {
	var channel:SoundChannel = soundObject.play();
}
 
//If you using package use this function sample instead just
//Change all the function to public or private function / methods
//public function playSound(soundObject:Object) {
//	var channel:SoundChannel = soundObject.play();
//}