Skip navigation
Currently Being Moderated

Problems with an expression...

Jun 23, 2009 9:57 AM

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.

 
Replies
  • Currently Being Moderated
    Jun 23, 2009 10:38 AM   in reply to sbaden04

    Just looking at your code, without actually trying it, my guess would be that it is because you didn't put the layer name triCode in quotes.

     

    change:

    if (currentLayer.source.name == triCode)

     

    to:

    if (currentLayer.source.name == "triCode")

     

     

    your way would make all of the results false, because their is no variable named triCode .... and that's what it would be referencing without quotes.

     

    Give that a try and let me know if it works.

     

    good luck!

    elaine

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 23, 2009 11:29 AM   in reply to sbaden04

    Much better approach! Glad you were able to get it resolved.

     

    take care,

    elaine

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points