I hope I'm not double posting but was told that this would be a better place to post this question:
Here's the scenario:
I have two comps: CompA and CompB
Source Text example: "DEN" (text layer in CompA)
Source Name example: "DEN" (mov in CompB)
I have written an expression and put it into the Source Text of a text layer in CompA. The code gets the source text and then loops through the layers in CompB comparing the Source Name to the Source Text in CompA. If the layer's source name matches the source text of CompA it enables the layer otherwise it disables it.
The code doesn't get any errors and appears to run but does not work. Any help would be greatly appreciated.
Here is the code:
var triCode = text.sourceText; //Gets source text from this comp (comp A)
var numberOfLayers = comp("teamLogo").numLayers; //Gets number of layers from comp B
/* Loops through comp B layers comparing layer name to source text in comp A */
for ( i=1; i <= numberOfLayers; i++ )
{
var currentLayer = comp("teamLogo").layer(i)
if (currentLayer.source.name == triCode)
{
currentLayer.enabled = true; //If comparison is true turns layer on
}
else {
currentLayer.enabled = false; //If comparison is false turns layer off
}
}
I noticed that the script is actually changing the text layer text in Comp A to "false". Not sure why... When I change the reference to false in the code to something else I get an error.
Mylenium recomended that I change to setting the opacity value instead of enabling the layer because expressions can't control switches like enable. I changed the code to:
var triCode = thisLayer.text.sourceText;
var numberOfLayers = comp("teamLogo").numLayers;
for ( i=1; i <= numberOfLayers; i++ )
{
var teamLayer = comp("teamLogo").layer(i)
if (teamLayer.source.name == triCode)
{
teamLayer.opacity = 100;
}
else
{
teamLayer.opacity = 0;
}
}
I'm getting the same results as with the previous code.