场景第一帧写上如下代码:(库中加载声音,标识符为:“myMusic”)
mySound = new Sound();
mySound.attachSound("myMusic");
mySound.start();
var soundkey = 1;//定义变量soundkey,监视声音播放情况
单个按钮上写上如下代码:
on (release) {
soundkey =-soundkey;//使变量值为原值相反数
trace('soundkey='+soundkey);//输出显示soundkey的值
if (soundkey == 1) {
mySound.stop();
mySound.start();
} //如果soundkey值为正,则播放声音,mySound.stop()使声音停止后再播,以免声音产生叠加,影响效果
else {
mySound.stop();
}//如果soundkey值为负,则声音停止
}