How to use a layer as mask for another
I think you need to use a track matte - this lets you use one layer to control the transparency of another:

https://helpx.adobe.com/after-effects/using/alpha-channels-masks-mattes.html