Recipe 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. Regardless of the way in which the sound was started, the Stop synchronization stops all instances of that particular sound that are playing.




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net