Thanks Andrei, this works!
The idea was to have several different matches, all listed in the same JSON, with each in a separate composition (so I can have all those compositions transition together for the final video.) To make things a bit simpler, it would be great if I could just copy-and-paste all the icon layers with their opacity expressions from one match composition to the other, without having to edit every layer to reference the right “match” in the JSON file. So, say the JSON looks like:
"match1team1name": "Team 1",
"match1team2name": "Team 2",
"match2team1name": "Team 3",
"match2team2name": "Team 4",
"match3team1name": "Team 1",
"match3team2name": "Team 3",
"match4team1name": "Team 2",
"match4team2name": "Team 4"
The top two layers of a match composition are text layers called “Team1” and “Team2”. In the first composition, they draw their Source Text from “match1team1name” and “match1team2name” in the JSON – in the second composition they draw from “match2team1name” and “match2team2name” and so on.
So I was thinking, could I remove all the “team icon” entries from the JSON, and just use the contents of the Team1 and Team2 layers for matching instead? That way I’d only be setting the team names once.
Your expression was:
eval("var json=" + footage("json.json").sourceText);
(json[match1team1icon]==thisLayer.name) ? 100 : 0
But instead, I was thinking of something like:
(thisComp.layer("Team1").sourceText==thisLayer.name) ? 100 : 0
So it’s just looking at the text layer that’s taking its contents from the JSON. That way I could copy all those Team icon layers from composition to composition and the expressions, and would only have to change those two text layers.
Unfortunately, this expression doesn’t seem to work (the opacity is always 0) – I wondered if you had any ideas why that might be?
Thanks again for your answer – and sorry for the long follow up question!
Take care,
Phil.