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.play 中的 doclickdiv() 的 MySound 未定义。

请帮我!为什么这不起作用?

4

2 回答 2

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
}
于 2011-04-26T21:20:06.180 回答
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
        });
于 2011-04-26T21:21:17.600 回答