Jump to content

Getting this.add is undefined when calling outside function


Recommended Posts


I'm trying to call a function in another file called createButtons.js; which contains this:

function createButtons (){

//Create Back to menu Button
    var menuButton = this.add.sprite(width-width+120,height-height+60,'menuButtons','editorb0.png');
        menuButton.on('pointerdown', function(pointer){

The function is loaded in my index.html; then I call the function in my main file in the create section simply with "createButtons();".

I get the TypeError: "this.add is undefined" in the console.

Any help is greatly appreciated, I'm sort of a noob in all this but i'm learning :)


Link to comment
Share on other sites


  • Recently Browsing   0 members

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