tailieunhanh - Học Actionscript 3.0 - p 34

Changing Sound Volume and Pan and positive interim values reflect some degree of pan right. The following script sets the channel instance to a pan setting of full left: var trans:SoundTransform = new SoundTransform(); = -1; = trans; To transform all playing sounds at once, substitute the specified channel with the master SoundMixer class. For example, the following script mutes all sounds: var trans:SoundTransform = new SoundTransform(); = 0; = trans; Now let’s apply what we’ve learned to our ongoing player example. The following code can be found in the source file, and demonstrates both volume and pan by using mouse coordinates. Figure 11-2 shows how the mouse will affect the sound transformation. Moving the mouse. | Changing Sound Volume and Pan and positive interim values reflect some degree of pan right. The following script sets the channel instance to a pan setting of full left var trans SoundTransform new SoundTransform -1 trans To transform all playing sounds at once substitute the specified channel with the master SoundMixer class. For example the following script mutes all sounds var trans SoundTransform new SoundTransform 0 trans Now let s apply what we ve learned to our ongoing player example. The following code can be found in the source file and demonstrates both volume and pan by using mouse coordinates. Figure 11-2 shows how the mouse will affect the sound transformation. Moving the mouse left and right pans the sound left and right. Moving the mouse up and down fades the volume up and down. Hl stage origin x 0 y 0 center of stage default direction of increasing y values will be inverted for usability using ActionScript 1 I I I I I I I I I I I I J Ï I I I I I I I I I I I I I Figure 11-2. How the mouse affects sound volume and panning in the adaption made to the sound player project Line 104 creates a SoundTransform instance and lines 105 through 109 contain the onPlayProgress function that will set and apply the transformations. This function will be called from the enter frame event listener function created earlier which we ll adapt in a moment. Chapter 11 Sound 309 Download from Wow eBook Changing Sound Volume and Pan NOTE Again if you want to transform every sound playing at a given moment simply substituting SoundMixer for the specific channel in line 108 will accomplish the task. To set these changes with the mouse in a natural and intuitive way we need to think about ActionScript mouse coordinates and apply a little math. Line 106 sets the volume based on the y-coordinate of the mouse. By dividing the current vertical mouse coordinate mouseY by the