Skip to main content
Known Participant
May 10, 2022 4:46 PM UTC
Answered

Play/stop sound in adobe animate html5 canvas document

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 is closed to new replies. Start a new post to keep the conversation going.
kglad
kgladCorrect answer
Community Expert
Aug 18, 2022 2:00 PM UTC

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");
}

16 replies

kglad
Community Expert
Community Expert
May 11, 2022 1:49 PM UTC

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");
}

 

Translate
Known Participant
May 12, 2022 4:11 PM UTC

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?

Translate
kglad
Community Expert
Community Expert
May 12, 2022 5:29 PM UTC

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.

Translate