The events look correct to me as you can use the layer index to reference the layer. To me it looks like the issue is:
the instance is invisible and setting the layer to visible does not set any instance on it to visible, layer and instance visibility is separate.
To fix it make sure you set both the instance and the layer visible, or set the instance to visible and only toggle the layers visibility (or vice versa).