3 Replies Latest reply on May 26, 2010 10:35 PM by romanobstuder

    JS: Buttons make States [Rollover] and [Click] available

    romanobstuder Level 1

      Hi all

      I am scripting InDesign buttons in JavaScript.

       

      var myStates = myButton.states;

      var myStateA = myStates[0];

      var myStateB = myStates[1];

      var myStateC = myStates[2];

      $.writeln ("A statetype: " + myStateA.statetype);
      $.writeln ("B statetype: " + myStateB.statetype);
      $.writeln ("C statetype: " + myStateC.statetype);
      If I manually create a button in InDesign only the State Appearance [Normal] is visible in the palette.
      The states [Rollover] and [Click] become active by clicking on the layer palette.
      Once this is done the above code works fine.
      If I create a button via a script:
      var myButton = myPage.buttons.add({visibilityInPdf:1181247844});
      only the [Normal] state exists. Therefore the script fails.
      I need some way to create the button and "activate" all 3 states of the button.
      Any hints very much appreciated!
      Romano

        • 1. Re: JS: Buttons make States [Rollover] and [Click] available
          romanobstuder Level 1

          UPDATE

           

          Adding

          myStates.add(State);

          2x created the extra to layers. I guess more to the point made the two layers accessable. The InDesign Object Model gets a bit blurry in my mind -)
          The following code is now working...
          ===========
          var myButton = myPage.buttons.add({visibilityInPdf:1181247844});
          var myStates = myButton.states;
          $.writeln ("myStates, lenght: " + myStates.length);
          $.writeln ("myStates, lenght: " + myButton.states.length);
          $.writeln ("absoluteVerticalScale: " + myButton.absoluteVerticalScale);
          $.writeln ("myStates: " + myButton.states);
          myStates.add(State);
          $.writeln ("myStates, lenght: " + myButton.states.length);
          myStates.add(State);
          $.writeln ("myStates, lenght: " + myButton.states.length);
          var myStateA = myStates[0];
          var myStateB = myStates[1];
          var myStateC = myStates[2];
          $.writeln ("A statetype: " + myStateA.statetype);
          $.writeln ("B statetype: " + myStateB.statetype);
          $.writeln ("C statetype: " + myStateC.statetype);
          $.writeln ("A statename: " + myStateA.name);
          $.writeln ("B statename: " + myStateB.name);
          $.writeln ("C statename: " + myStateC.name);
          ===========

          • 2. Re: JS: Buttons make States [Rollover] and [Click] available
            Peter Kahrel Adobe Community Professional & MVP

            Here's an example of how to code rollover. The script creates two buttons, one (grey) with the text "Roll", the other with the text "Pop". In the exported PDF, only the grey button displays. When you roll over it, the other button pops up. On roll off, the "Pop" button disappears.

             

            Peter

             

             

            doc = app.documents[0];

            // add a button which, when moused over, displays a textframe
            rollb = doc.buttons.add ({geometricBounds: [30,30,50,70], fillColor: "Black", fillTint: 50});
            rollb.textFrames.add ({geometricBounds: [30,30,50,70], contents: "Roll!"});

            // add a second button which will show when the other button is moused over
            popb = doc.buttons.add ({geometricBounds: [30,90,50,130]});
            // hide it initially in the PDF
            popb.visibilityInPdf = VisibilityInPdf.hiddenInPdf;
            // add a text frame to the button so that we can add some text
            tf = popb.textFrames.add ({geometricBounds: [30,90,50,130], contents: "Pop!"});

            // set mouse behaviour
            mouse_in = rollb.showHideFieldsBehaviors.add ();
            mouse_in.behaviorEvent =  BehaviorEvents.mouseEnter;
            mouse_in.fieldsToShow = popb;

            mouse_out = rollb.showHideFieldsBehaviors.add ();
            mouse_out.behaviorEvent =  BehaviorEvents.mouseExit;
            mouse_out.fieldsToHide = popb;

            • 3. Re: JS: Buttons make States [Rollover] and [Click] available
              romanobstuder Level 1

              UPDATE

               

              First a big thank you to Peter

              I did not exactly use the cody you gave me but you got me thinking about the text field of a button in a different way.

              The states of a button are rather tricky to access. Maybe the following code gives somebody else a clue how to solve there specific scripting in regards to buttons.

               

               

               

              var myButton = myPage.buttons.add();

              myButton.geometricBounds = [myCurrentParagraphBaselinePosition - 5, myX1, myCurrentParagraphBaselinePosition,  myX1 + 60];

               

              //var myTextFrameOnMyButton = myButton.textFrames.add({geometricBounds: [myCurrentParagraphBaselinePosition - 5, myX1, myCurrentParagraphBaselinePosition,  myX1 + 60], contents: "Roll!"});

               

              //$.writeln ("Button, text Frame, content: " + myTextFrameOnMyButton.contents);

               

              myButton.absoluteRotationAngle = 0;

               

              var myStates = myButton.states;

               

              $.writeln ("myStates, lenght: " + myStates.length);

              $.writeln ("myStates, lenght: " + myButton.states.length);

              $.writeln ("absoluteVerticalScale: " + myButton.absoluteVerticalScale);

              $.writeln ("myStates: " + myButton.states);

               

              myStates.add(State);

              $.writeln ("myStates, lenght: " + myButton.states.length);

               

              myStates.add(State);

              $.writeln ("myStates, lenght: " + myButton.states.length);

               

              var myStateA = myStates[0];

              var myStateB = myStates[1];

              var myStateC = myStates[2];

               

              $.writeln ("A statetype: " + myStateA.statetype);

              $.writeln ("B statetype: " + myStateB.statetype);

              $.writeln ("C statetype: " + myStateC.statetype);

               

              $.writeln ("A statename: " + myStateA.name);

              $.writeln ("B statename: " + myStateB.name);

              $.writeln ("C statename: " + myStateC.name);

               

               

              var myTextFrameA = myStateA.textFrames.add({geometricBounds: [myCurrentParagraphBaselinePosition - 5, myX1, myCurrentParagraphBaselinePosition,  myX1 + 60], contents: "Some Text"});

              var myTextFrameB = myStateB.textFrames.add({geometricBounds: [myCurrentParagraphBaselinePosition - 5, myX1, myCurrentParagraphBaselinePosition,  myX1 + 60], contents:  "Some more Text"});

              var myTextFrameC = myStateC.textFrames.add({geometricBounds: [myCurrentParagraphBaselinePosition - 5, myX1, myCurrentParagraphBaselinePosition,  myX1 + 60], contents: "Some more Text B"});

               

               

              myTextFrameA.fillColor  = "None";

              myTextFrameB.fillColor  = "tbgGrey";

              myTextFrameC.fillColor  = "None";