programlocura

Phaser 1.1.3 - Getting error

Recommended Posts

Hi everyone!

 

I've downloaded the 1.1.3 min version and added into my project, but i'm getting the following error:

Uncaught TypeError: Cannot read property 'style' of null - line 21670.

I was looking for the bug, it seems that "target" variable, where the code says: document.getElementById(parent) is a null value. 

 

Maybe i'm doing something wrong, but i've only changed the phaser.js file (build directory) from the 1.1.3 to 1.1.2.

 

Thanks in advance,

Regards.

Share this post


Link to post
Share on other sites

this is how this error happened to me - 

var game = new Phaser.Game(960, 640, Phaser.CANVAS, 'my_game');

here's how you create a new game right?..

so you need to have a  div #my_game in you html
<div id="my_game" ></div>

or you can just do it like this

var game = new Phaser.Game(960, 640, Phaser.CANVAS, '');

and not give any div id...in this case the game will be added directly to the body of the page...

try it see if it works.

Share this post


Link to post
Share on other sites

EDIT: Don't listen to me, I made a mistake; I removed the parent element and forgot to update my Game constructor arguments! Do'h!

 

 

I get the same error. The problem occurs in the addToDOM-function in phaser.js:

addToDOM: function (canvas, parent, overflowHidden) {        var target;        if (typeof overflowHidden === 'undefined') { overflowHidden = true; }        if (parent)        {            // hopefully an element ID            if (typeof parent === 'string')            {                target = document.getElementById(parent);            }            // quick test for a HTMLelement            else if (typeof parent === 'object' && parent.nodeType === 1)            {                target = parent;            }            if (overflowHidden)            {                target.style.overflow = 'hidden';            }        }        // fallback, covers an invalid ID and a none HTMLelement object        if(!target)        {            target = document.body;        }        target.appendChild(canvas);        return canvas;    }

One way to fix it is as follows:

 

Move the following statement

if (overflowHidden)            {                target.style.overflow = 'hidden';            }

below this statement

// fallback, covers an invalid ID and a none HTMLelement object        if(!target)        {            target = document.body;        }

This fixes the case where there is a parent element and overflowHidden is true.

 

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.