I have an Entity class that is extending Sprite, and has a static manager. Here are the important bits of code:
class Entity extends Sprite {
private var _registered:Bool;
public function new() {
super();
_registered = false;
this.addEventListener(Event.ADDED_TO_STAGE, function(e) { _manager.register(this); _registered = true; });
this.addEventListener(Event.REMOVED_FROM_STAGE, function(e) { _manager.unregister(this); _registered = false; });
}
private static var _manager:EntityManager = new EntityManager();
public static function ofType(type:String):Array<Entity> {
return _manager.ofType(type);
}
}
My issue is, the REMOVED_FROM_STAGE events don’t fire for every entity when I remove their parent. So I might have a structure like this:
Scene
|-Entity
|-Entity
|-Entity
And if I remove the scene from the stage, not all of the Entities will have their REMOVED_FROM_STAGE event fired. I’ve checked the source and it looks like __dispatchChildren should hit all of them.
So I guess my question is, am I understanding correctly that all of the entities should have the REMOVED_FROM_STAGE event fired when their parent is removed from the stage? I’m having a hard time determining if the error is in my code or my understanding…