ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to Animate a Slider with external Json file?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
John Westlen
How to Animate a Slider with external Json file?
on Feb 9, 2019 at 7:05:41 pm

Hello,

So I am trying to make an array of numbers, 48 numbers to be exact. And would like After Effects to use that data written on a Json file and have it imported to a slider. Also, having the numbers change every four seconds.
Example of what i mean:
Array-
[
{
"ID": 1,
"slider": 1000,
"duration": 4
},
{
"ID": 2,
"slider":2000 ,
"duration": 4
},

so when the slider starts at 1,000 it animates and plays all the numbers between 1,000-2,000 within four seconds and then gets to 2,000.

How could i go about doing this?

I am new to coding so please if you are kind enough to explain this to me.

Thank you!


Return to posts index

Oleg Pirogov
Re: How to Animate a Slider with external Json file?
on Feb 11, 2019 at 7:41:24 am

My shot will be:

$.evalFile('PUT_YOUR_JSON_FILE_PATH_HERE');

var dur = 0;

for (var i=0, len = arr.length; i<len; i++){
dur+=arr[0].duration;
if (dur>=time) break;
}

i === len || i === len-1 ? arr[len-1].slider : linear(time, dur-arr[i].duration, dur, arr[i].slider, arr[i+1].slider);


[This goes to slider property expression]

As I understand your data, IDs are points in time separated from each other by corresponding durations. So the expression sums consequent durations to find a pair of points in time a.k.a. IDs (namely ID i and ID i+1) between which the current time falls. Then it interpolates between slider values of those IDs, i.e. "plays all the numbers between 1,000-2,000 within four seconds and then gets to 2,000".

If current time is beyond the last ID, slider freezes at the slider value of the last ID (arr[len-1].slider).

The JSON file looks as follows:
var arr = [{"ID": 1, "slider": 1000, "duration": 4}, {"ID": 2, "slider":2000, "duration": 4}, {"ID": 3, "slider": 3000, "duration": 4}];

Seems to work as intended.


Return to posts index

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