Page 1 of 1
a more succint question about scripting:
Posted: May 7th, 2005, 5:18 pm
by Jai
are objects (user defined: i.e. var monkey = new Object();) scoped forever, or do they end when the script executes?
can expressions communicate any information to script objects and vice versa?
Posted: May 11th, 2005, 9:22 am
by davestewart
When writing external scripts, JavaScript essentially has 2 scopes: function (local) and global.
Any variables declared within a function using "var" can only be seen inside the function, and will be independant of any other (same named) variables ouside the function. These variables also die when the function ends.
Any variables declared without var (inside or outside a function) will be instantiated and will be visible anywhere within the AE scripting environment, and will live for as long as After Effects is open. You can of course, re-assign values as and when.
However, you cannot (to my knowledge) assign global variables using an external script, that can be used within expressions assigned to object properties. Expressions will only reference other item's (comps, solids, effects, etc) properties.
You can, though, assign local variables within JavaScript expressions on object properties. For example, on a position track:
x=position[0];
y=random(1,10);
[x,y];
You can also assign expressions programatically to objects properties from an external script:
app.project.activeItem.layers[1].Rotation.expression='random(0,100)'
I hope that answers all your questions...
Dave