(Dave probably read “lighting” instead of “lightning,” that’s what I did the first time. With lighting it wouldn’t really matter.)
Ok, so you want to sample the foreground layer to see when the lightning strikes and apply it to the background as a color adjustment.
The basic method would be as follows.
1) Add a point control to the foreground layer. This is used to pick the point where you want to sample.
2) Add Brightness Contrast Effect to the background layer and use this expression for the Brightness value:
targetLayer = thisComp.layer(thisLayer.index-1);
samplePoint = targetLayer.effect("Point Control")("Point");
sampleRadius = [10,10];
sampledColor_8bpc = 255 * targetLayer.sampleImage(samplePoint, sampleRadius);
R = Math.round(sampledColor_8bpc[0]);
G = Math.round(sampledColor_8bpc[1]);
B = Math.round(sampledColor_8bpc[2]);
V = (R+G+B)/3;
V
That code will take a 20 by 20 pixel square area around the point set by a point control on the layer above (index-1), average the RGB value to a single value and apply it to the Brightness of the layer below. ANY shift in top layer’s brightness will affect the brightness of the bottom layer. Thus, for practical purposes, you’d want to give “V” a threshold level, that occurs only during the actual flashes, above which it would affect brightness. And you could sample a smaller or larger area as needed. And if there are more layers in between you foreground and background layers, you’d have to change the layer selection value (index-[number of layers here]).