Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Making the opacity to switch on and off – should be easy.

  • Making the opacity to switch on and off – should be easy.

    Posted by Thor Hansvik on January 19, 2013 at 9:56 am

    Yes, I am new to this…

    I have a precomp I want to switch the opacity to 0 and 100 for every e.g. 10th frame. That is, 0% for the 10 first frames, then 100% for the next 10 frames and back to 0% for the next 10 frames and so on…

    I tried the following expression but I guess that the state variable is initialized for every new frame. Thus, the opacity stays at 100% for 10 frames, switching to 0% for one frame, and then switching back to 100% for the next 10 frames and so on.

    How (if possible) do I prevent the state variable to be initialized for every new frame, or solve this problem?


    frames = timeToFrames() % 10;
    state = 1;

    if (frames == 0)
    state = state * -1;

    if (state == 1)
    f = 1;
    else
    f = 0;

    transform.opacity = 100*f;

    Dan Ebberts replied 13 years, 7 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    January 19, 2013 at 5:37 pm

    This should work:

    f = timeToFrames(time-inPoint);
    Math.floor(f/10)%2 ? 100 : 0

    Dan

  • Thor Hansvik

    January 20, 2013 at 11:31 am

    Thanks, it works!

    Do I understand this right; The intire expression code is executed for each frame? Is it possible to define a variable that is initialized at “start up” (frame 0 or -1) ?

  • Dan Ebberts

    January 20, 2013 at 5:18 pm

    >The intire expression code is executed for each frame?

    Yes.

    > Is it possible to define a variable that is initialized at “start up” (frame 0 or -1) ?

    No, variables can’t persist between frames.

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy