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

stop sound with action script?

New Here ,
Dec 22, 2009 Dec 22, 2009

Copy link to clipboard

Copied

Hi,

Im a beginner with action script, and is there a way to stop a sound using actionscript?

My sound is called "CRICKET.mp3", if thats necessary to know.

TOPICS
ActionScript , Code , How to

Views

21.5K

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

correct answers 1 Correct answer

Community Expert , Dec 22, 2009 Dec 22, 2009

you can always use:

SoundMixer.stopAll();

to stop all sounds.  but, if you want to stop one particular sound, you should apply stop() to your sound's soundchannel (created when the play() method is applied to your sound).

Votes

Translate

Translate
Advocate ,
Dec 22, 2009 Dec 22, 2009

Copy link to clipboard

Copied

How are you playing the sound? Are you using a script or is it on the timeline? If script, could you share a bit of it so we know how you're starting the file?

Votes

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 Expert ,
Dec 22, 2009 Dec 22, 2009

Copy link to clipboard

Copied

you can always use:

SoundMixer.stopAll();

to stop all sounds.  but, if you want to stop one particular sound, you should apply stop() to your sound's soundchannel (created when the play() method is applied to your sound).

Votes

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
Contributor ,
Aug 10, 2024 Aug 10, 2024

Copy link to clipboard

Copied

hello man

how do i proceed in order to paste the SoundMixere.stopAll();

where do i place it in action script?

can you give an example?

love your helps

 

Votes

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 Expert ,
Aug 10, 2024 Aug 10, 2024

Copy link to clipboard

Copied

LATEST

execute stopAll whenever you want to stop all sound

Votes

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
Explorer ,
Dec 23, 2009 Dec 23, 2009

Copy link to clipboard

Copied

simple example with 2 buttons 'play' and 'stop', pls try to use it to clear how this work..

create 2 buttons and give them instance names: play_btn and stop_btn

put your .mp3 file to the same folder with your .fla file

and write code:

var req:URLRequest = new URLRequest("CRICKET.mp3");
var sound:Sound = new Sound();
var controller:SoundChannel;

function soundLoaded(event:Event):void
{
     controller = sound.play();
     controller.stop();
     play_btn.addEventListener(MouseEvent.CLICK, playSound);
     stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
}

function playSound(event:MouseEvent):void
{
     controller = sound.play();
}

function stopSound(event:MouseEvent):void
{
     controller.stop();
}

sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(req);

Votes

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
New Here ,
Dec 23, 2009 Dec 23, 2009

Copy link to clipboard

Copied

Hi Sergey,

I tried to do what you said about playing and stopping sound using that code you posted but it didn't work for me!!

I have a wav sound file in the same folder as the .fla file but nothing! it doesn't show any errors in the code so I'm confused!!

Please have a look at the files I've attached!

Ben.

Votes

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
Explorer ,
Dec 23, 2009 Dec 23, 2009

Copy link to clipboard

Copied

Although there are various sound file formats used to encode digital audio, ActionScript 3.0, Flash Player and AIR support sound files that are stored in the mp3 format. They cannot directly load or play sound files in other formats like WAV or AIFF.

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d2...

I think you can convert your .wav to .mp3

Votes

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
New Here ,
Dec 23, 2009 Dec 23, 2009

Copy link to clipboard

Copied

Ok! Thanks for the info!

Will try converting the files to mp3.

Cheers,

Ben.

Votes

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
Valorous Hero ,
Dec 23, 2009 Dec 23, 2009

Copy link to clipboard

Copied

Hey Sergey, great script!

Can you please give an example how the script will be if the sound will just start playing automatically and then stop after certain time without any buttons.

Thank you for your help.

Votes

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
Explorer ,
Dec 24, 2009 Dec 24, 2009

Copy link to clipboard

Copied

var req:URLRequest = new URLRequest("yourSoundNameHere.mp3");
var sound:Sound = new Sound();

function soundLoaded(event:Event):void
{
     sound.play();
}

sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(req);

Votes

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
Explorer ,
Dec 24, 2009 Dec 24, 2009

Copy link to clipboard

Copied

Yestarday i put link to page where you can find info about how to load .mp3... please click to it..

there you can find this code:

var req:URLRequest = new URLRequest("yourCode.mp3");
var s:Sound = new Sound(req);
s.play();

you can use it:)

Votes

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
Valorous Hero ,
Dec 24, 2009 Dec 24, 2009

Copy link to clipboard

Copied

Thanks Sergey,

I was more interested in how to stop the sound after certain time. For example - stop after 10 seconds when MySong.mp3 is 2 minutes long.

Also I don't know how to make the sound start after certain time, for example start after 5 seconds then play for 10 seconds and stop.

Thank you for you help, very much appreciated.

Votes

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
Explorer ,
Dec 25, 2009 Dec 25, 2009

Copy link to clipboard

Copied

Find way how to start playing after some secons:

//2000 this is mean then your sound will start to play after 2 second from start.
//3 this is how many time you repeat your sound
var snd:Sound = new Sound(new URLRequest("manscreamdistance.mp3"));
snd.play(2000, 3);


Now need clear how to stop it:)

If find way will write..

Votes

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