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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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