Task: Panning Sound

I l @ ve RuBoard

You can also adjust the pan of a sound while the sound is playing. You can use this to make sounds appear to come from one side and travel to the other.

  1. Create a new movie.

  2. Import the sound 22airplane.wav from the CD-ROM.

  3. Set the sound's Linkage properties so that it exports with the movie and its linkage name is 22airplane.wav.

  4. Create a simple shape and convert it to a movie clip. Name it actions.

  5. The load handler attached to this movie clip starts the sound playing. It sets the pan to -100 so that the sound comes only from one side.

     onClipEvent(load) {     // load sound     thisSound = new Sound();     thisSound.attachSound("22airplane.wav");     // set initial pan     thisSound.setPan(-100);     // play three times     thisSound.start(); } 
  6. The enterFrame handler looks at the position and duration properties of the sound object. These are both measured in milliseconds . By dividing these by each other and multiplying by 200, you get a value from 0 to 200. Subtract 100 to get a value from -100 to 100. Then, set the pan to this value:

     onClipEvent(enterFrame) {     // get value from -100 to 100 based on position     pan = 200*thisSound.position/thisSound.duration - 100;     // set pan     thisSound.setPan(pan); } 

    The result is that the sound starts on one side, coming completely out of one speaker. Then the sound travels to the other side as setPan is used to set the pan to values between -100 and 100. The sound should end with a pan of 100.

Try the movie 22airplane.fla to see this in action.

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