home *** CD-ROM | disk | FTP | other *** search
Wrap
////////////////////////////////////////////////// // // 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. // ////////////////////////////////////////////////// ////////////////////////////////////////////////// // // Radio Toggle.js // // DESCRIPTION // // This script takes one small object and creates a group // of two radio buttons from it. It add a dynamic text box // which displays which button is on during execution. // It shows adding different states to objects and adding // scripts to the states. // // HOW TO USE // // Select Automation > Run Automation Scripts > Radio Toggle.js // // Click on the preview button and view the radio buttons // and their function. // ////////////////////////////////////////////////// // 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 >= 1){ // Checks if at least one object is selected button = comp.selection[0]; // First selected object is assigned to button_in // saves the current selection application.currentComposition.saveSelection(); createButtonsAndStates(button); // Function createButtonandStates called application.currentComposition.restoreSelection(); } else{ // If no objects are selected brings the Console window up Console.show(); // Writes to the Console Console.write("\nPlease select at least one object which becomes the model for the shape for the radio buttons and run the 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 at least one object which becomes the model for the shape for the radio buttons and run script again.\n"); } // Add your own functions here ////////////////////////////////////////////////// // // createButtonsAndStates: // // Creates a group of two radio buttons taking as arguement just one inner object // for a radio button. Give them differents effects and states. Then calls another // function which in turn adds the functionality to the radio buttons. // // button: The selected object which is the inner object in a radio button. // ////////////////////////////////////////////////// function createButtonsAndStates(button_in){ button_in.name = "dot"; // Named as dot on the timeline for use in player script button_in.isMovieClip = true; // Make it a movieclip // Inner object is filled button_in.stroke.type = LMStrokeType.fill; // Add off state and add script to the off state for dot button_in.addState("off"); // Adds a new state "off" button_in.currentState = "off" ; // Makes off the current state script1 = 'this._alpha = 0;' ; // Adds statement in variable script1 // Adds script in script1 to the current state of button_in button_in.setStateChangeScript("off", script1); // Add on state and add script to the on state for dot button_in.addState("on"); // Adds a new state "on" button_in.currentState = "on"; // Makes on the current state script1 = 'this._alpha = 100;'; // Adds statement in variable script1 // Adds script in script1 to the current state of button_in button_in.setStateChangeScript("on", script1); // Create an outer ring for the radio button and position it on the top of it button_out = button_in.duplicate(); button_out.deleteState("off"); // does not work till build 67 button_out.deleteState("on"); // does not work till build 67 // Workaround: Delete the states manually in LiveMotion button_out.currentState = "normal"; // Note: When an object is duplicated and it has multiple states // To edit setting for the duplicated object select its normal state // Else the settings will be changed for the last current state only. // Outer ring is just an outline button_out.stroke.type = LMStrokeType.outline; button_out.stroke.width = 5; // Size of the outer ring is double the size of the inner button_out.size.x = (button_in.size.x + button_in.size.x); button_out.size.y = (button_in.size.y + button_in.size.y); button_out.name = "Outer";// Name the outer ring on the timeline button_out.isMovieClip = true; // Convert it to a movieclip button_out.addState(LMStateType.mouseDown);// Add Down state to the outer ring // Group the inner and outer rings to form one radio button // Create an array of objects to group. var obj1 = new Array(button_in, button_out); // Using the group method of composition to group the array. var Group1 = comp.group(obj1); // Naming the group using the name property. Every object has a name property. Group1.name = "Radio1"; Group1.isMovieClip = true;// Converting group to a movieclip // Note: Since scripts for the down states for outer buttons are different we are not // setting them before duplicating as in the inner case. // Create Group2 for radio button 2 // The Group is created with all states and effects that Group1 has! Group2 = Group1.duplicate(); // Duplicate group 1 Group2.name = "Radio2"; // Naming group2 to Radio2 on the timeline // Positioning Group2 Group2.position.x = Group1.position.x + Group1.size.x + 50 ; Group2.position.y = Group1.position.y ; AddScript(Group1, Group2); // Calls funtion AddScript. Passes the buttons to it. } ////////////////////////////////////////////////// // // AddScript: // // This is a function that adds the functionality to the radio buttons created. // // Group1: First radio button. // Group2: Second radio button. // ////////////////////////////////////////////////// function AddScript(Group1, Group2){ // Create a dynamic text object to display which button is on at a time // Position it above the buttons - This is approximate, edit if it goes off the composition display = comp.createObject(LMObjectType.dynamicText, 100, Group1.Outer.position.y-Group1.Outer.size.y); display.text = "Display Box";// Displays this text in the dynamic text box display.variable = "disp"; // Name the variable in the dynamic text box // Sets the horizontal and vertical size of the objects text reflow box - LMPoint object display.reflowSize.x = 100; display.reflowSize.y = 20; // Setting current state within groups of objects // Setting current state of Outer in Group1 to Down Group1.Outer.currentState = LMStateType.mouseDown; // Accumulating the script statements to be written in the down state in variable script1 script1 = '// This radio button is selected so set the state of the dot for this button to on \n'; script1 += '_root.Radio1.dot.lmSetCurrentState("on");\n'; script1 += '// Set the state of dot of the other radio button to off, since only on is on at a time \n'; script1 += '_root.Radio2.dot.lmSetCurrentState("off");\n'; script1 += '// Set variable disp to display message - button 1 is on \n'; script1 += '_root.disp = "Radio Button 1 on";\n'; // Writing script to the Down state of Outer in Group1 Group1.Outer.setStateChangeScript(LMStateType.mouseDown, script1); // Setting current state of Outer in Group2 to Down Group2.Outer.currentState = LMStateType.mouseDown; // Accumulating the script statements to be written in the down state in variable script1 script2 = '// This radio button is selected so set the state of the dot to on \n'; script2 += '_root.Radio2.dot.lmSetCurrentState("on");\n'; script2 += '// Set the state of dot of the other radio button to off, since only on is on at a time \n'; script2 += '_root.Radio1.dot.lmSetCurrentState("off");\n'; script2 += '// Set variable disp to display message - button 2 is on \n'; script2 += '_root.disp = "Radio Button 2 on";\n'; // Writing script to the Down state of Outer in Group2 Group2.Outer.setStateChangeScript(LMStateType.mouseDown, script2); // Setting script on the onLoad handler so that we have only one button on when the script is loaded scriptHandler = '_root.Radio1.dot.lmSetCurrentState("off");\n'; scriptHandler += '_root.disp = "Radio Button 2 on";\n'; // Set the script on the specific handlers. comp.setHandlerScript(LMHandlerType.onLoad, scriptHandler); }