-
sampleImage() and subtraction
Just starting on an expression and have hit a bizarre wall. I’m using sampleImage() to test 5 layers and see if they have alpha in their centers, essentially testing if they’re empty or not. Then I add those five values to give me a number of “full” layers from 1 to 5 (one layer will always be full). Then I use that number to get a value from an array I’ve made. Works great UNTIL I try to subtract 1 to get the right array value. Then After Effects throws up an error that “property or method named ‘-1’ in Class ‘Array’ is missing…” Thinking it might be some weird syntax rule, I switch the project from Legacy to JavaScript. Then it tells me my first line in an undefined value.
The weird thing is, it seems to work under JavaScript if I use it in Source Text, but not under ExtendScript, even though it still gives me the correct value despite the error. Is there some weirdness with sampleImage() I’m missing?
target1=thisComp.layer("SHIRT_001.png");
a=target1.sampleImage([960,540],[5,5]);
target2=thisComp.layer("SHIRT_002.png");
b=target2.sampleImage([960,540],[5,5]);
target3=thisComp.layer("SHIRT_003.png");
c=target3.sampleImage([960,540],[5,5]);
target4=thisComp.layer("SHIRT_004.png");
d=target4.sampleImage([960,540],[5,5]);
target5=thisComp.layer("SHIRT_005.png");
e=target5.sampleImage([960,540],[5,5]);
total=a[3]+b[3]+c[3]+d[3]+e[3];
x=total-1;
val=[100,90,80,70,60];
val[x]