
Sound.setTransform() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
787
if (panDirection = = "right") {
newPan = panEffect.getPan() + panIncrement;
if (newPan > 100) {
panDirection = "left";
panEffect.setPan(panEffect.getPan() - panIncrement);
} else {
panEffect.setPan(newPan);
}
} else {
newPan = panEffect.getPan() - panIncrement;
if (newPan < -100) {
panDirection = "right";
panEffect.setPan(panEffect.getPan() + panIncrement);
} else {
panEffect.setPan(newPan);
}
}
}
}
// Usage:
theSoundClip_mc.doPanEffect();
The following example causes sounds in soundClip_mc to react to the mouse. Assuming a
Stage width and height of 550 and 400, the sounds pan left and right with the mouse’s
horizontal position and increase or decrease in volume with the mouse’s vertical position.
To try out the effect, create a new movie clip instance named
soundClip_mc on the main
timeline and attach the following code to frame 1 of the main timeline. Then either place
sounds inside
soundClip_mc or export a sound from the Library with an export identifier of
“bgMusic”.
// Create a new Sound object and attach the sound bgMusic to it
soundClip_mc.volControl = new Sound(soundClip_mc);
soundClip_mc.volControl.attachSound("bgMusic");
soundClip_mc.volControl.start(0, 999); // Play and loop the sound
// With every frame, set volume ...