7 Replies Latest reply on Apr 19, 2010 2:27 AM by transendental

    Accessing the variables of a nested comp

    transendental

      Hi,

       

      I have a main comp and a shapes comp. The shapes comp is nested in the main comp. The shapes comp contains an inner rectangle and an outer rectangle and the outer rectangle is on layer 1.  In the main comp I need to change the opacity of the outer rectangle without effecting its inner rectangle. 

       

      I've tried: comp("shapes comp").layer(1).transform.opacity=50; in the opacity of the main comp but this changes the opacity of the entire shapes comp.


      Any help would be greatly appreciated.


      Thanks.

        • 1. Re: Accessing the variables of a nested comp
          Szalam Adobe Community Professional & MVP

          In your main comp, create a null layer. Name it Opacity control. Apply Effect>Expression Controls>Slider to it.

          In your shapes comp alt-click (or option-click on a Mac) the opacity property of your inner rectangle. Write the following expression:

          comp("Main comp").layer("Opacity control").effect("Slider Control")("Slider");

          Then in your main comp you can control the opacity by moving the slider on the null object.

          Or, rather than writing the code and making sure all of your capitalization and spelling of the layers is correct, just drag the timeline of your precomp out separate from your other comp's timeline and pickwhip from the opacity on the rectangle layer to the slider effect on the null.

          1 person found this helpful
          • 2. Re: Accessing the variables of a nested comp
            transendental Level 1

            Thanks Szalam,

             

            Partial success.  When I set the slider to 0 the outer rectangle disappears completely and the when I set it to 1 its opacity (in the main comp) in 100%, although in the shapes comp the opacity tracks the slider accuratly and sets the opacity correctly.  I've tried going into decimals on the slider but it has a sharp cut off point where the rectangle is either on or off.

            • 3. Re: Accessing the variables of a nested comp
              Mylenium Most Valuable Participant

              Where do you apply the expression? On the opacity parameter of the entire shape layer or inside a shape blending group? Do you use specific blending modes that may just make it appear as if it where using incorrect ranges because the layer content appears instantanuously rather than gradually based on the underlying formula?

               

              Mylenium

              • 4. Re: Accessing the variables of a nested comp
                transendental Level 1

                Thanks Mylenium,

                 

                This approach is actually not addressing my original need.  What I'm hoping to be able to do is take an object oriented programming approach.  I'd like to be able to create an object (the 'shape comp') which I can drop into many other comps but be able to make adjustments to the properties of a shape comp from the comp within which it is nested.  The changes to any one shape comp must not effect any of the other nested shape comps.

                 

                Is this possible?

                • 5. Re: Accessing the variables of a nested comp
                  Szalam Adobe Community Professional & MVP

                  Not if multiple copies of the precomp are on the screen at the same time.

                  And only if the parts of the precomposition that are used are from different points in the precomposition's time.

                  So, you would want to make your precomp the same size, or longer than the amount of time it will be used so that no one instance is from the same point on the precomp's timeline.

                   

                  I think the basic answer to your question is no..

                  1 person found this helpful
                  • 6. Re: Accessing the variables of a nested comp
                    A. Cobb Level 3

                    The answer is no.  A comp has no way of knowing what comp it is nested in.

                     

                    Also, in your original post it looks like you were trying to set the value of the opacity property of the layer from an expression on another property (on another layer in another comp).  In expressions, only user-defined variables can be written to.  Everything else, including the values of layer properties, is read-only.  The only way you can modify the value of a property is by applying an expression to that property, and you don't modify the value through an assignment statement (e.g. "opacity = 50"), but rather by writing the last statement of the expression such that it evaluates to the desired value (e.g. "50").  That's the "expression" part of expressions.

                    • 7. Re: Accessing the variables of a nested comp
                      transendental Level 1

                      Thanks guys.  I know what to put on my wish list.