Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Phaser 1.1.3 - Getting error


programlocura
 Share

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.

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

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

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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