反正没事干,就写一个教程,希望个位多多指教~~~ 先看看效果:
点击浏览该文件
在一个flash中,可能有两个背景音乐,或者是做一个flash的播放器,可以用到上面这个办法。
1,先做好几个按钮。一个是控制声音的停止,一个是控制声音的播放,一个就是选择声音,还有一个是动态文本框,变量是“aa”。
2,做好后,把所有元件拖到主场景中,在第一真上写上下面代码:
var listx=new Array("天空之城","Missing U");
count=0;//这个是声音选择按钮时的一个变量
mySound = new Sound(); //定义声音类
count=0;//这个是声音选择按钮时的一个变量
mySound = new Sound(); //定义声音类
3,在停止声音播放按钮上写上:
on(release){
mySound.stop();
}
mySound.stop();
}
4,在播放按钮上写:
on(release){
mySound.stop();
mySound.start();
}
mySound.stop();
mySound.start();
}
5,就是选择按钮,这里,我做的按钮是循还的,就是库里有两个声音,a,b,按一下就播放a,再按一下就播放b,再按就播放a……而且选择后,自动播放,不用再按播放按钮。因此,刚刚播放按钮就多了一句“ mySound.stop();”就是为了避免出错。
on(release){
var count;
count=count+1;
if(count>=2){
count=0-1;
count=count+1;
}
aa=listx[count];
mySound.stop();
mySound.attachSound(aa);
mySound.start();
}
var count;
count=count+1;
if(count>=2){
count=0-1;
count=count+1;
}
aa=listx[count];
mySound.stop();
mySound.attachSound(aa);
mySound.start();
}
6,最后,当然就是导入你想要播放的声音,还要把库里的声音设置好(这个不会就好好看看教程,基础嘛,就不说了~!)
7,Ctrl+Enter,测试成功。
