Forgive my lack of skill and understanding, I am new to this, can you explain where I am going wrong?
This is what I tried:
this.stop();
this.SoundOn.visible = true;
this.SoundOff.visible = false;
this.SoundOn.addEventListener("click", ClickToHideOn.bind(this));
this.SoundOn.addEventListener("click", ClickToShowOn.bind(this));
this.SoundOff.addEventListener("click", ClickToHideOff.bind(this));
this.SoundOff.addEventListener("click", ClickToShowOff.bind(this));
this.SoundOn.addEventListener("click", silence.bind(this));
this.SoundOff.addEventListener("click", serenade.bind(this));
this.SoundOff.addEventListener("click", loadAudio.bind(this));
createjs.Sound.on("fileload", this.loadAudio, this);
createjs.Sound.registerSound("sounds/PeterGunderMovement1.mp3", "SoundOn");
var SoundOn = createjs.Sound.createInstance("SoundOn");
createjs.Sound.registerSound("sounds/PeterGunderMovement1.mp3", "SoundOff");
var SoundOff = createjs.Sound.createInstance("SoundOff");
function loadAudio(event) {
var instance = createjs.Sound.play("sound");
instance.on("complete", this.handleComplete. this);
instance.volume = 0.5;
}
function ClickToHideOn()
{
this.SoundOn.visible = false;
}
function ClickToShowOn()
{
this.SoundOff.visible = true;
}
function ClickToHideOff()
{
this.SoundOff.visible = false;
}
function ClickToShowOff()
{
this.SoundOn.visible = true;
}
function silence()
{
SoundOn.paused = true;
}
function serenade()
{
SoundOn.play();
SoundOff.paused = false;
}
Hi Thad, your getting there.... you need to make sure you don't have any sound in your timeline layers.
You only need 1 event listener per button ....you only need to register one sound, as you pause, play that particular sound, unless you have a specific SoundOff sound....
this.stop(); // Register all our sounds here, as well as the fileload event. createjs.Sound.registerSound("sounds/PeterGunderMovement1.mp3", "SoundOn"); createjs.Sound.addEventListener("fileload", handleFileLoad); // Create all our variables here to be called later. var SoundOn = createjs.Sound.createInstance("SoundOn"); // Set the button visibility states. this.SoundOn.visible = true; this.SoundOff.visible = false; // Add the even listeners for our buttons. this.SoundOn.addEventListener("click", silence.bind(this)); this.SoundOff.addEventListener("click", serenade.bind(this)); function handleFileLoad(event) { // Once sound has loaded, start playing audio, you can also use this.play(); if you have animations. console.log("sound loaded"); createjs.Sound.removeEventListener("fileload", handleFileLoad); SoundOn.play(); SoundOff.paused = false; } function silence() { // the button called SoundOff will trigger this console.log("Button Pause Sound"); this.SoundOn.visible = false; this.SoundOff.visible = true; SoundOn.paused = true; } function serenade() { // the button called SoundOnwill trigger this console.log("Button Play Sound"); this.SoundOn.visible = true; this.SoundOff.visible = false; SoundOn.play(); SoundOff.paused = false; } |