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时,图像不会消失,并且它表示未定义doclickdiv()中MySound.play中的MySound。

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

最佳答案

您收到此错误的原因是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
}

10-07 18:10