// 敬请批评指点 By 与梦同行 2004年4月23日-----╮
_root.attachMovie("about","about",-1);// ---<
// -----------------------------------------╯
onLoad()
{
// 初始化变量
var t = 0;
var i = 0;
}
// 主音乐,设置不同target,是为了不同音量
_root.createEmptyMovieClip("MC_one", 1);
sound_one = new Sound("MC_one");
sound_one.attachSound("梁祝");
sound_one.start(0,9999);
sound_one.setVolume(100);
// 背景音乐,与主音乐不同音量
_root.createEmptyMovieClip("MC_two", 2);
sound_two = new Sound("MC_two");
sound_two.attachSound("舞蹈");
sound_two.start(0, 9999);
// 实现了与主音乐不同音量
sound_two.setVolume(5);
// 捆绑播放与暂停按钮,设置显隐
// ★·→"pause_m"、"play_m"与"MC_one"以及"MC_two"不同深度!!
_root.attachMovie("pause_m", "pause_m", 3);
_root.attachMovie("play_m", "play_m", 4);
play_m._visible = false;
pause_m._visible = true;
play_m._x = pause_m._x = 500;
play_m._y = pause_m._y = 350;
play_m.onRelease = function()
{
sound_one.stop("梁祝");
sound_one.start(t,1); // 仅播放一次,否则导致声音重叠
sound_two.setVolume(5);
this._visible = false;
pause_m._visible = true;
loop = true; // 设置循环为真,通知"loopmusic"函数执行声音循环
// 以下显示相关信息
_root.createTextField("info",5,150,100,250,110);
with (info)
{
textColor = 0xFF0000;
border = true;
size = 20;
text = "nt暂停在曲目的第 " + t + " 秒;n" + "nt从 " + t + " 秒处重新播放音乐;n" + "nt当前为第 " + i + " 次重新播放!n";
}
}
pause_m.onRelease = function()
{
// 也可"sound_one.stop();",因为已经指定target
sound_one.stop("梁祝");
t = sound_one.position / 1000;
i++;
sound_two.setVolume(20);
this._visible = false;
play_m._visible = true;
_root.createTextField("info",5,150,100,250,110);
with (info)
{
textColor = 0x0000FF;
border = true;
text = "nt暂停在曲目的第 " + t + " 秒;n";
}
}
function loopmusic()
{
// 判断已播放毫秒数是否等于声音总毫秒数 判断是否要循环
// 如果满足条件,声音从头开始播放9999次^-^
if (sound_one.position == sound_one.duration && loop)
{
sound_one.start(0,9999);
loop = flase;
}
}
// 每0.1秒刷新一次:如刷新时间过长,会导致第一次循环时有明显停顿
var sound_one_ID = setInterval(loopmusic, 100);
评论