滑鼠在舞台水平移動,左右聲道音量隨之平滑切換;兩側喇叭圖示同步縮放,視覺化聲音定位。

Sound.setPan(-100~100):-100 僅左聲道、0 平均、100 僅右聲道。_xmouse:滑鼠水平座標,配合舞台寬度換算為 -100~100。Math.abs():取絕對值,用於喇叭縮放幅度。200×200 px,灰底 #CCCCCC。匯入聲音檔至庫。
影片剪輯 drum,第 1 幀繪製小喇叭圖案。

drum 實例,命名 lbox(左)、rbox(右),中間文字「Stereo Control」。
direction = _xmouse / 2 - 100; // 滑鼠X→-100~100
s = new Sound();
s.setPan(direction); // 即時設定聲道平衡
if (direction < 0) {
with (_root.lbox) {
_yscale = _xscale = Math.abs(direction) + 100; // 左喇叭放大
}
} else {
with (_root.rbox) {
_yscale = _xscale = Math.abs(direction) + 100; // 右喇叭放大
}
}
gotoAndPlay(4); // 回到第4幀持續偵測滑鼠
_xmouse 範圍 0~200 → /2 -100 映射至 -100~100,完美對應 setPan 定義域。with(_root.lbox) 簡化重複屬性存取。_ymouse 控制前後聲道(需 5.1 聲道素材)。SoundMixer.computeSpectrum() (AS3) 繪製左右聲道波形。