neurofuzzy Posted October 19, 2014 Share Posted October 19, 2014 I have a button with a callback that effectively completes a state and moves on to the next state. The world remains but I remove the UI (including that button). The problem is, it seems that the callback fires on mouseup, but before the button changes back to the up state. So, when the button is removed using button.destroy(), it causes null reference errors:Uncaught TypeError: Cannot read property 'cache' of nullIt is referencing this.game.cache, but this.game is null. I could fork Phaser and fix this, but I was wondering if maybe I'm just doing it wrong. Thanks! Link to comment Share on other sites More sharing options...
Juholei Posted March 27, 2015 Share Posted March 27, 2015 I encountered this issue now myself. Below is the code from my project.var PointEditScreen = function(game) { Phaser.Image.call(this, game, 600, 50, 'background'); var exitButton = game.add.button(360, 5, 'exit-button', this.closeScreen, this, 1, 0, 2, 0); this.addChild(exitButton);PointEditScreen.prototype.closeScreen = function() { this.destroy();};The code works, but results in the same error as with the original poster: "Uncaught TypeError: Cannot read property 'cache' of null". The error does not happen if don't I give any values to downFrame and upFrame when creating the button. Also, if I set the downFrame and upFrame to the same value, in my case the frames would then be 1, 0, 2, 2, the error does not occur. So is this a bug or am I doing something wrong? Edit: Seems to be fixed in Phaser 2.3.0. My problem was with 2.2.2. Great Link to comment Share on other sites More sharing options...
Aymeric Posted April 16, 2015 Share Posted April 16, 2015 Sounds like there are still some issues with Phaser 2.3.0 https://github.com/photonstorm/phaser/issues/1748 Link to comment Share on other sites More sharing options...
Recommended Posts