0

我有这样的脚本

 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 声音

我怎样才能做到这一点?

4

1 回答 1

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;
 }
于 2013-02-11T06:19:59.743 回答