The second part of creating a dynamic sound control for volume is correlating the y position of the slider bar with the parameter for the setVolume() method. You want the top of the groove to correspond to a volume of 100 and the bottom of groove_mc to correspond to a volume of 0 (Figure 5).
Figure 5: The setVolume() parameters need to correspond with the position of the slider_mc movie clip on top of the groove_mc movie clip.
But how do you get the y-coordinates of the moving slider to match up with a number from 0 to 100? One way is to use the movie clip method globalToLocal(), which can convert the coordinates of the slider bar to coordinates that are relative to the groove movie clip. Because the groove movie clip is 100 pixels high and the slider bar is constrained to the groove movie clip’s height, the groove movie clip’s local coordinates provide a convenient correlation with the volume settings (Figure 6).
Figure 6: The global coordinates of the slider_mc movie clip are determined by the root Timeline’s Stage. The local coordinates are relative to the groove_mc movie clip.