Skip to main content
Known Participant
May 10, 2022
Answered

Play/stop sound in adobe animate html5 canvas document

  • May 10, 2022
  • 1 reply
  • 1770 views

Hello,

 

I wanted to know if there is any way to make this AS3 code work in HTML5 document?

 

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound_3);

var fl_SC_3:SoundChannel;


var fl_ToPlay_3:Boolean = true;

function fl_ClickToPlayStopSound_3(evt:MouseEvent):void
{
if(fl_ToPlay_3)
{
var s:Sound = new Sound(new URLRequest("http://www.helpexamples.com/flash/sound/song1.mp3"));
fl_SC_3 = s.play();
}
else
{
fl_SC_3.stop();
}
fl_ToPlay_3 = !fl_ToPlay_3;
}

This topic has been closed for replies.
Correct answer kglad

Sorry for bring you again on this ... if you can simply and complete this code for me ..

 

function registerSoundF(s){

createjs.Sound.registerSound(s,s);

}

function playSoundF(s){

createjs.Sound.play(s);

}

function stopSoundF(s){

createjs.Sound.stop(s);

}

 

If my button instance name is button_1 ,
sound path is"audio/soung1.mp3" and
soundID is "a" ...
what will be the complete code. 

I am unable to use it correctly 


createjs.Sound.registerSound("./audio/soung1.mp3", "soung1ID");

this.button_1.addEventListener('click',toggleF.bind(this));

 

if(!this.playing_defined){

this.playing=false;

this.playing_defined=true;

}

 

function toggleF(){

if(this.playing){

stopF();

} else {

playF();

}

this.playing=!this.playing;

}

}

function playF(){
createjs.Sound.play("soung1ID");

}

function stopF(){
createjs.Sound.stop("soung1ID");
}

1 reply

kglad
Community Expert
Community Expert
May 11, 2022

createjs.Sound.registerSound("http://www.helpexamples.com/flash/sound/song1.mp3", "soundID");

this.button_1.addEventListener('click',toggleF.bind(this));

 

if(!this.playing_defined){

this.playing=false;

this.playing_defined=true;

}

 

function toggleF(){

if(this.playing){

stopF();

} else {

playF();

}

this.playing=!this.playing;

}

}

function playF(){
createjs.Sound.play("soundID");

}

function stopF(){
createjs.Sound.stop("soundID");
}

 

Known Participant
May 12, 2022

Thanks for the help but as I am not good with coding, I don't know what is the issue there, as its not playing sound. Can you help in this?

https://1drv.ms/u/s!AteMvMBtvCb1gVBfhIZ9lmfJRSnx?e=tpOBPH

 

Another thing I wanted to ask if i want to link the button from a sound in the library, how it can be done?

kglad
Community Expert
Community Expert
May 12, 2022

i charge for downloading and fixing files.  free help i only offer via the adobe forums.

 

if you want me to download your file, fix it and encode the playing of a library sounds, send me a private message.