Jump to content

Getting this.add is undefined when calling outside function


Babsobar
 Share

Recommended Posts

Hello,

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.setInteractive();
        menuButton.on('pointerdown', function(pointer){
        this.scene.start('MainMenu')
         },this)
        menuButton.setScrollFactor(0);
} 

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

 Share

  • Recently Browsing   0 members

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