研究国外flash中的音乐控制 2005-10-2918:15
?今天主要研究了一下国外的几个flash中的音乐控制,主要要实现的功能为:一个音乐开关,当点击之后,声音由大到小减弱到0,并且暂停。当再次点击,声音由小到大,并且从暂停出继续播放。
主要实现步骤:
有关声音可以写在同一个MC里,这个MC内有2层。
主MC有3层,第一层放AS:
mysound=new Sound();
mysound.attachSound("music"); //将库中链接标志符为music的文件付给mysound
mysound.start(0,100); //循环100次
第2层放置一个MC(随便什么,画一个矩形即可)。选择这个MC,在上面放入下面的AS:
onClipEvent (load)
{
_root.soundstatus = "on";
_root.mySound = new Sound(_level0);
_root.mySound2 = new Sound(_level1);
_root.mySound3 = new Sound(_level2);
_root.mySound4 = new Sound(_level3);
_root.mySound5 = new Sound(_level4);
maxvolume = 100;
minvolume = 0;
}
onClipEvent (enterFrame)
{
if (_root.soundstatus == "on")
{
step = 5;
} // end if
if (_root.soundstatus == "off")
{
step = -5;
} // end if
maxvolume = maxvolume + step;
if (maxvolume > 100)
{
maxvolume = 100;
} // end if
if (maxvolume < 0)
{
maxvolume = 0;
} // end if
_root.mySound.setVolume(maxvolume);
_root.mySound2.setVolume(maxvolume);
_root.mySound3.setVolume(maxvolume);
_root.mySound4.setVolume(maxvolume);
_root.mySound5.setVolume(maxvolume);
}
在第3层放入一个起到开关作用的MC,这个MC里面又放入一个MC,里面的这个MC内有3层
1为AS
2为按钮
3为开关效果
在AS的第一、二帧分别写入:stop();
按钮起到触发事件的作用,在它的第1帧写入:
on (release)
{
gotoAndPlay(2);
}
on (release)
{
_root.soundstatus = "off";
}
按钮的第二帧写入:
on (release)
{
gotoAndPlay(1);
}
on (release)
{
_root.soundstatus = "on";
}
最下面一层就是开关的效果,可以在第一帧里面写on,第2帧写off
另外,导入的mp3文件的“链接”要勾选第1,3项,链接标示符为mysound.