0
votes

I have one background sound to use in my project. But when I click the button to other scene, the sound repeats themselves and worse, it redundant with the sound in next scene. I was trying to use one background song for the whole project but this problem happened. Can teach me how?

I am using Adobe Flash CS6. Thank you.

1

1 Answers

1
votes

the sound is repeating itself because timeline is repeating by default and you should add command stop() in actionscript. You did not provide any source code so I'll assume you don't have any, in your case here is a sample program in actionscript that loops the background music.

import flash.events.MouseEvent;

stop();   //<-- make sure to stop timeline
var bgMusic:Sound = new BGMusic(); 
var bgChannel:SoundChannel = new SoundChannel();
bgChannel = bgMusic.play();
bgChannel.addEventListener(Event.SOUND_COMPLETE, loop);

startButton.addEventListener(MouseEvent.CLICK, startGame);

function startGame(e:MouseEvent):void {
    gotoAndStop(1, "Scene 2");    //<-- stop after clicking button
}

function loop(e:Event):void {
    bgChannel = bgMusic.play();
    bgChannel.addEventListener(Event.SOUND_COMPLETE, loop);
}