All audio plays at once
Hi. I am making a child's game in Animate on an HTML5 canvas. There are three scenes and each scene has buttons which play audio. This all works fine until I revisit a scene - then all the audio plays at once without any intervention. Why is this happening?
This is an example of the code for the audio:
let audio1Playing = false
let audio2Playing = false
let audio3Playing = false
function init(){
var assetPath = "sounds/";
var sounds = [
{src:"audio1.mp3", id:"audio1"},
{src:"audio2.mp3", id:"audio2"},
{src:"audio3.mp3", id:"audio3"}
]
var preload = new createjs.LoadQueue()
preload.addEventListener("fileload", handleFileComplete)
preload.loadFile (assetPath)
function handleFileComplete(event){
createjs.Sound.registerSounds(sounds, assetPath)
audio1Play = createjs.Sound.play("audio1")
audio2Play = createjs.Sound.play("audio2")
audio3Play = createjs.Sound.play("audio3")
}
root.play_btn.addEventListener("click", playAudio1.bind(this));
function playAudio1 () {
if(!audio1Playing){
audio1Play.play()
audio1Playing = true
} else {
audio1Play.stop()
audio1Playing = false
}
}
}
init()As I say, this works fine one the first pass, but as soon as I navigate back to the initial frame, all the audio starts playing at once. How do I stop this happening, please?
