Highlighted

About JSX importing in AfterEffects 15.1

New Here ,
Apr 20, 2018

Copy link to clipboard

Copied

I've been importing json files with stringified javascript and evaled them in my comps to reuse scripts.

Since updating to 15.1 I get an error when I try to import them and as the error tells me, I renamed them to jsx files and it works fine.

I would like to know the specification of the imported jsx files. (Not the extended script jsx)

Are they just basically the same as imported JSON only with different file extensions?

I was hoping if I can write javascript directly without the hassle of having to stringify it everytime.

Are there any documents related to this?

Adobe Community Professional
Correct answer by Mathias Moehl | Adobe Community Professional

Not sure whether it is documented, yet. I actually plan a tutorial about this.

These jsx files are essentially json files with the great extra feature that they can contain functions as values (which is not allowed in normal JSON, that's why they renamed it to jsx).

Example file:

{

  "myColor":[0.5,0.5,0.5,1],

  "myOpacity":50,

  "foo":function(x){ return x+1;}

}

Now you can access the function foo in an expression like this

var myLib = footage("myFile.jsx").sourceData;

myLib.foo(10) // result is 11

TOPICS
Expressions

Views

3.0K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

About JSX importing in AfterEffects 15.1

New Here ,
Apr 20, 2018

Copy link to clipboard

Copied

I've been importing json files with stringified javascript and evaled them in my comps to reuse scripts.

Since updating to 15.1 I get an error when I try to import them and as the error tells me, I renamed them to jsx files and it works fine.

I would like to know the specification of the imported jsx files. (Not the extended script jsx)

Are they just basically the same as imported JSON only with different file extensions?

I was hoping if I can write javascript directly without the hassle of having to stringify it everytime.

Are there any documents related to this?

Adobe Community Professional
Correct answer by Mathias Moehl | Adobe Community Professional

Not sure whether it is documented, yet. I actually plan a tutorial about this.

These jsx files are essentially json files with the great extra feature that they can contain functions as values (which is not allowed in normal JSON, that's why they renamed it to jsx).

Example file:

{

  "myColor":[0.5,0.5,0.5,1],

  "myOpacity":50,

  "foo":function(x){ return x+1;}

}

Now you can access the function foo in an expression like this

var myLib = footage("myFile.jsx").sourceData;

myLib.foo(10) // result is 11

TOPICS
Expressions

Views

3.0K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 20, 2018 0
Adobe Community Professional ,
Apr 20, 2018

Copy link to clipboard

Copied

Not sure whether it is documented, yet. I actually plan a tutorial about this.

These jsx files are essentially json files with the great extra feature that they can contain functions as values (which is not allowed in normal JSON, that's why they renamed it to jsx).

Example file:

{

  "myColor":[0.5,0.5,0.5,1],

  "myOpacity":50,

  "foo":function(x){ return x+1;}

}

Now you can access the function foo in an expression like this

var myLib = footage("myFile.jsx").sourceData;

myLib.foo(10) // result is 11

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 20, 2018 0
New Here ,
Apr 26, 2018

Copy link to clipboard

Copied

Hi! I'm fairly new at scripting and for some reason I don't get to know I can't load the jsx into AE.

I think the problem lays at how I save the script.

Can I use a Windows' document text, save it as a jsx and then import it into AE?

Thx!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 26, 2018 0
New Here ,
Apr 20, 2018

Copy link to clipboard

Copied

Thanks I that's exactly what I needed to know. (should have tried it out myself.)

I'm looking forward to your tutorial!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 20, 2018 0
Adobe Community Professional ,
Apr 23, 2018

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2018 0
New Here ,
Apr 24, 2018

Copy link to clipboard

Copied

Great tutorial! So much better than cramming a javascript string into a json! I had to do it through a gulp task just for that and it was so tedious.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 24, 2018 0
Explorer ,
Nov 20, 2018

Copy link to clipboard

Copied

Hi, is it possible for the function to access the key values, for example

  1.   "myColor":[0.5,0.5,0.5,1], 
  2.   "myOpacity":50
  3.   "foo":function(x){ return x+myOpacity;} 
  4. }

so that the expression

var myLib = footage("myFile.jsx").sourceData; 

myLib.foo(10)

results in 60;

I couldn't get this to work, really appreciate any help and advice.

Also will using JSON files to store functions be slower than having the function within the expression?

Many thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 20, 2018 0
Guide ,
Nov 20, 2018

Copy link to clipboard

Copied

I think you'd have to create a local variable and retrieve the value from the library first, like this:

var myLib = footage("myFile.jsx").sourceData;

var myOpacity = myLib.myOpacity;

myLib.foo(10)

Dan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 20, 2018 0
Explorer ,
Nov 20, 2018

Copy link to clipboard

Copied

Thanks Dan, that will work!

Is it possible for an expression to change the value of a JSON variable/key so that another expression will use the new value?

Cheers

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 20, 2018 0
Guide ,
Nov 20, 2018

Copy link to clipboard

Copied

I don't think that's possible.

Dan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 20, 2018 0
Explorer ,
Nov 20, 2018

Copy link to clipboard

Copied

Thanks Dan, i've been toying with this for a while and believe you're right, it's a pity.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 20, 2018 0
New Here ,
Sep 02, 2020

Copy link to clipboard

Copied

Change:

 

  "foo":function(x){ return x+myOpacity;} 

to:

  "foo":function(x){ return x + this.myOpacity;} 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0