Event complete in Soundjs
I'm developing a game like Simon Says, I have a couple of functional versions, but not optimal.
Beginning to develop something more practical, I generated this code:
createjs.Sound.registerSound("audio/do.mp3", "do");
createjs.Sound.registerSound("audio/re.mp3", "re");
createjs.Sound.registerSound("audio/mi.mp3", "mi");
createjs.Sound.registerSound("audio/fa.mp3", "fa");
createjs.Ticker.setInterval(1000);
var arregloAzar = [""];
var numeroAzar = 0;
var incremento = 0;
var sonido;
var queNota;
for (i = 1; i < 10; i++) {
numeroAzar = (Math.floor((Math.random() * 4) + 1));
arregloAzar = numeroAzar;
console.log(arregloAzar);
}
function miFuncion() {
incremento++;
if (incremento < arregloAzar.length) {
//console.log("este es el cajón " + incremento + " del arreglo " + arregloAzar[incremento]);
switch (arregloAzar[incremento]) {
case 1:
queNota = "do";
console.log(queNota);
createjs.Sound.addEventListener("fileload", loadedF.bind(this));
break;
case 2:
queNota = "re";
console.log(queNota);
createjs.Sound.addEventListener("fileload", loadedF.bind(this));
break;
case 3:
queNota = "mi";
console.log(queNota);
createjs.Sound.addEventListener("fileload", loadedF.bind(this));
break;
case 4:
queNota = "fa";
console.log(queNota);
createjs.Sound.addEventListener("fileload", loadedF.bind(this));
break;
}
} else {
createjs.Ticker.removeEventListener("tick", miFuncion);
}
}
function loadedF(e) {
sonido = createjs.Sound.play(queNota);
//sonido.on("complete", alerta); (this works, but call "alerta" repeatedly)
}
function ejecuta() {
createjs.Ticker.addEventListener("tick", miFuncion);
}
ejecuta();
This works, the switch-case properly executes the corresponding code, but the audio only plays the first time. I already checked in the console and if it accedes to each case according to the increment that takes the sequence. I am trying to handle this with tickers, in order to have the animations reproduced that will have to press the user according to each button.
In a previous version I did it type Flash, with a click reproduced a movieclip that in turn reproduced the corresponding sound. This does not work correctly in Animate when the sequence of clicks generated by the AI is displayed.
Thanks for your support and an apology for my English google.
Cheers!
