我有一个像这样的剧本
var idsya1:Idsya1 = new Idsya1();
var iqlab1:Iqlab1 = new Iqlab1();
var ikhsya1:Ikhsya1 = new Ikhsya1();
if (idsya_1.hitTestObject(idsyabox_1))
{
idsya_1.enabled = false;
//idsya_1.visible = false;
idsya_1.buttonMode = false;
idsya_1.x = 145.30 ;
idsya_1.y = 168.05;
idsya1.play();
score+=10;
skor.text = " " + score;
}
if (iqlab_1.hitTestObject(iqlabbox_1))
{
iqlab_1.enabled = false;
// iqlab_1.visible = false;
iqlab_1.buttonMode = false;
iqlab_1.x = 719.95;
iqlab_1.y = 155.25;
iqlab1.play();
score+=10;
skor.text = " " + score;
}
if (ikhsya_1.hitTestObject(ikhsyabox_1))
{
ikhsya_1.enabled = false;
//idsya_1.visible = false;
ikhsya_1.buttonMode = false;
ikhsya_1.x = 459.95;
ikhsya_1.y = 198.75;
ikhsya1.play();
score+=10;
skor.text = " " + score;
}
Idsya1,Iqlab1和Ikhsya1是来自图书馆的声音..idsya_1,ikhsya_1和iqlab_1是一个动画片段。
我的问题是当idsya_1击中idsyabox_1然后idsya1声音将播放,并且它起作用,但是当ikhsya_1击中ikhsyabox_1时,播放的声音也是ikhsya1和idsya1,当iqlab_1击中iqlabbox_1时,所有声音都将播放..为什么是这发生了吗?
我的意思是当idsya_1点击idsyabox_1然后播放的声音是idsya1声音
当iqlab_1点击iqlabbox_1时,播放的声音是iqlab1声音
当ikhsya_1击中ikhsyabox_1时,播放的声音是ikhsya1声音
我该怎么做?
答案 0 :(得分:0)
可能是因为你在循环中检查碰撞,并且每次循环触发它都会检查你的每个奇怪名字MovieClips
是否有碰撞并相应地播放声音。如果您希望每次尝试播放声音,请尝试使用Boolean
属性来测试是否已播放。所以你会有这样的事情:
if (iqlab_1.hitTestObject(iqlabbox_1) && !iqlab_1SoundHasPlayed) // checking if the sound has already played
{
iqlab_1.enabled = false;
// iqlab_1.visible = false;
iqlab_1.buttonMode = false;
iqlab_1.x = 719.95;
iqlab_1.y = 155.25;
iqlab1.play();
score+=10;
skor.text = " " + score;
iqlab_1SoundHasPlayed = true;
}