Friday, August 10, 2007

Panning Sound

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();

    // set initial pan
    // play three times

  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

    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.

No comments: