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

Stop a sound from playing

Community Beginner ,
Oct 22, 2014 Oct 22, 2014

Hi, I am trying to stop a sound from playing when the PlayBtn is pressed. The PlayBtn advances the playhead to the next frame and plays an embedded video.

I've tried several different ways of doing this but I am kind of new and self taught.

Thanks for any help you can offer.

import flash.utils.getDefinitionByName;   

var SoundClass:Class = getDefinitionByName("YuhYuhEdited") as Class;

var newSound:Sound = new SoundClass();

newSound.play()

stop();

PlayBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);

function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void

{

  gotoAndPlay(2);

}

TOPICS
ActionScript
258
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 ,
Oct 22, 2014 Oct 22, 2014

use:

import flash.utils.getDefinitionByName;  

var preventPlayBool:Boolean;

var alreadyDefined:Boolean;

if(!alreadyDefined){

alreadyDefined=true;

var SoundClass:Class = getDefinitionByName("YuhYuhEdited") as Class;

var newSound:Sound = new SoundClass();

}

if(!preventPlayBool){

newSound.play();

preventPlayBool=false;  // assuming you want this sound to play every time you enter this frame, except when PlayBtn is clicked.

}

stop();

PlayBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);

function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void

{

preventPlayBool=true;

  gotoAndPlay(2);

}

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 ,
Oct 22, 2014 Oct 22, 2014

Appreciate you taking some time to help me. I used the above exactly as written and the sound continues to play when the PlayBtn is used. The play head does progress to the next frame as intended still.

I want the music to play on the intro screen and then turn off when the button is pressed and the video starts.

Again, thanks for the help.

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 ,
Oct 22, 2014 Oct 22, 2014

Why does newSound.stop() not work? When added to the playbtn function?

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 ,
Oct 22, 2014 Oct 22, 2014
LATEST

I actually just figured out one way to do it:

PlayBtn.addEventListener(MouseEvent.CLICK, fl_ClickToStopAllSounds);

function fl_ClickToStopAllSounds(event:MouseEvent):void

{

  SoundMixer.stopAll();

}

It stops the music but allows the audio to play on the video that picks up in the next frame.

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