New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroying Button dispatch Error #1748

Closed
alamboley opened this Issue Apr 16, 2015 · 3 comments

Comments

4 participants
@alamboley
Copy link

alamboley commented Apr 16, 2015

Hey, I'm using Phaser 2.3.0 and I still have a bug concerning destroying a button after ckicking on it. I'm aware of this forum post.

btn = add.button(0, 0, 'general', _validated, this, 'ValiderOver.png', 'Valider.png', 'ValiderActif.png', 'Valider.png', container);
btn.input.useHandCursor = true;

function _validated() {
     btn.destroy(); => Uncaught TypeError: Cannot read property 'getFrameByName' of null
}

An other issue is to use container.removeAll(true);. If I don't specify the true, no error but I still can see the hand cursor (and I've my callback called). If I specify the true arg, I've the same error than previously. The weird thing is it's happening despite I clicked on a button which is not in this group!

If I put some setTimeouteverywhere, no issues.

@netgfx

This comment has been minimized.

Copy link

netgfx commented Apr 16, 2015

I noticed this also, maybe it is also related to this post I made: http://www.html5gamedevs.com/topic/13843-events-linger-after-remove-and-destroy/#entry78906

@georgefrick

This comment has been minimized.

Copy link

georgefrick commented Jun 18, 2015

I am also experiencing this, I've been trying workarounds to get the button off the screen without breaking everything with no luck.

My current workaround, is to not destroy the button, but only remove it;
this.playButton.inputEnabled = false;
game.world.remove(this.playButton);
//this.playButton.destroy();
this.playButton = undefined;

photonstorm added a commit that referenced this issue Jul 8, 2015

All Game Objects have a new boolean property called `pendingDestroy`.…
… If you set this to `true` then the object will automatically destroy itself in the *next* logic update, rather than immediately. This is useful for cases when you wish to destroy an object from within one of its own callbacks, such as with buttons or other input events (thanks @alamboley #1748)
@photonstorm

This comment has been minimized.

Copy link
Owner

photonstorm commented Jul 8, 2015

This is now addressed in the dev branch via the new pendingDestroy property. Here's an example showing use:


var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });

function preload() {

    game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);

}

var button;

function create() {

    game.stage.backgroundColor = '#4b0049';

    button = game.add.button(game.world.centerX - 95, 460, 'button', nukeButton, this, 2, 1, 0);

}

function nukeButton() {

    button.pendingDestroy = true;

    text = game.add.text(game.world.centerX, game.world.centerY, '- button nuked -', { font: '64px Arial', fill: '#ffffff' });

    text.anchor.set(0.5);

}

@photonstorm photonstorm closed this Jul 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment