8 Replies Latest reply on Nov 16, 2009 9:08 AM by Trish Meyer

    Stop an expression and hold the current value

    Andy Bay Level 1

      Hi!

       

      How do you stop and expression so that the layer keeps it's value before the expression was stopped?

       

      I have an expression that is telling a layer to move on the x axis until it reaches 10 seconds. After ten seconds I want it to keep the value that it had when it was stopped. My expression so far looks like this:

       

      if (time<10) value+time*10 else ValueAtTime

       

      but it's returning the following error: Class 'global' has no property or method named 'ValueAtTime'.

       

      Is it possible to use the ValueAtTime to achieve this?

       

      Any help will be appreciated!

        • 1. Re: Stop an expression and hold the current value
          Todd_Kopriva Level 8

          One thing to note: Expressions are case-sensitive. I see that you have 'ValueAtTime', not 'valueAtTime'.

           

          Also, valueAtTime takes an argument, which represents the time from which to read the value.

          1 person found this helpful
          • 2. Re: Stop an expression and hold the current value
            Andy Bay Level 1

            Thank you Todd, that was helpfull!

             

            It's still not working though, now the error message says

             

            "Object of type Function found where a number, array or property is needed"

             

            I think the solution to this is something obvious and simple, but I couldn't find anything by searching.

             

            Any help will be appreciated!

            • 3. Re: Stop an expression and hold the current value
              Todd_Kopriva Level 8

              You can get past that error by heeding the second paragraph in my first message. I.e., you need to give valueAtTime its argument.

              • 4. Re: Stop an expression and hold the current value
                Andy Bay Level 1

                Thanks again for helping out!

                 

                I'm not sure how to tell valueAtTime to take the current value for the parameter (x-position). I tried to put in valueAtTime(time) and valueAtTime(10) but the layer keeps jumping back to it's beginning position.

                 

                So I guess the question goes: How do I tell valueAtTime to return the current value for my property?

                • 5. Re: Stop an expression and hold the current value
                  Todd_Kopriva Level 8

                  OK, now that we've gotten you past the two syntax errors, we can finally talk about the real issue.

                   

                  The valueAtTime method queries the keyframe-based value of the property at the time specified. It doesn't look at the expression-based values.

                   

                  BTW, why aren't you just using keyframes for this? Perhaps you have some reason for wanting to use an expression here, but if all that you're trying to do is move a layer horizontally and then stop, that's something that you can do easily with two keyframes.

                  1 person found this helpful
                  • 6. Re: Stop an expression and hold the current value
                    Andy Bay Level 1

                    Thanks for educating me Todd, it's appreciated!

                     

                    Anyway I'm using expressions just because I'm trying to learn them (you are right that this could be done with keyframes too). As you see I have still a loong way ahead of me! But I have had a similar kind of problems with expressions many times and would like to know if there is a solution.

                     

                    In other words, is there any way to make an expression stop and hold it's current value at that point in time?

                    • 7. Re: Stop an expression and hold the current value
                      Mylenium Most Valuable Participant

                      To hold a specific value that in itself is based on other expression values it would have to run in a loop (while())and be triggered by a specific criteria. Unless it is really necessary, I would avoid it, as AE's model basically re-evaluates the expressions for every frame to derive the value, so as time progresses, it gets slower and slower, because more frames amass. Converting the animation to keyframes and cleaning up the excess often is more efficient, unless you really need to be it dynamic and changeable....

                       

                      Mylenium

                       

                      PS: You can of course always use time-remapping on a pre-comp. Since it influences the comp time, expressions will respect any hold animation on it...

                       

                      Mylenium

                       

                      Message was edited by: Mylenium

                      • 8. Re: Stop an expression and hold the current value
                        Trish Meyer Level 1

                        Have you thought about tying the value in the expression to a Slider (Expression Controls > Slider). Then the value that you want to hold can be controlled by keyframing the Slider effect.

                         

                        Not sure if that gets you anywhere that you couldn't have gone with just regular keyframes, but the Slider effect is how you control the wiggle expression (otherwise it will wiggle with the same values for the entire layer). Using Slider, you can start off with no wiggle, ramp it up, and then hold on that value, or ramp back down.