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?
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
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
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!
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!
Copy link to clipboard
Copied
Here is the tutorial
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.
Copy link to clipboard
Copied
Hi, is it possible for the function to access the key values, for example
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!
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
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
Copy link to clipboard
Copied
I don't think that's possible.
Dan
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.
Copy link to clipboard
Copied
Change:
"foo":function(x){ return x+myOpacity;}
to:
"foo":function(x){ return x + this.myOpacity;}