Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Why does newSound.stop() not work? When added to the playbtn function?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now