Verax

Cannot read property 'length' of undefined

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

Share this post


Link to post
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.

Share this post


Link to post
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();
        }

    }

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.