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.
- //
- //////////////////////////////////////////////////
-
- //////////////////////////////////////////////////
- //
- // Event Handlers.js
- //
- // DESCRIPTION
- //
- // This script shows how to add script to the event handlers
- // in the player script. This allows you to write event based
- // script in your programs.
- //
- // HOW TO USE
- //
- // Create three objects in the composition and run the script.
- // Note: You may create more objects in the composition and
- // change the loop controls as number of objects -1 accordingly, as
- // you would do for the objects array of composition.
- //
- // Select Automation > Run Automation Scripts > Event Handlers.js
- //
- // Preview the result by switching to the preview mode
- // or export the file and view it in the browser
- //////////////////////////////////////////////////
-
- // Main Code [Execution of script begins here]
-
- // Check if any composition is open
- if(application.compositions.length > 0){
- comp = application.currentComposition;
- if(comp.selection.length >= 3){ // Checks if at least one object is selected
- var objs = comp.selection; // Store all selected objects in the array objs
- setScript(comp, objs); // Call function setScript
- }
- else{ // If no objects are selected brings the Console window up
- Console.show();
- // Writes to the Console
- Console.write("\nPlease select at least 3 objects to apply the Animation and run the script again.\n");
- }
- }
- else{// if no composition open
- // opens a new composition
- comp = application.newComposition();
- Console.show();
- Console.write("\nNew Composition opened\nPlease create and select at least 3 objects to apply the Animation and run the script again.\n");
- }
-
- // Add your own functions here
-
- //////////////////////////////////////////////////
- //
- // setScript:
- //
- // Demonstrates how user can add scripts to the different event
- // handlers available in LiveMotion application. Also shows
- // a way to access all the objects in the composition through
- // player script. Adding scripts to event handlers help you to
- // do event based programming.
- //
- // comp: The currently open and active file/composition.
- // objs: All the selected objects in the composition.
- //
- //////////////////////////////////////////////////
-
- function setScript(comp, objs)
- {
- // Loop for naming all the objects in the composition
- // and converting them into movieclips
- for(i=0; i < objs.length ; i++){
- // Name all objects on the composition
- objs[i].name = "object"+i;
-
- // Convert object into MovieClip
- objs[i].isMovieClip = true;
- }
-
- // Note: After we convert objects to movie clips we can use
- // any of the movie clip properties/functions to manipulate
- // or animate the objects.
-
- // Assign script for the onLoad event handler to the variable script1.
- script1 = 'var j=0;\n';
- script1 += 'var numy = _root._height / 2; // height of the composition \n';
- script1 += 'var numx = _root._width / 2; // width of the composition\n';
-
- // Loop for positioning objects in a queue with difference of
- // their heights only so that one does not overlap over the other.
- script1 += 'for(var i=0; i < 3; i++){\n';
- script1 += '\t// Position all objects on composition\n';
- script1 += '\t_root[\"object\"+i]._x = 0; \n';
- script1 += '\t//Difference between positioning objects is the height of each object \n';
- script1 += '\t_root[\"object\"+i]._y = _root[\"object\"+i]._height;\n} \n';
-
-
- // This script in variable script2 is for the onEnterFrame event handler.
- script2 = 'angle = j*(Math.PI/180); // the angle for the circle\n';
-
- // Loop through all objects in the composition.
- script2 += 'for(var i=0; i < 3; i++){\n';
- script2 += '\t// 3 is the num of objects\n';
-
- // Setting the x position through the movieclips property - ._x
- // of the objects to make them move in a circle.
- script2 += '\t_root[\"object\"+i]._x = 95*Math.sin(angle+(i*2*Math.PI/8))+numx;\n';
- script2 += '\t// Formula to calculate x position of object to move them in a circle\n';
-
- // Setting the y position through the movieclips property - ._y
- // of the objects to make them move in a circle.
- script2 += '\t_root[\"object\"+i]._y = 95*Math.cos(angle+(i*2*Math.PI/8))+numy;\n';
- script2 += '\t// Formula to calculate y position of object to move them in a circle\n}' ;
- script2 += 'j++;\n';
-
- // Set the script on the specific handlers.
- comp.setHandlerScript(LMHandlerType.onLoad, script1);
- comp.setHandlerScript(LMHandlerType.onEnterFrame, script2);
-
- // Note: A similar getHandlerScript method is also available to get any
- // player script on any handler. This could be more useful in LiveTabs.
- return;
- }
-
-