Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping Sounds 1

Status
Not open for further replies.
Dec 24, 2001
857
GB
In the Flash movie I'm currently creating, you can click on different buttons which then play sounds. I want to make it so that when you click on a button, it stops any sound which are currently playing and then plays the one its supposed to.

Can anyone tell me how to do this?

Thanks...
 
You could probably issue a stopAllsounds action at the beginning of each button's code, so that it will first stop all (including background music!) sounds playing before playing the current new sound...

Or if you're using the sound object (see the actionscript dictionary), you could simply use the Sound.stop action with a dynamic variable, set each time a new sound is started.

Best wishes,
wink4.gif
ldnewbie
 
I've tried using the 'StopAllSounds' command on press and release, but then it won't even play my file anymore. The reason for this is that I have put the sound in the 'Down' frame of the button, so it plays and then stops immediately.

Is there a way to get around this, or will I have to set the buttons actions to:

On Release
StopAllSounds
On Release
'Command to play file'

...and if this is the case, what is the command to get the button to play the file?
I tried using the 'exec' command in FSCommand, but I don't know what to put as the directory as the file I'm using is in my library.

Any help would be welcomed.

Thanks...
 
Didn't think you were inserting sounds on the down state of your buttons, which should only be done for short button sounds. Thought you were controlling sound movie clips with your buttons.

Here's an example:

On the first frame of the main movie...
cycle = 1;

The first 2 buttons (blue & red) each control 1 sound movie clip (sound1 & sound2), through this script:

on (press) {
stopAllSounds ();
_root.sound1.play();
// _root.sound2.play(); for red button
cycle = 1; // resets green button
}

The green buttons cycles through 3 sound movie clips, and holds this script:

on (press) {
stopAllSounds ();
_root["sound"+cycle].play();
cycle += 1;
if (cycle>3) {
cycle = 1;
}
}

All three movie clips are 2 frames movie clips, with a stop action on the first frame, and the sound inserted in the second frame. Their instance's name are sound1, sound2 and sound3.

Regards,
wink4.gif
ldnewbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top