-
Trigger source text change with markers
Hi,
I have a text layer where the source text comes from a substring of the name of a layer in another comp. In this case it comes from the layer with the highest index value.
I’d like to turn this into an expression whereby each marker will decrease the layer index by 1, and thus change the source text accordingly.
Below is what I have so far. I don’t think I’m setting up the marker triggers correctly – to be honest I don’t fully understand what’s going in this part of the expression as I’ve just copied it from tutorials focusing on triggering position animations and the like.
I’m finding that up until the first marker my source text just reads “1” and after that it reads as the first line of source text that I want, but doesn’t then update with subsequent markers.
Can anyone please help?
//set variables
sc = comp("otherComp"); // source comp
lc = sc.numLayers; // layer count of source comp
idx = lc; // layer index;
m = thisLayer.marker;//define function that updates text
function upd() {idx = idx--};//marker triggers
if (m.numKeys > 0) {
n = m.nearestKey(time).index;
if (time < m.key(n).time) n--;
if (n > 0) {
upd();
sc.layer(idx).name.substr(3,sc.layer(idx).name.length);
}}else {
sc.layer(idx).name.substr(3,sc.layer(idx).name.length);
}