FORUMS: list search recent posts

# Making the opacity to switch on and off - should be easy.

FAQ   •   VIEW ALL
 Making the opacity to switch on and off - should be easy. on Jan 19, 2013 at 9:56:22 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;```

 Re: Making the opacity to switch on and off - should be easy.on Jan 19, 2013 at 5:37:55 pm

This should work:

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

Dan

 Re: Making the opacity to switch on and off - should be easy.on Jan 20, 2013 at 11:31:11 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) ?

 Re: Making the opacity to switch on and off - should be easy.on Jan 20, 2013 at 5:18:02 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