i’m having difficulty attaching a sound clip to on object so that when it’s clicked, a sound will play out. I don’t have a seperate actionscript file to my game, the actionscript is within the timeline. My soundtrack is in my library and my movie clip has the appropriate instance name, here is the code;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundChannel
import flash.net.URLRequest;
GBtn.addEventListener(MouseEvent.CLICK,muteBtnPressed);
var s:Sound = new Sound;
s.load(new URLRequest("song.wav"));
var sc:SoundChannel = s.play(0,1000);
sc.soundTransform = new SoundTransform(0);
var soundMuted:Boolean = false;
function muteBtnPressed(evt:MouseEvent){
if(soundMuted==true){
soundMuted = false;
sc.soundTransform = new SoundTransform(1);
GBtn.gotoAndStop("on");
} else {
(soundMuted == false){
soundMuted = true;
sc.soundTransform = new SoundTransform(0);
GBtn.gotoAndStop("off");
}
}
at the moment, this is code for a mute button, but I will reverse this eventualy to play when clicked. Any advice would be greatly appreciated as my work is in for tomorrow and I’m getting a bit behind! Thank you!!
If the sound is in the library set it to export for Actionscript with the class name “Song”. Then replace these two lines
With this
This will instantiate your library sound.