Skip to main content
Known Participant
August 16, 2021
Question

How to stop sound using button?

  • August 16, 2021
  • 3 replies
  • 1622 views

Please help.

 

I'm creating a interactive book using action script.

 

Well i have assigned each layer a movie clip symbol and inside that symbol I have several sound file.

 On the 1st layer (my first page) I have buttons to goto the specific layer (Page) but when I click on the button all the sounds overlapping each other.

 

Please help me... I'm stuck on this.

HELP.

This topic has been closed for replies.

3 replies

Community Expert
August 17, 2021

Here is a thread on stopping  asound with Actionscript:
https://community.adobe.com/t5/animate/stop-sound-with-action-script/m-p/2347938


I tend to use Javascript and find the following an easy way to start and stop a sound:
If the audio is imported into the FLA file, give the audio a linkage name in the library. This is different from the file name:
To play the sound with a linkage name of - music
createjs.Sound.play("music");

and to stop the audio:
createjs.Sound.stop();

or to play a sound external to the FLA
var myAudio = new Audio("music.mp3'");
myAudio.play();

To stop the sound:
soundPlayer.pause();
soundPlayer.currentTime = 0;


Legend
August 16, 2021

"On the 1st layer (my first page) I have buttons to goto the specific layer (Page)"

 

You can't go to layers in Animate. That's conceptual nonsense. You can go to frames. If you've organized your content so that all your pages are individual layers of the same timeline, you're going to have nothing but trouble.

 

All your pages should be in individual movieclips, and each movieclip should be in its own frame on the timeline.

 

Known Participant
August 17, 2021

Really sorry...i meant frames.

 

Lets say.........the white rectangle on the left side is my button and it is assigned to go to frame 4.....well it does goto frame 4 but all sounds overlap with each sound..

.

PLEASE HELP ME.

JoãoCésar17023019
Community Expert
Community Expert
August 16, 2021

Hi.

 

Your sounds should be distributed in labels or frames.

 

Here is a sample of how you can play sounds within a Movie Clip.

 

AS3 code:

import flash.events.MouseEvent;

var currentSound:String;

function playSound(e:MouseEvent):void
{
	var index:uint = uint(e.target.name.replace("soundButton", "")); // here we remove the suffix "soundButton" from the name so only the number in the name is left
	currentSound = "sound" + index; // this name is used by the sounds MovieClip
	sounds.gotoAndPlay(2); // we send the playhead to frame 2 so the current sound playing within that Movie Clip will be stoped before playing the next one
}

soundButton0.addEventListener(MouseEvent.CLICK, playSound);
soundButton1.addEventListener(MouseEvent.CLICK, playSound);

 

And this is the structure of the sounds Movie Clip:

 

The second and the third frames in the sounds layer are responsible for stopping the current sound.

 

FLA / source / code / files:

https://github.com/joao-cesar/adobe/tree/master/animate%20cc/as3/play_sounds_in_movie_clip

 

It's a very simple approach and of course it can be improved. If you need more control, you will probably need to use AS3 to play and control the sounds.

 

I hope this helps.

 

Regards,

JC

Known Participant
August 17, 2021

Can you please solve this too...it will mean alot 

 

Lets say.........the white rectangle on the left side is my button and it is assigned to go to frame 4.....well it does goto frame 4 but all sounds overlap with each sound..

 

 

 

PLEASE HELP ME.

JoãoCésar17023019
Community Expert
Community Expert
August 17, 2021

Where are the sounds?

 

Have you tried the template provided in the GitHub link?