Sound Transforms

I l @ ve RuBoard

Although setVolume and setBalance seem to provide a lot of control over a sound, you can go even further. By creating sound transform objects, you can precisely control stereo sounds ”which sound channel comes out of which speaker.

In a typical sound played in a typical way, the left channel's sound comes out of the left speaker, and the right channel's sound comes out of the right speaker.

However, you can change this by creating a sound transform object and applying it to the sound object with a setTransform command.

A sound transform object is actually just a plain variable object. But it needs to have four specific properties. Here is an example:

 mySoundTransform = {ll: 75, rr: 25, rl: 25, lr: 75}; 

The four properties have two characters in each of their names . The first character represents the speaker. The second character represents the channel. So ll is the property that determines how much of the left channel comes out of the left speaker. rl is how much of the left channel comes out of the right speaker.

graphics/clock.gif

You obviously need a stereo sound to use a sound transform normally. However, if you use Flash's default compression settings, your stereo sound will be compressed into a mono sound when you test or publish the movie.


Using sound transforms, you can switch which channel comes out of which speaker. All you need to do is put 100 percent of the left channel out of the right speaker and 100 percent of the right channel out of the left speaker. Here is a button that does this:

 on (release) {     var mySound = new Sound();     mySound.attachSound(soundName);     var mySoundTransform = new Object();     mySoundTransform = {ll: 0, rr: 0, lr: 100, rl: 100};     mySound.setTransform(mySoundTransform);     mySound.start(); } 

The example movie 22steropan.fla includes several demonstration buttons . It also includes a sound where the left and right channels play completely separate sounds. The left channel features a robin singing away, whereas the right features a cardinal.

graphics/bulb.gif

If you are using a sound transform with a mono sound, note that the entire sound is stored in the left channel. So only ll and rl properties will have any effect.


You can use one of the top three buttons to play the sound normally, but with the pan set to either the left, middle, or right. The left and right buttons allow you to hear only one channel at a time.

Then there are two buttons below that use sound transforms to play only one channel at a time, but in the opposite speakers .

I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

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