Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I make a toggle button to stop sound/music from playing?

Community Beginner ,
Mar 05, 2017 Mar 05, 2017

I have researched on YouTube and through this support forum to try to understand how to do this, but I cannot get it to work. Does anyone know of a way to do this with actionscript, perhaps in the most simple form possible please?

2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 05, 2017 Mar 05, 2017

var s:Sound = new S();  // where S is the class (=linkage id in library panel) of your sound

var sc:SoundChannel = s.play();

var s_bool:Boolean = true;

toggle_button.addEventListener(MouseEvent.CLICK,toggle_soundF);

function toggle_soundF(e:MouseEvent):void{

if(s_bool){

sc.stop();

} else {

sc=s.play();

}

s_bool=!s_bool;

}

Translate
Community Expert ,
Mar 05, 2017 Mar 05, 2017

var s:Sound = new S();  // where S is the class (=linkage id in library panel) of your sound

var sc:SoundChannel = s.play();

var s_bool:Boolean = true;

toggle_button.addEventListener(MouseEvent.CLICK,toggle_soundF);

function toggle_soundF(e:MouseEvent):void{

if(s_bool){

sc.stop();

} else {

sc=s.play();

}

s_bool=!s_bool;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2017 Mar 05, 2017

Apologies, but I get the message "Call to a possibly undefined method s". Its refering to the part where it says new S.

I put the song name like the following:

var s:Sound = new S("Motivator.mp3");

I assume I am doing something incorrectly?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 05, 2017 Mar 05, 2017

Is there any text in the Linkage column in the library? If there is, it's quite likely you put Motivator in there. If you did, the line should read:

var s:Sound = new Motivator();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2017 Mar 05, 2017

This was a great help. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2017 Mar 05, 2017

This helped a bunch. I'll be sure to credit you, thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2017 Mar 05, 2017

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 20, 2018 Mar 20, 2018

I'm trying to use this in an HTML5 canvas. Where do I add this code, just to a frame with symbol in it, or how is it supposed to work?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2018 Mar 20, 2018

that's actionscript which won't work in canvas.  you need to use javascript/createjs, SoundJS v1.0.0 API Documentation : SoundJS

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 21, 2018 Dec 21, 2018

is it possible fadeIn and fadeOut the sound when toggle the button? can you give the example with .fla file maybe, thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 21, 2018 Dec 21, 2018
LATEST

as3 or javascript?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines