Adobe 0046100128056 Scripting Guide - Page 163

Key frames, duration and speed of the animation. For example

Page 163 highlights

CHAPTER 11: Creating Dynamic Documents Working with Animation 163 //Given a page containing the ovals "myOvalA" and "myOvalB"... var myMotionPreset = app.motionPresets.item("move-right-grow"); myOvalA.animationSettings.duration = 2; myOvalA.animationSettings.playsLoop = true; myOvalA.animationSettings.preset = myMotionPreset; myOvalA.animationSettings.designOption = DesignOptions.fromCurrentAppearance; myOvalB.animationSettings.duration = 2; myOvalB.animationSettings.playsLoop = true; myOvalB.animationSettings.preset = myMotionPreset; myOvalB.animationSettings.designOption = DesignOptions.toCurrentAppearance; Key frames Key frames are points in the timeline of an animation. With InDesign scripting, you can add key frames at any time in the animation, which gives you the ability to apply changes to objects as they are animated. Key frames are part of the motion path applied to an animated page item, and are specified relative to the duration and speed of the animation. For example, for an animation with a duration of two seconds, playing at 24 frames per second, the last frame in the animation is frame 48. The following script fragment shows how to add key frames to a motion path, and how to change the transformations applied to an animated page item at each key frame. For the complete script, refer to TransformAnimation. //Given a page containing ovals "myOvalA," "myOvalB," and "myOvalC"... //The motion path is constructed relative to the center of the object, and key frames //are based on the duration of the animation divided by the number of frames per second //(usually 24). The following array sets key frames at the start, midpoint, and end //of a path. var myMotionPath = [[0,[[0,0], [0,0], [0,0]]], [23,[[234,0], [234,0], [234,0]]], [47,[[468,0], [468,0], [468,0]]]]; myOvalA.animationSettings.duration = 2; myOvalA.animationSettings.motionPath = myMotionPath; //The transformation changes at each key frame. //scaleXArray in the form [[keyframe, scale], [keyframe, scale], ...] myOvalA.animationSettings.scaleXArray = [[0, 100], [23,200], [47, 100]]; //scaleYArray in the form [[keyframe, scale], [keyframe, scale], ...] myOvalA.animationSettings.scaleYArray = [[0, 100], [23,200], [47, 100]]; //opacityArray in the form [[keyframe, opacity], [keyframe, opacity],...]; myOvalA.animationSettings.opacityArray = [[0, 100], [23, 20], [47, 100]]; myOvalA.animationSettings.playsLoop = true; myOvalB.animationSettings.duration = 2; myOvalB.animationSettings.motionPath = myMotionPath; myOvalB.animationSettings.scaleXArray = [[0, 200], [23,300], [47, 50]]; myOvalB.animationSettings.scaleYArray = [[0, 200], [23,300], [47, 50]]; myOvalB.animationSettings.opacityArray = [[0, 10], [23, 80], [47, 60]]; myOvalB.animationSettings.playsLoop = true; myOvalC.animationSettings.duration = 2; myOvalC.animationSettings.motionPath = myMotionPath; myOvalC.animationSettings.scaleXArray = [[0, 50], [23,200], [47, 400]]; myOvalC.animationSettings.scaleYArray = [[0, 50], [23,200], [47, 400]]; myOvalC.animationSettings.opacityArray = [[0, 100], [23, 40], [47, 80]]; myOvalC.animationSettings.playsLoop = true;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209

C
HAPTER
11: Creating Dynamic Documents
Working with Animation
163
//Given a page containing the ovals "myOvalA" and "myOvalB"...
var myMotionPreset = app.motionPresets.item("move-right-grow");
myOvalA.animationSettings.duration = 2;
myOvalA.animationSettings.playsLoop = true;
myOvalA.animationSettings.preset = myMotionPreset;
myOvalA.animationSettings.designOption = DesignOptions.fromCurrentAppearance;
myOvalB.animationSettings.duration = 2;
myOvalB.animationSettings.playsLoop = true;
myOvalB.animationSettings.preset = myMotionPreset;
myOvalB.animationSettings.designOption = DesignOptions.toCurrentAppearance;
Key frames
Key frames are points in the timeline of an animation. With InDesign scripting, you can add key frames at
any time in the animation, which gives you the ability to apply changes to objects as they are animated.
Key frames are part of the motion path applied to an animated page item, and are specified relative to the
duration and speed of the animation. For example, for an animation with a duration of two seconds,
playing at 24 frames per second, the last frame in the animation is frame 48.
The following script fragment shows how to add key frames to a motion path, and how to change the
transformations applied to an animated page item at each key frame. For the complete script, refer to
TransformAnimation.
//Given a page containing ovals "myOvalA," "myOvalB," and "myOvalC"...
//The motion path is constructed relative to the center of the object, and key frames
//are based on the duration of the animation divided by the number of frames per second
//(usually 24). The following array sets key frames at the start, midpoint, and end
//of a path.
var myMotionPath = [[0,[[0,0], [0,0], [0,0]]], [23,[[234,0], [234,0], [234,0]]],
[47,[[468,0], [468,0], [468,0]]]];
myOvalA.animationSettings.duration = 2;
myOvalA.animationSettings.motionPath = myMotionPath;
//The transformation changes at each key frame.
//scaleXArray in the form [[keyframe, scale], [keyframe, scale], ...]
myOvalA.animationSettings.scaleXArray = [[0, 100], [23,200], [47, 100]];
//scaleYArray in the form [[keyframe, scale], [keyframe, scale], ...]
myOvalA.animationSettings.scaleYArray = [[0, 100], [23,200], [47, 100]];
//opacityArray in the form [[keyframe, opacity], [keyframe, opacity],...];
myOvalA.animationSettings.opacityArray = [[0, 100], [23, 20], [47, 100]];
myOvalA.animationSettings.playsLoop = true;
myOvalB.animationSettings.duration = 2;
myOvalB.animationSettings.motionPath = myMotionPath;
myOvalB.animationSettings.scaleXArray = [[0, 200], [23,300], [47, 50]];
myOvalB.animationSettings.scaleYArray = [[0, 200], [23,300], [47, 50]];
myOvalB.animationSettings.opacityArray = [[0, 10], [23, 80], [47, 60]];
myOvalB.animationSettings.playsLoop = true;
myOvalC.animationSettings.duration = 2;
myOvalC.animationSettings.motionPath = myMotionPath;
myOvalC.animationSettings.scaleXArray = [[0, 50], [23,200], [47, 400]];
myOvalC.animationSettings.scaleYArray = [[0, 50], [23,200], [47, 400]];
myOvalC.animationSettings.opacityArray = [[0, 100], [23, 40], [47, 80]];
myOvalC.animationSettings.playsLoop = true;