Skip to main content
Participating Frequently
October 22, 2014
Question

Stop a sound from playing

  • October 22, 2014
  • 1 reply
  • 274 views

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);

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
October 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);

}

Participating Frequently
October 23, 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.