Stage.stageHeight and parent.removechild(this) kills my program

i’m really new to haxe/openfl but i’ve not been doing to badly . . . I think but i’ve ran into a problem and I cant work out
:frowning:

	 if (PushClass.controller == "dead")
	{
		_tick -= 1;
		if (_tick < 0)
		{
			parent.removeChild(this);
		}
	}
	
	//abs
	//_xAbs = Math.abs(stage.stageWidth / 2 - this.x);
	//_yAbs = Math.abs(stage.stageHeight / 2 - this.y);

this works but when i remove the comments for stage.stageHeight and stage.stageWidth it gives me this error:
AL lib: (EE) alc_cleanup: 1 device not closed
please hewlp :slightly_smiling:

no worrys fix it when i went to fall asleep

You should do your maths before removing it from the stage, since you remove the references to location and the stage component within the Sprite when you remove it, causing the crash.

Neko in particular will complain about this, because it doesn’t like null's. If you absolutely need to use those references after removing the object, I would create a local variable at the top of your function reference the x and y position of your object, and use Lib.current.stage instead of just stage. That should prevent the crash :slightly_smiling:

thank you :slight_smile: when I had a think over it thought it might be something like this

1 Like