If you are familiar with after effects, think of a layer object as a sub-comp. If you click on the Scene name in the object manager you can then go over to the render tab and select how the layers affect each other. You can then put your mask on the very lowest line in the layer object and it will then mask everything in the layer object that is above it. If you move it up one, it masks everything except the object that is below it. Remember that a layer object has no z position. You can't move it back or forward. Good Luck.
#XPression