
Adobe
Blog

One of the most effective uses of the Sound class and its methods is to create dynamic controls in Flash® 8 that allow the user to set the desired volume level or speaker balance. A common strategy is to create a draggable movie clip that acts as a sliding controller. By correlating the position of the draggable movie clip with the volume parameter of the setVolume() method, you can make the volume change dynamically as the viewer moves the movie clip.
For a vertical slider bar that controls volume, you must create two elements: the handle or slider and the track or groove it runs along (Figure 1). First, you create a movie clip called groove_mc. To make things easy, make the groove_mc movie clip 100 pixels high with its registration point at the bottom of the rectangle. Making the groove_mc 100 pixels high will make it simpler to correlate the position of the slider on the groove_mc with the setVolume() parameter. To create the draggable slider, create a movie clip called slider_mc and assign the startDrag() action with constraints on the motion relative to the groove_mc movie clip.
Figure 1: The components of a volume control are the slider that moves up and down and the groove.
To follow along with this article, you will need the following software:
Basic knowledge of Flash 8
H. Paul Robertson is an ActionScript developer/writer for the Platform Developer Documentation team at Adobe Systems. Previously he worked as a web applications developer and co-authored Macromedia Flash 8 Advanced: Visual QuickPro Guide (Peachpit Press, 2005) with Russell Chun. Paul is a Certified Flash Developer and holds a Masters degree in Instructional Systems Technology from Indiana University. When he's not programming web applications, writing about web applications, teaching about web applications, or updating his blog, Paul spends his time collecting kitchen gadgets and trying to achieve his three children's level of mastery of Legos, Star Wars trivia, and other equally important subjects.
Excerpted from “Macromedia Flash 8 Advanced for Windows and Macintosh: Visual QuickPro Guide” by Russell Chun and H. Paul Robertson © 2006. Used with the permission of Peachpit. To purchase this book, please visit www.peachpit.com.