Off topic: Please don’t start your function name with capital letters.
On topic:
Idk if the problem is the one specified by Thomas. But if so, why don’t pass the composition as a parameter in your function?
Something like
function detect(comp) {
var videoLayer = comp.selectedLayers[0];
var time = comp.time;
var frame = Math.round(time / comp.frameDuration);
var opacityLevel = videoLayer.property("Transform").property("Opacity");
var threshold = 48.0;
above = false;
while (frame <= 100) {
t = frame * comp.frameDuration;
if (above) {
if (opacityLevel.valueAtTime(t, true) != threshold) {
frame++;
above = false;
}
} else if (opacityLevel.valueAtTime(t, true) == threshold) {
above = true;
var myMarker = new MarkerValue("Mark");
videoLayer.property("Marker").setValueAtTime(t, myMarker);
}
frame++;
}
}
//and call it like this on the onClick event of the button
detect(app.project.activeItem);
I need to see the entire code and test it in order to see the problem, because it’s not that obvious.
If you can share your code or file, I could be more explicit.
Andrei
My Envato portfolio.