Jump to content

Noob: function creation syntax - Uncaught Reference Error


gdogfunk
 Share

Recommended Posts

Hello,

 

I'm currently learning phaser and have been going through the Zenva courses as well as tuts from phaser.io and other online sources and last night I had a main menu screen working just fine and decided to break up the code into more manageable files with a boot.js, preload.js, mainmenu.js, etc. and I'm stuck on an error where it will not move on to the main menu state due to an 'Uncaught ReferenceError: actionOnClick is not defined'.   However, it is defined.

 

When I had my file working, I had the function syntax as:

 

function preload (){}

function create () {{

function update () {}

function actionOnClick (){}

etc.

 

However, in the lessons that have the code spread over multiple files, I see the syntax of the functions as:

 

 

Game.MainMenu = function(){};
 
Game.MainMenu.prototype = {
 
create: function () {}, (with a comma after each method)
actionOnClick () {}
etc.
 
After formatting my code like the above comma-separated syntax, I am getting the Uncaught reference error.  I have tried reordering the functions thinking maybe the actionOnClick needed to be above the create: function(), but that's not working.
 
Can someone please explain the difference of the function syntax above and why commas are used to separate methods in the one syntax and not the other?  Is there a reasoning to using one over the other?  And how might I solve the reference error?
 
Thank you very much in advance!
 
Ryan
 
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...