2011-04-26 170 views
1
  soundManager.url = 'swf/'; 

      soundManager.createSound({ 
       id: 'mySound', 
       url: 'http://localhost/htmlshooter/mp3/gun.mp3', 
       autoLoad: true, 
       autoPlay: true, 
       volume: 100 
      }); 

      function placeimage(){ 
       var t = $('<img src="img/php/target.png" alt="image" id="' + Math.floor(Math.random()*55) + '" onclick="doclickimg(this.id);">'); 
       $('#div').append(t); 
       t.css('left', Math.floor(Math.random()*(800 - t.width()))); 
       t.css('top', Math.floor(Math.random()*(300 - t.height()))); 
       setTimeout(placeimage, 2000); 
      } 

      placeimage(); 

      function doclickimg(imgid){ 
       doclickdiv(); 
       $('#'+imgid).remove(); 
       // +1 score 
      } 


      function doclickdiv() { 
       mySound.play(); 
       // -1 bullet 
      } 

現在,當我點擊我的div時,圖像不會消失,並且它說MySound從mySound.play在doclickdiv()中沒有定義。Soundmanager:MySound is not defined

請幫幫我!爲什麼這不起作用?

回答

2

您收到此錯誤,因爲mySound尚未定義對象。你可能將有更好的運氣...

var mySound = soundManager.createSound({ 
    id: 'mySound', 
    url: 'http://localhost/htmlshooter/mp3/gun.mp3', 
    autoLoad: true, 
    autoPlay: true, 
    volume: 100 
}); 

或...

function doclickdiv() { 
    soundManager.getSoundById('mySound').play(); 
    // -1 bullet 
} 
1

mySound沒有定義。你可能想改變:

soundManager.createSound({ 
      id: 'mySound', 
      url: 'http://localhost/htmlshooter/mp3/gun.mp3', 
      autoLoad: true, 
      autoPlay: true, 
      volume: 100 
     }); 

var mySound = soundManager.createSound({ 
      id: 'mySound', 
      url: 'http://localhost/htmlshooter/mp3/gun.mp3', 
      autoLoad: true, 
      autoPlay: true, 
      volume: 100 
     }); 
相關問題