![]() ![]() | |
可以使用内置 Sound 类控制 SWF 文件中的声音。若要使用 Sound 类的方法,必须先创建一个 Sound 对象。然后可以使用 attachSound() 方法在 SWF 文件运行时将库中的声音插入该 SWF 文件。
要查看声音控件的动画演示,可单击“播放”按钮,然后调节音量和左右平衡。
Sound 类的 setVolume() 方法控制着音量,而 setPan() 方法则调节声音的左右平衡。
下面的步骤介绍如何创建如上所示的声音控件。
将声音附加到时间轴上: a_thousand_ways。playButton。 stopButton。 speaker。
speaker.stop();
song = new Sound();
song.onSoundComplete = function() {
speaker.stop();
};
song.attachSound("a_thousand_ways");
playButton.onRelease = function() {
song.start();
speaker.play();
};
stopButton.onRelease = function () {
song.stop();
speaker.stop();
}
该代码首先停止扬声器影片剪辑。然后创建一个新的 Sound 对象 (song),并向该对象附加链接标识符为 a_thousand_ways 的声音。接下来,它为 song 对象定义 onSoundComplete 处理函数,该函数将在声音结束后停止 speaker 影片剪辑。最后,与 playButton 和 stopButton 对象关联的 onRelease 处理函数使用 Sound.start() 和 Sound.stop() 方法开始和停止该声音,并且还播放和停止 speaker 影片剪辑。
创建滑动的音量控件: 这创建了一个在第一帧中带有按钮的影片剪辑。
on (press) {
startDrag(this, false, left, top, right, bottom);
}
on (release) {
stopDrag();
}
startDrag() 参数 left、top、right 和 bottom 是在剪辑动作中设置的变量。
onClipEvent (load) {
top = _y;
bottom = _y;
left = _x;
right = _x+100;
_x += 100;
}
onClipEvent (enterFrame) {
_parent.song.setVolume(_x-left);
}
创建滑动的平衡控件:
on (press) {
startDrag ("", false, left, top, right, bottom);
dragging = true;
}
on (release, releaseOutside) {
stopDrag();
dragging = false;
}
startDrag() 参数 left、top、right 和 bottom 是在剪辑动作中设置的变量。
onClipEvent (load) {
top=_y;
bottom=_y;
left=_x-50;
right=_x+50;
center=_x;
}
onClipEvent (enterFrame) {
if (dragging==true){
_parent.setPan((_x-center)*2);
}
}
有关 Sound 类的方法的更多信息,请参见 Sound 类。
![]() ![]() | |