Copy link to clipboard
Copied
Hi,
creating Actionscript 3 buttons that controlled audio (play/stop) worked fine for me.
But on a HTML5-Canvas I just cant get it to work.
The start/stop options under properties are also not working with HTML5.
This is my buttons action. Does anybody have an idea what I can add to stop a certain MP3 from playing when clicked?
this.negBtn01.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));
function fl_ClickToGoToAndStopAtFrame()
{
this.gotoAndStop("01_neg");
??????????? ( WHAT CAN I ADD HERE?) ????????????????
}
If the problem can be solved differently, please let me know.
Copy link to clipboard
Copied
People use different way to control sounds. Below is what I use for example:
Note: I put my code in frame one.
Note2:
play ( src [interrupt="none"|options] [delay=0] [offset=0] [loop=0] [volume=1] [pan=0] [startTime=null] [duration=null] )
createjs.Sound.play("reset", "none", 0, 0, 0, 0.5);
reset is the link name in library.
function startGame() {
this.gotoAndStop("game");
this.music = createjs.Sound.play("music", "none", 0, 0, -1, 0.4);
}
Here is an example for a music button:
//************************* MUSIC BUTTON ************************
this.musicBtn.addEventListener("click", musicToggle.bind(this));
var on = 0;
function musicToggle() {
if (on == 0) {
this.musicBtn.musicStatus.gotoAndStop("musicOff");
this.music.paused = true;
on = 1;
} else {
this.musicBtn.musicStatus.gotoAndStop("musicOn");
this.music.paused = false;
on = 0;
}
}
Copy link to clipboard
Copied
Thank you resdesign.
I tried that out but it´s not really working for me that way.
Let´s say I have an imported audiofile called "speaker.mp3" which is allready playing at some point (audiowave starting at a certain keyframe).
Now I need a button that doesn´t toggle the sound on and off, but it should only stop that one MP3 from playing.
Since there is background music, not all sounds should stop.
Isn´t there a line of code that will just stop that one audiofile from playing?
Maybe the answer is in your example. But since I have multiple audiofiles a I am looking for a more efficient way of solving this.
Any ideas?