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.
Â
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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(); //} |

























