Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

About JSX importing in AfterEffects 15.1

New Here ,
Apr 20, 2018 Apr 20, 2018

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?

TOPICS
Expressions
6.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 20, 2018 Apr 20, 2018

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

Translate
Community Expert ,
Apr 20, 2018 Apr 20, 2018

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

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2018 Apr 26, 2018

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2018 Apr 20, 2018

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

I'm looking forward to your tutorial!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2018 Apr 23, 2018

Here is the tutorial

https://mamoworld.com/tutorials/after-effects-expressions-nerd-tip-1-building-your-own-expressions-l...

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2018 Apr 24, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2018 Nov 20, 2018

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2018 Nov 20, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

I don't think that's possible.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2018 Nov 20, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 02, 2020 Sep 02, 2020
LATEST

Change:

 

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

to:

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

 

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