home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////////////////////////////
- //
- // ADOBE SYSTEMS INCORPORATED
- // Copyright 2002 Adobe Systems Incorporated
- // All Rights Reserved
- //
- // NOTICE: Adobe permits you to use, modify, and
- // distribute this file in accordance with the terms
- // of the Adobe license agreement accompanying it.
- // If you have received this file from a source
- // other than Adobe, then your use, modification,
- // or distribution of it requires the prior
- // written permission of Adobe.
- //
- //////////////////////////////////////////////////
-
- //////////////////////////////////////////////////
- // Opacity.js
- //
- // DESCRIPTION
- //
- // This script demonstrates the use of opacity stopwatch with timeline.
- // Switch to Preview mode to see the object slowly disappear.
- //
- // HOW TO USE
- //
- // Create any object and select it in the Composition.
- // Select Automation > Run Automation Scripts > Opacity.js
- // Click on Preview Mode to view the object disappear gradually.
- //
- //////////////////////////////////////////////////
-
-
- // Main Code [Execution of script begins from here]
-
- // Check if any composition is open
- if(application.compositions.length > 0){
- comp = application.currentComposition;
- if(comp.selection.length >= 1){ // Checks if at least one object is selected
- var objs = comp.selection; // Store all selected objects in the array objs
-
- // saves the current selection
- application.currentComposition.saveSelection();
- for (i=0; i < objs.length; i++) {
- changeOpacity(objs[i], 24, 0, 3); // Funciton changeOpacity called
- // Make changes in the parameters here to change the behavior of the function
- }
- // restores the saved selection
- application.currentComposition.restoreSelection();
- }
- else{ // If no objects are selected brings the Console window up
- Console.show();
- // Writes to the Console
- Console.write("\nPlease select the objects to animate opacity and run script again.\n");
- }
- }
- else{// if no composition open
- // opens a new composition
- comp = application.newComposition();
- Console.show();
- Console.write("New Composition opened\nPlease create and select the objects to animate opacity and run script again.\n");
- }
-
-
- // Add your own functions here
-
- //////////////////////////////////////////////////
- // changeOpacity:
- // Changes opacity of object till the object gradually disappears
- //
- // target: the object to disappear
- // frames: the number of frames on the timeline
- // opacity: the opacity to end at
- // keyFrameRate: rate at which to place key frames
- //
- //////////////////////////////////////////////////
-
- function changeOpacity(target, frames, opacity, keyFrameRate)
- {
- var frame0; // Variable to store the current frame
-
- frame0 = 0;
-
- var oriOpacity = target.opacity; // store initial object opacity
- // check and turn on the opacity stopwatch if it is different from
- // the final opacity
- if (opacity != oriOpacity){
- target.stopwatch.opacity = true;
-
- //first frame - stagger holds it
- target.currentFrame = frame0 + i ;
- target.opacity = oriOpacity;
-
- //last frame
- target.currentFrame = frame0 + frames + i;
- target.opacity = opacity;
- }
- }
-
-