FLASH如何用按钮控制声音

2025-03-10 10:35:32
推荐回答(2个)
回答1:

第一步:新建四个按钮,分别命名为: btn1、btn2、btn3、btn4,注意是变量名,属性栏“按钮”四个字下面的那个框里的;
第二步:新建四个影片剪辑,分别命名为: mc1、mc2、mc3、mc4,注意是变量名,属性栏“影片剪辑”四个字下面的那个框里的;
第三步:分别进入每个影片剪辑进行编辑,第一帧为空帧,接着选中第二帧,把音乐放在第二帧里;
第四步:四个影片剪辑都进行第三步操作,不过在第二帧里放入不同的音乐;
第五步:返回主场景,选中第一帧,按F9弹出脚本面板,写下:
for (i=1; i<=4; i++) {
_root["mc"+i].stop();
}
_root.btn1.onPress = function() {
stopAllSounds();
for (i=1; i<=4; i++) {
_root["mc"+i].gotoAndStop(1);
}
_root.mc1.gotoAndPlay(2);
};
_root.btn2.onPress = function() {
stopAllSounds();
for (i=1; i<=4; i++) {
_root["mc"+i].gotoAndStop(1);
}
_root.mc2.gotoAndPlay(2);
};
_root.btn3.onPress = function() {
stopAllSounds();
for (i=1; i<=4; i++) {
_root["mc"+i].gotoAndStop(1);
}
_root.mc3.gotoAndPlay(2);
};
_root.btn4.onPress = function() {
stopAllSounds();
for (i=1; i<=4; i++) {
_root["mc"+i].gotoAndStop(1);
}
_root.mc4.gotoAndPlay(2);
};
这样就可以了,点按钮1播放mc1里的音乐,点按钮2就播放mc2的,依此类推。

回答2:

用这个命令
stopallsound()
play()
就可以了