4 Replies Latest reply on May 4, 2009 9:12 AM by subieguy2

    Multiple Actions Assigned

    subieguy2 Level 1

      Is it possible to assign more then one action to a button that was created by a script at the document level?

       

      Looking to have my script create my button like so....

       

      // Sizes button
      var initialPosition = [ 325, 700 ];
      var w = 44.65;
      var h = 10.21;
      var vGap = 1;
      var aRect = [initialPosition[0], initialPosition[1]-(h+vGap), initialPosition[0]+w, initialPosition[1]-h-(h+vGap)];

       

      // 001_callout
      var c001 = this.addField("001_callout", "button", 1, aRect);
      c001.setAction("MouseUp", "this.gotoNamedDest('view_03');");

       

      The script I wrote above works fine. Only problem is I want it to go the destination and change the layer state. I have 7 layers that need to be turned off and 2 that need to stay on.

       

      Anyone help?

        • 1. Re: Multiple Actions Assigned
          MarkWalsh Level 4

          Write a function to do what you want, and call that function as the action for that button

          • 2. Re: Multiple Actions Assigned
            subieguy2 Level 1

            I am new to scripting so I am about to ask a very basic question I am sure.

             

            How do I write a function that will do 2 actions?

             

            Then would I use the getField command to assign the function to the button?

             

            If you could write a small sample code with comments that would really help me out!

             

            Thanks!

            • 3. Re: Multiple Actions Assigned
              MarkWalsh Level 4

              function goToFunction () {

                   this.gotoNamedDest('view_03');");

                   // Do more stuff here

              }

               

              Then, you would use 'goToFunction()' (or whatever you name your function) as the action for your button.

               

              c001.setAction("MouseUp", "goToFunction();");

              1 person found this helpful
              • 4. Re: Multiple Actions Assigned
                subieguy2 Level 1

                This did work for me. My code is still sloppy and probably could be much more efficient but hey...it works for now!

                 

                Thanks for the help!

                 

                For anyone referencing this post here is what my code looks like so you can edit to your own needs....

                 

                // Sizes button
                var initialPosition = [ 325, 700 ];
                var w = 44.65;
                var h = 10.21;
                var vGap = 1;
                var aRect = [initialPosition[0], initialPosition[1]-(h+vGap), initialPosition[0]+w, initialPosition[1]-h-(h+vGap)];

                 

                // Callout one function...
                function calloutOne(){
                this.gotoNamedDest('view_03');
                var CalloutOne = "Callout 1";
                var PasteFirst = "Paste 1st (Data)";
                var ocgArray = this.getOCGs(this.pageNum);

                 

                // Changes layer state. Turns off any layer that isn't labeled "Callout 1" and "Paste 1st (Data)"

                for ( var i=0; i < ocgArray.length; i++) {
                if ( ocgArray[i].name == CalloutOne ) {
                ocgArray[i].state = true;
                }
                else ocgArray[i].state = false;
                }

                 

                for ( var z=0; z < ocgArray.length; z++) {
                if ( ocgArray[z].name == PasteFirst ) {
                ocgArray[z].state = true;
                }
                }
                }

                 

                 

                 

                // Creating button. Assigning button a name of "001_callout". Assigning the button the actions of on MouseUp run function calloutOne.
                var c001 = this.addField("001_callout", "button", 1, aRect);
                c001.setAction("MouseUp", "this.calloutOne();");