I created a new comp and added a red solid and a camera.
I set the 3D checkbox on the red solid. (cube switch)
I selected the red solid and pressed the T-KEY to reveal the opacity value. for the red solid.
I ALT-Clicked on the stop watch.
I pasted this code into the expression box.
footSource=thisComp.layer("Red Solid 2").position;
I pressed the numberpad enter key to lock the expression into place.
NOTE:If your red solid is named something other than "Red Solid 2" you will get an expression error message, simply correct the name of the solid and or camera as needed to match your comp.
Use the camera Track-Z tool to zoom the camera in and out. The red solid will fade in and out as the camera distance changes.
Because this expression returns a number between minBright and maxBright (in this case 0-100 i.e. a percentage) you can use this expression on any animatable parameter that requres a percentage range. Transition complete comes to mind, but I'm sure there are others as well.
Thanks for the code Mylenium!