简体   繁体   中英

Function being used, when it isn't a function?

Battle.CreateInputs = function(json) {
if (json.Battle.Continue !== undefined) {
    $('#attackBox').css('display', 'none');
    $('#Continue').mousedown(function(e) {
        Battle.PlaySound('die')
        Battle.Continue($(this).attr('continue'), e);
        return false;
    });
} else if (json.Battle.Captcha !== undefined) {
    $('#attackBox').css('display', 'none');
    $('#CaptchaForm').submit(function(e) {
        Battle.PlaySound('captcha')
        Battle.SubmitCaptcha($('#Captcha').val(), e);
        return false;
    });
} else if (json.Battle.Restart !== undefined) {        
    $('#attackBox').css('display', 'none');
    $('#Restart').click(function(e) {
        Battle.PlaySound('coin')
        Battle.Restart($(this).attr('restart'), e);
        return false;
    });
} else {
    $('#attackBox').css('display', 'inline-block');
    $('input').mousedown(function(e) {
        Battle.PlaySound('hit')
        Battle.Move($(this).attr('post_code'), e);
        return false;
    });
}}; 

So, this is the code that I'm having problems with. I always receive the error "Battle.PlaySound is not a function". Here is a link to the Javascript and the code snippet that I was using.

My Code - http://pastebin.com/BnHLaYN3

Site Javascript - http://pastebin.com/0NcyWvGn

Battle.PlaySound is indeed not a function. As per your code:

Battle.PlaySound = {};

You are defining it as an object.

Should be something like this instead:

Battle.PlaySound = function(sound) {
    //Do something with sound here.
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM