Jump to content

Cannot read property 'length' of undefined


Verax
 Share

Recommended Posts

Hi guys, I was trying to make a group of objects and got the following error:

phaser.js:45776 Uncaught TypeError: Cannot read property 'length' of undefined

Everything seems to be fine, anyone has a clue why this might be happening?

 

FYI: I'm using Phaser 2.5.0

 

Thank you for your help.

 

 

Captura.PNG

Link to comment
Share on other sites

You'll likely need to include code for anyone to pick out the specific problem, but the problem looks like you are trying to check the length of an uninitialized variable.

Something along the lines of:
 

var myArray;
console.log(myArray.length)  // <-- myArray is currently undefined


It may also be a little more obscure, if the undefined variable is being passed into a function or something.

Link to comment
Share on other sites

Well, I'm just making a group, and there is no loop in my code, it says it's in Phaser's postupdate function which would look like this:

postUpdate: function() {

        if (this.customRender)
        {
            this.key.render();
        }

        if (this.components.PhysicsBody)
        {
            Phaser.Component.PhysicsBody.postUpdate.call(this);
        }

        if (this.components.FixedToCamera)
        {
            Phaser.Component.FixedToCamera.postUpdate.call(this);
        }

        for (var i = 0; i < this.children.length; i++)
        {
            this.children.postUpdate();
        }

    }

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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