121
JavaScript Reference
Property object
121
m y S h a p e . c l o s e d = f a l s e ;
m y P r o p e r t y . s e t V a l u e ( m y S h a p e ) ;
Example: Get the value of a color at a particular time
A color is stored as an array of four floats, [r,g,b,opacity]. This sets the value of the red component of a light's
color at time 4 to be half of that at time 2:
v a r m y P r o p e r t y = m yL i g h t . c o l o r ;
v a r c o l o r V a l u e = m yP r o p e r t y . v a l u e A t T i m e ( 2 , t r u e ) ;
c o l o r V a l u e [ 0 ] = 0 . 5 * c o l o r V a l u e [ 0 ] ;
m y P r o p e r t y . s e t V a l u e A t T i m e ( 4 , c o l o r V a l u e ) ;
Example: Check that a scale calculated by an expression at time 3.5 is the expected value of [10,50]
v a r m y P r o p e r t y = m yL a y e r . s c a l e ;
/ / f a l s e v a l u e o f p r e E x p r e s s i o n m e a n s e v a l u a t e t h e e x p r e s s i o n
v a r s c a l e V a l u e = m y P r o p e r t y . v a l u e A t T i m e ( 3 . 5 , f a ls e ) ;
i f ( s c a l e V a l u e [ 0 ] = = 1 0 & & s c a l e V a l u e [ 1 ] = = 5 0 ) {
a l e r t ( " h u r r a y " ) ;
}
e l s e {
a l e r t ( " o o p s " ) ;
}
Example: Keyframe a rotation from 0 to 90 and back again
The animation is 10 seconds, and the middle keyframe is at the 5 second mark. Rotation properties are stored
as a OneD value.
m y P r o p e r t y = m y L a y e r . r o t a t i o n ;
m y P r o p e r t y . s e t V a l u e A t T i m e ( 0 , 0 ) ;
m y P r o p e r t y . s e t V a l u e A t T i m e ( 5 , 9 0 ) ;
m y P r o p e r t y . s e t V a l u e A t T i m e ( 1 0 , 0 ) ;
Example: Change the keyframe values for the first three keyframes of some source text
m y P r o p e r t y = m y T e x t L a y e r . s o u r c e T e x t ;
i f ( m y P r o p e r t y . n u m K e y s < 3 ) {
a l e r t ( " e r r o r , I t h o u g h t t h e r e w e r e 3 k e y f r a m e s " ) ;
}
e l s e {
m y P r o p e r t y . s e t V a l u e A t K e y ( 1 , n e w T e x t D o c u m e n t ( " k e y n u m b e r 1 " ) ) ;
m y P r o p e r t y . s e t V a l u e A t K e y ( 2 , n e w T e x t D o c u m e n t ( " k e y n u m b e r 2 " ) ) ;
m y P r o p e r t y . s e t V a l u e A t K e y ( 3 , n e w T e x t D o c u m e n t ( " k e y n u m b e r 3 " ) ) ;
}
Example: Set values using the convenience syntax for position, scale, color, or source text
/ / T h e s e t w o a r e e q u i v a l e n t . T h e s e c o n d f i l l s i n a d e f a u l t o f 0 .
m y L a y e r . p o s i t i o n . s e t V a l u e ( [ 2 0 , 3 0 , 0 ] ) ;
m y L a y e r . p o s i t i o n . s e t V a l u e ( [ 2 0 , 3 0 ] ) ;
/ / T h e s e t w o a r e e q u i v a l e n t . T h e s e c o n d f i l l s i n a d e f a u l t o f 1 0 0 .
m y L a y e r . s c a l e . s e t V a l u e ( [ 5 0 , 5 0 , 1 0 0 ] ) ;
m y L a y e r . s c a l e . s e t V a l u e ( [ 5 0 , 5 0 ] ) ;
/ / T h e s e t w o a r e e q u i v a l e n t . T h e s e c o n d f i l l s i n a d e f a u l t o f 1 . 0
Summary of Contents for 65009963 - After Effects CS4
Page 1: ...SCRIPTING GUIDE...