a more succint question about scripting:

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Jai
Posts: 3
Joined: May 5th, 2005, 1:29 pm

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?
davestewart
Posts: 114
Joined: March 10th, 2005, 5:50 am
Location: London, UK
Contact:

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
Post Reply