17.10. Starting and Stopping Sounds with Buttons

Problem

You want users to be able to start and stop a sound using buttons.

Solution

Create two buttons. On the Down frame of each button, add the same sound. On the Start button, synchronize the sound to Start. On the Stop button, synchronize the sound to Stop.

Discussion

Flash offers a convenient way to start and stop sounds by using the Start and Stop synchronization settings, respectively. You can readily create buttons that start and stop a sound when you know how to use the Start and Stop synchronization settings properly:

  1. Create a button symbol, and place an instance on the stage. This button will be the start button.

  2. Edit the start button, and add the sound to its timeline on the Down frame.

  3. Make sure to set the sound’s synchronization to the Start option.

  4. Return to the main timeline.

  5. Create a second button symbol, and place an instance on the stage. This button will be the stop button.

  6. Edit the stop button, and add the sound to its timeline on the Down frame.

  7. Change the sound’s synchronization setting to Stop. This will cause Flash to stop playing all instances of that particular sound.

That is all there is to starting and stopping a sound with buttons. When you click on the start button, the sound should begin to play, and when you click on the stop button, the sound should stop.

You can use the Stop synchronization setting to stop a sound whether it was started by the playhead entering a timeline keyframe or by the user pressing a button. ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.