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をクリックしても画像が消えず、doclickdiv()のMySound.playからの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 に答える