programlocura Posted December 27, 2013 Share Posted December 27, 2013 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 More sharing options...
MisterMaSK Posted December 28, 2013 Share Posted December 28, 2013 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 thisvar 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 More sharing options...
rich Posted December 28, 2013 Share Posted December 28, 2013 Need to see some code really, probably only your game constructor. Sounds like the parent value being passed in doesn't exist or is of the wrong type. Link to comment Share on other sites More sharing options...
anissen Posted December 29, 2013 Share Posted December 29, 2013 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 statementif (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 More sharing options...
rich Posted December 29, 2013 Share Posted December 29, 2013 No worries, I will still make this more robust in the next update. Link to comment Share on other sites More sharing options...
programlocura Posted December 30, 2013 Author Share Posted December 30, 2013 Hi!I've moved that lines below the "target" line and it works! Thanks Link to comment Share on other sites More sharing options...
rich Posted December 30, 2013 Share Posted December 30, 2013 This change is in the dev branch now. Link to comment Share on other sites More sharing options...
Recommended Posts