ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Something weird with Expression code?

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Frank LimaSomething weird with Expression code?
by on Jun 5, 2012 at 7:01:08 am

I want to directly modify the opacity on a layer using Adobe Expression. I have this code here as a test:

if(thisComp.layer(6).opacity == 95)
{
opacity = 25;
}

if(thisComp.layer(6).opacity == 25)
{
opacity = 10;
}


Now if I set my opacity at 95 initially (by myself) it will do the first 'if' statement PERFECTLY and then completely overlook the second. I notice that with this code, it doesn't look at the changes it made to the Opacity at all. Is there a way to DIRECTLY modify it and access it even after the changes?

For example, if I right click and choose 'edit value' under opacity. It still says 95% even though the code already changed it to 25%

In short, I want a way to directly modify the opacity using code and accessing it.


Return to posts index

Walter SoykaRe: Something weird with Expression code?
by on Jun 5, 2012 at 3:00:30 pm

You cannot programmatically assign a value to a property in an expression as you are trying to do with the line "opacity = 25;". Expressions are evaluated every frame, and they return a value to the property in which the expression is built.

In other words, the property gets the final result of the expression.

Your code above only works because the assignation "opacity = 25" evaluates to 25; this value is then returned to the property with the expression applied. You could drop the "opacity =" and just make that line the constant "25" and you'd get the same results.

To achieve your goal here, you would have to store the "25" value assignment in the first conditional in a variable, then check both your new variable and the original opacity value in the second conditional. Finally, you'd have to return the variable.

Walter Soyka
Principal & Designer at Keen Live
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
RenderBreak Blog - What I'm thinking when my workstation's thinking
Creative Cow Forum Host: Live & Stage Events


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2016 CreativeCOW.net All Rights Reserved
[TOP]