How to stop sound using button?

Community Beginner ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

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.

TOPICS
ActionScript , Code , Error , How to , Timeline

Views

113

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

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:

image.png

 

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

Likes

Translate

Translate

Report

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

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

 

16291911135074993774437362911368.jpg

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.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Where are the sounds?

 

Have you tried the template provided in the GitHub link?

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

"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.

 

Likes

Translate

Translate

Report

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Really sorry...i meant frames.

 

1629190631184574503254250277565.jpg

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.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

LATEST

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;


Likes

Translate

Translate

Report

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