O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

13.13. Creating Advanced Stereo Panning Effects

Problem

You want to be able to modify the panning of both the right and left channels of a stereo sound.

Solution

Use the setTransform( ) method.

Discussion

When working with monaural sounds, the basic getPan( ) and setPan( ) methods suffice. However, when dealing with stereo sounds, you can use the getTransform( ) and setTransform( ) methods to control the panning of each channel.

The setTransform( ) method takes a single parameter: a sound transform object. You can create a sound transform object by creating a generic instance of the Object class with the following properties:

ll

Percentage of the left channel playing through the left speaker

lr

Percentage of the left channel playing through the right speaker

rl

Percentage of the right channel playing through the left speaker

rr

Percentage of the right channel playing through the right speaker

Here is an example in which the right channel is played through the left speaker and the left channel is played through the right speaker:

soundTransform = {ll: 0, lr: 100, rl: 100, rr: 0};
mySound_sound.setTransform(soundTransform);

You can also use getTransform( ) in conjunction with setTransform( ) to perform changes relative to the current settings:

// Get the current transform object.
soundTransform = mySound_sound.getTransform(  );

// Add 50 to the current ll property.
soundTransform.ll += 50;

// Set the new transform object.
mySound_sound.setTransform(soundTransform);

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required