Add an object to your top layer, or use an object already present in your top layer, and use that object, to reference the top layer.
for 0 to someobject.layerNumber
Hehe I know. There isn't anything like this, there really isn't a reason to use number of layers in events and logic.
I use it a lot for zooming purposes.