home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Scripting_Resources / Samples / Automation_Scripts / Opacity.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  3.1 KB  |  100 lines

  1. //////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED 
  4. // Copyright 2002 Adobe Systems Incorporated 
  5. // All Rights Reserved 
  6. //
  7. // NOTICE:  Adobe permits you to use, modify, and 
  8. // distribute this file in accordance with the terms
  9. // of the Adobe license agreement accompanying it.  
  10. // If you have received this file from a source 
  11. // other than Adobe, then your use, modification,
  12. // or distribution of it requires the prior 
  13. // written permission of Adobe. 
  14. //
  15. //////////////////////////////////////////////////
  16.  
  17. //////////////////////////////////////////////////
  18. // Opacity.js
  19. //
  20. // DESCRIPTION
  21. //
  22. // This script demonstrates the use of opacity stopwatch with timeline.
  23. // Switch to Preview mode to see the object slowly disappear.
  24. //
  25. // HOW TO USE
  26. //
  27. // Create any object and select it in the Composition.
  28. // Select Automation > Run Automation Scripts > Opacity.js
  29. // Click on Preview Mode to view the object disappear gradually.
  30. //
  31. //////////////////////////////////////////////////
  32.  
  33.  
  34. // Main Code [Execution of script begins from here]
  35.  
  36. // Check if any composition is open
  37. if(application.compositions.length > 0){
  38.     comp = application.currentComposition;
  39.     if(comp.selection.length >= 1){ // Checks if at least one object is selected
  40.         var objs = comp.selection; // Store all selected objects in the array objs
  41.         
  42.         // saves the current selection
  43.         application.currentComposition.saveSelection(); 
  44.         for (i=0; i < objs.length; i++) {
  45.             changeOpacity(objs[i], 24, 0, 3); // Funciton changeOpacity called
  46.             // Make changes in the parameters here to change the behavior of the function         
  47.         }        
  48.         // restores the saved selection
  49.         application.currentComposition.restoreSelection();
  50.     }
  51.     else{ // If no objects are selected brings the Console window up 
  52.         Console.show();
  53.         // Writes to the Console
  54.         Console.write("\nPlease select the objects to animate opacity and run script again.\n");
  55.     }
  56. }
  57. else{// if no composition open
  58.     // opens a new composition
  59.     comp = application.newComposition();
  60.     Console.show();
  61.     Console.write("New Composition opened\nPlease create and select the objects to animate opacity and run script again.\n");
  62. }
  63.  
  64.  
  65. // Add your own functions here
  66.  
  67. //////////////////////////////////////////////////
  68. // changeOpacity:
  69. // Changes opacity of object till the object gradually disappears
  70. //
  71. // target: the object to disappear
  72. // frames: the number of frames on the timeline
  73. // opacity: the opacity to end at
  74. // keyFrameRate: rate at which to place key frames
  75. //
  76. //////////////////////////////////////////////////
  77.  
  78. function changeOpacity(target, frames, opacity, keyFrameRate)
  79.     var frame0; // Variable to store the current frame
  80.  
  81.     frame0 = 0;
  82.         
  83.     var oriOpacity = target.opacity; // store initial object opacity
  84.     // check and turn on the opacity stopwatch if it is different from 
  85.     // the final opacity
  86.     if (opacity != oriOpacity){
  87.         target.stopwatch.opacity = true;     
  88.     
  89.         //first frame - stagger holds it 
  90.         target.currentFrame = frame0 + i ;
  91.         target.opacity = oriOpacity;
  92.     
  93.         //last frame    
  94.         target.currentFrame = frame0 + frames + i;
  95.         target.opacity = opacity;
  96.     }
  97. }
  98.  
  99.