3 Replies Latest reply on Oct 6, 2011 8:23 AM by barrywrightiii

    Invalid Parameter When Attempting to Create a TimingGroup for a Button

    barrywrightiii

      Hello everyone,

       

      I'm attempting to create an interactive document involving some scripted animations.

       

      I was successful in setting up timingGroups based on the OnPageClick trigger, but I'm having a hard time setting up timingLists and timingGroups for Buttons.  I've tried numerous configurations and parameter values, but I always get an "invalid parameter" error when trying to run my script.

       

      I'll post the relevant snippet of code below (isolating only the necessary objects), then post the entire script in a reply.

       

      - Snippet -

       

      var myRectangle1P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "-4Green", "-4Green", myGreen, myNoneSwatch, 0);

      var myButton1 = myMakeTextFrameButton(myDocument.pages.item(0), [6,1.5,6.5,2.75], "Negative 4", "Negative 4", "Myriad Pro", 18, Justification.centerAlign, false)

      myRectangle1P1.animationSettings.duration = 2;

      myRectangle1P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[-288, 0], [-288, 0], [-288, 0]]]];

      myRectangle1P1.animationSettings.opacityArray = [[0,100],[11,100],[35,0]];

      myButton1.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle1P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

       

      // Change timing settings

          var myPageOneTimingSettings = myDocument.spreads.item(0).timingSettings;

          //Remove the default On Page Load timing list.

          myPageOneTimingSettings.timingLists[0].remove();

          var myButton1TimingList = myButton1.timingSettings.timingLists.add(DynamicTriggerEvents.onRelease);

          var myButton1TimingGroup = myButton1TimingList.timingGroups.add(myRectangle1P1,0);

      //

       

      Other things I've tried in setting up the ButtonTiming Group were:

      1.     Have the dynamicTarget be the Button itself

      2.     Give the animation behavior a variable, and have the dynamicTarget be that variable

      3.     Have a null value for dynamicTarget

       

      In each case, I received the same "invalid parameter" error.

       

      Any thoughts on this?  A possible workaround?

       

      Thanks,

      Barry Wright, III

        • 1. Re: Invalid Parameter When Attempting to Create a TimingGroup for a Button
          barrywrightiii Level 1

          The full script is listed below. If there is a better way to attach something like this, please let me know and I'll edit accordingly.

           

          // Test animation; proof-of-concept for horizontal translation interaction.

          // An Indesign CS5 Javascript

          //

          // Author: Barry Wright, III

          //

          // Builds a set of 5 buttons which translate an object horizontally while changing it's color,

          // This toy version adds buttons to trigger each animation. It also modifies the utility functions for rectangles and text frames to require a script label parameter.

          main()

          function main(){

              // Setup functions

              mySetSWFExportPreferences();

              var myDocument = app.documents.add();

              mySetUnits(MeasurementUnits.inches);

              myDocument.transparencyPreferences.blendingSpace = BlendingSpace.RGB;

              myDocument.documentPreferences.facingPages = false;

              myDocument.documentPreferences.pageWidth = 10;

              myDocument.documentPreferences.pageHeight = 8;

              var myRed = myMakeColor("Red", ColorSpace.RGB, ColorModel.process, [255, 0, 0]);

              var myGreen = myMakeColor("Green", ColorSpace.RGB, ColorModel.process, [0, 255, 0]);

              var myBlue = myMakeColor("Blue", ColorSpace.RGB, ColorModel.process, [0, 0, 255]);

              var myNoneSwatch = myDocument.swatches.item("None");

              // Add base rectangles to animate

              var myRectangle1P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "-4Green", "-4Green", myGreen, myNoneSwatch, 0);

              var myRectangle2P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "-2Green", "-2Green", myGreen, myNoneSwatch, 0);

              var myRectangle3P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "0Green", "0Green", myGreen, myNoneSwatch, 0);

              var myRectangle4P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "2Green", "2Green", myGreen, myNoneSwatch, 0);

              var myRectangle5P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "4Green", "4Green", myGreen, myNoneSwatch, 0);

              // Add other color rectangles for color tweening

              var myRectangle6P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "-4Blue", "-4Blue", myBlue, myNoneSwatch, 0);

              var myRectangle7P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "-2Blue", "-2Blue", myBlue, myNoneSwatch, 0);

              var myRectangle8P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "0Blue", "0Blue", myBlue, myNoneSwatch, 0);

              var myRectangle9P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "2Blue", "2Blue", myBlue, myNoneSwatch, 0);

              var myRectangle10P1 = myMakeRectangle(myDocument.pages.item(0), [3.625,4.5,4,5.5], "4Blue", "4Blue", myBlue, myNoneSwatch, 0);

              // Add textframe buttons using new utility function

              var myButton1 = myMakeTextFrameButton(myDocument.pages.item(0), [6,1.5,6.5,2.75], "Negative 4", "Negative 4", "Myriad Pro", 18, Justification.centerAlign, false);   

              var myButton2 = myMakeTextFrameButton(myDocument.pages.item(0), [6,3,6.5,4.25], "Negative 2", "Negative 2", "Myriad Pro", 18, Justification.centerAlign, false);

              var myButton3 = myMakeTextFrameButton(myDocument.pages.item(0), [6,4.5,6.5,5.75], "Zero", "Zero", "Myriad Pro", 18, Justification.centerAlign, false);

              var myButton4 = myMakeTextFrameButton(myDocument.pages.item(0), [6,6,6.5,7.25], "Positive 2", "Positive 2", "Myriad Pro", 18, Justification.centerAlign, false);

              var myButton5 = myMakeTextFrameButton(myDocument.pages.item(0), [6,7.5,6.5,8.75], "Positive 4", "Positive 4", "Myriad Pro", 18, Justification.centerAlign, false);

              // Change duration of animation for each rectangle

              myRectangle1P1.animationSettings.duration = 2;

              myRectangle2P1.animationSettings.duration = 2;

              myRectangle3P1.animationSettings.duration = 2;

              myRectangle4P1.animationSettings.duration = 2;

              myRectangle5P1.animationSettings.duration = 2;

              myRectangle6P1.animationSettings.duration = 2;

              myRectangle7P1.animationSettings.duration = 2;

              myRectangle8P1.animationSettings.duration = 2;

              myRectangle9P1.animationSettings.duration = 2;

              myRectangle10P1.animationSettings.duration = 2;

              // Add motion paths for each rectangle (note that we changed to .motionPath to allow for the use of keyframes)

              mySetUnits(MeasurementUnits.points);

              myRectangle1P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[-288, 0], [-288, 0], [-288, 0]]]];

              myRectangle2P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[-144, 0], [-144, 0], [-144, 0]]]];

              myRectangle3P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[0, 0], [0, 0], [0, 0]]]];

              myRectangle4P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[144, 0], [144, 0], [144, 0]]]];

              myRectangle5P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[288, 0], [288, 0], [288, 0]]]];

              myRectangle6P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[-288, 0], [-288, 0], [-288, 0]]]];

              myRectangle7P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[-144, 0], [-144, 0], [-144, 0]]]];

              myRectangle8P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[0, 0], [0, 0], [0, 0]]]];

              myRectangle9P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[144, 0], [144, 0], [144, 0]]]];

              myRectangle10P1.animationSettings.motionPath = [[0, [[0, 0], [0, 0], [0, 0]]], [11, [[0, 0], [0, 0], [0, 0]]], [47, [[288, 0], [288, 0], [288, 0]]]];

              mySetUnits(MeasurementUnits.inches);

              // Add opacity arrays for each rectangle (current animation is set to 2 sec = 24 frames)  Include the .5 second delay and finish .5 early.

              myRectangle1P1.animationSettings.opacityArray = [[0,100],[11,100],[35,0]];

              myRectangle2P1.animationSettings.opacityArray = [[0,100],[11,100],[35,0]];

              myRectangle3P1.animationSettings.opacityArray = [[0,100],[11,100],[35,0]];

              myRectangle4P1.animationSettings.opacityArray = [[0,100],[11,100],[35,0]];

              myRectangle5P1.animationSettings.opacityArray = [[0,100],[11,100],[35,0]];

              myRectangle6P1.animationSettings.opacityArray = [[0,0],[11,0],[35,100]];

              myRectangle7P1.animationSettings.opacityArray = [[0,0],[11,0],[35,100]];

              myRectangle8P1.animationSettings.opacityArray = [[0,0],[11,0],[35,100]];

              myRectangle9P1.animationSettings.opacityArray = [[0,0],[11,0],[35,100]];

              myRectangle10P1.animationSettings.opacityArray = [[0,0],[11,0],[35,100]];

              // Add button control to animations (the timing will be covered by timing groups)

             

              myButton1.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle1P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton1.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle6P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton2.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle2P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton2.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle7P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton3.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle3P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton3.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle8P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton4.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle4P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton4.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle9P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton5.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle5P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

              myButton5.animationBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp, enableBehavior:true, animatedPageItem:myRectangle10P1, autoReverseOnRollOff:false, operation:AnimationPlayOperations.play});

           

          // Change timing settings

              var myPageOneTimingSettings = myDocument.spreads.item(0).timingSettings;

              //Remove the default On Page Load timing list.

              myPageOneTimingSettings.timingLists[0].remove();

              var myButton1TimingList = myButton1.timingSettings.timingLists.add(DynamicTriggerEvents.onRelease);

              var myButton1TimingGroup = myButton1TimingList.timingGroups.add(myRectangle1P1,0);

          //

          }

          //Utility functions.

          function mySetUnits(myUnits){

              app.documents.item(0).viewPreferences.horizontalMeasurementUnits = myUnits;

              app.documents.item(0).viewPreferences.verticalMeasurementUnits = myUnits;

          }

          // Added a script label parameter to the function myMakeTextFrame to allow reference

          function myMakeTextFrame(myPage, myBounds, myString, myString2, myFontName, myPointSize, myJustification, myFitToContent){

              var myTextFrame = myPage.textFrames.add({geometricBounds:myBounds});

              myTextFrame.texts.item(0).insertionPoints.item(0).contents = myString

              myTextFrame.texts.item(0).parentStory.appliedFont = app.fonts.item(myFontName);

              myTextFrame.texts.item(0).parentStory.pointSize = myPointSize;

              myTextFrame.texts.item(0).parentStory.fillColor = app.documents.item(0).swatches.item("Black");

              myTextFrame.texts.item(0).justification = myJustification;

              myTextFrame.label = myString2;

              if(myFitToContent == true){

                  myTextFrame.fit(FitOptions.frameToContent);

              }

              return myTextFrame;

          }

          function myMakeTextFrameButton(myPage, myBounds, myString, myString2, myFontName, myPointSize, myJustification, myFitToContent){

              var myTextFrame = myPage.textFrames.add({geometricBounds:myBounds});

              myTextFrame.texts.item(0).insertionPoints.item(0).contents = myString

              myTextFrame.texts.item(0).parentStory.appliedFont = app.fonts.item(myFontName);

              myTextFrame.texts.item(0).parentStory.pointSize = myPointSize;

              myTextFrame.texts.item(0).parentStory.fillColor = app.documents.item(0).swatches.item("Black");

              myTextFrame.texts.item(0).justification = myJustification;

              myTextFrame.label = myString2;

              if(myFitToContent == true){

                  myTextFrame.fit(FitOptions.frameToContent);

              }

              var myButton = myPage.buttons.add({geometricBounds:myBounds});

              myButton.states.item(0).addItemsToState(myTextFrame);

              return myButton;

              }

          // Added a script label parameter to the myMakeRectangle for reference in CS5.5

          function myMakeRectangle(myPage, myBounds, myString, myString2, myFillColor,  myStrokeColor, myStrokeWeight){

              var myRectangle = myPage.rectangles.add({geometricBounds:myBounds, fillColor:myFillColor, strokeWeight:myStrokeWeight, strokeColor:myStrokeColor, name:myString, label:myString2});

              return myRectangle;

          }

          function myMakeColor(myColorName, myColorSpace, myColorModel, myColorValue){

              var myColor;

              var myDocument = app.documents.item(0);

              myColor = myDocument.colors.item(myColorName);

              if(myColor.isValid == false){

                  myColor = myDocument.colors.add({name:myColorName});

              }

              myColor.properties = {space:myColorSpace, model:myColorModel, colorValue:myColorValue};

              return myColor;

          }

          function mySetSWFExportPreferences(){

              app.swfExportPreferences.rasterizePages= false;

              app.swfExportPreferences.flattenTransparency = false;

              app.swfExportPreferences.dynamicMediaHandling = DynamicMediaHandlingOptions.includeAllMedia;

              app.swfExportPreferences.frameRate = 24;   

          }

          • 2. Re: Invalid Parameter When Attempting to Create a TimingGroup for a Button
            barrywrightiii Level 1

            I should also mention that I had similar issues when trying to create a timingGroup for a regular object (like myRectangle1P1 in the script above).

             

            I think I have a decent workaround, but I think it would be very useful for myself and others to know how to set a timingGroup correctly for objects and buttons.

             

            Continuing to troubleshoot....

             

            Barry

            • 3. Re: Invalid Parameter When Attempting to Create a TimingGroup for a Button
              barrywrightiii Level 1

              Working forward; I was able to access the timing group of the button, and group two animations directly in Indesign.  This makes me hopeful that it can indeed be done using scripting!

               

              This made me realize I may have had an issue since there is already an a timingGroup present.

               

              I attempted to remove it using the remove method:

               

              --- Snippet ---

               

              // Change timing settings

                  var myPageOneTimingSettings = myDocument.spreads.item(0).timingSettings;

                  //Remove the default On Page Load timing list.

                  myPageOneTimingSettings.timingLists[0].remove();

                  // Attempt to clear Button Timing List

                  myButton1.timingSettings.timingLists[0].remove();

              }

               

              --- End Snippet ---

               

              This threw an error; "Cannot delete button timing list directly.  To delete, remove button action list."