6 Replies Latest reply on Jun 23, 2009 10:53 AM by sbaden11

    Problems with an expression...

    sbaden11

      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.

        • 1. Re: Problems with an expression...
          Adolfo Rozenfeld Adobe Employee

          sbaden:

          You may want to post this in the expressions and/scripting (see below) forums, where masters such as Dan Ebberts are regular contributors (mind you, "such as Dan Ebberts" probably means "Dan Ebberts").

           

          You can't manipulate UI switches like Visibility with expressions (turn it on if a condition is met, for example).

          Expressions return the values of those switches, so you can modify a property value in a certain way if it's active, for example.

           

          To drive UI elements, you need to use scripting, not expressions.

          1 person found this helpful
          • 2. Re: Problems with an expression...
            Mylenium Most Valuable Participant

            sbaden04 wrote:

             

            The code doesn't get any errors and appears to run but does not work.

             

            As explained before, AV properties and switches are read-only for expressions (which is logical, as an expression is a sandboxed piece of code that should not never be able to modify or break out of its sandbox). What you want can however easily be achieved by modifying your expression to work on teh opacity property. The result would be the same visually, and AE is even smart enough to not consider layers with 0%opacity for processing, so there's not even a performance hit with this alternate approach.

             

            Mylenium

            1 person found this helpful
            • 3. Re: Problems with an expression...
              sbaden11 Level 1

              Thanks Mylenium,

               

              I tried changing to opacity as you recomended but I'm getting the same results. The text value in the text layer is "DEN" but when I change the code to opacity= 0  "DEN" changes to "0".

               

               

               

              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;
                              }
                  }

               

              Picture 9.png

              • 4. Re: Problems with an expression...
                Adolfo Rozenfeld Adobe Employee

                No, again, you can't modify the value of a property from another property.

                You'd have to write an expression for the opacity property, and it's that expression what should check the text layer's source text, and change opacity according to your criteria.

                • 5. Re: Problems with an expression...
                  Mylenium Most Valuable Participant

                  Yupp, as said, the expression must be applied to the property it is supposed to modify. Apologies, if my otehr post was vague in that regard.

                   

                  Mylenium

                  • 6. Re: Problems with an expression...
                    sbaden11 Level 1

                    Hey Mylenium and Adolfo...

                     

                    Thank you very much... You are absolutely correct. I was going at it all backwards. I made the changes you recommended and worked perfectly.

                     

                    I added the code to the opacity and it changed imediately.

                     

                     

                    if (comp("changeName").layer("triCode").text.sourceText == thisLayer.source.name)
                        {
                            transform.opacity = 100;
                        }
                    else
                        {
                            transform.opacity = 0;
                        }

                     

                     

                    Thanks again for all your help!!