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.