11 Replies Latest reply on Jan 5, 2012 11:09 AM by George_Johnson

    I need help duplicating a button

    T_Stevens Level 1

      I have a button that I often have to put on forms, so I have a pdf with nothing but that button in it. Whenever I need to use the button I open the pdf, go into my forms tools, edit the form, copy the button, and then paste it into the pdf that needs the button. I'm looking for a way to streamline the process by using an action. My idea is that I can insert my button pdf as the first page of any other pdf, move the button from page 1 to page 2 (or duplicate it on to page 2), then delete page 1 leaving just my form with the button.

      The problem I'm running into is that I can't find any way of moving, or duplicating my button on to page 2. I assumed I could do it with a script, but I haven't been able to get it done. I don't think creating a new button with a script will work since my button has about 350 lines of script already attached to it, as well as specialty images when rolled-over and pressed (though if there's a way to maintain those attributes I'm happy to try).

      Any help would be greatly appreciated.

        • 1. Re: I need help duplicating a button
          try67 MVP & Adobe Community Professional

          It's possible to create a script that will create the button and apply all

          of the properties you want it to have. Basically you need to use the

          addField() method of the Document object, and then just use any Field

          properties you wish. All of this can be placed inside an action and applied

          to one or more files.

          1 person found this helpful
          • 2. Re: I need help duplicating a button
            George_Johnson MVP & Adobe Community Professional

            You can also programmatically add the page to the document, make it a template, and spawn the template onto the page you want the button to be, and then remove the template page.

            • 3. Re: I need help duplicating a button
              T_Stevens Level 1

              I appreciate the help. Because of the replies I received, I assume that I can't just move the button from one page to another, so I'm proceeding with your suggestion try67, and this is where I'm at:

              My action now inserts my button page in the form, uses a script to get the icons from that button, and deletes the button page. The script also creates a new button on the first page of the form and sets up the button properties.

              The problem I'm facing now is getting the javascript from my original button into the new button.

               

              My current solution is to copy the original button's javascipt and paste it into my action's javascript. I wrap that script in a function called "buttonFunction" and then use the following code snippet in my action javascript:

               

              function buttonFunction()

              {

              //about 350 lines of code

              }

              f.setAction("MouseUp","buttonFunction()");

               

              I'm hoping there's a way to get the 350 lines of code into my newly created button without having that code written into my action script. Is it possible to copy my original button's javascript into a variable, then using that variable instead of buttonFunction()?

              I'm hoping for something like:

              var myScript = g.getAction("MouseUp");

              f.setAction("MouseUp",myScript);

               

              If you have any ideas, I would appreciate the help.

              • 4. Re: I need help duplicating a button
                try67 MVP & Adobe Community Professional

                No, that's not possible. You need to convert your script into a single

                string (remembering to escape all quotes and back-slashes) and then apply

                it using the setAction() method of the Field object you've created.

                1 person found this helpful
                • 5. Re: I need help duplicating a button
                  T_Stevens Level 1

                  One more question for you:

                  On occasion the original button's javascript is updated by someone else, and I'm not always aware of the change until later. Do you have any recommendations on how I can incorporate those changes into my new button without manually updating the action script whenever I notice a change to the original button?

                  • 6. Re: I need help duplicating a button
                    try67 MVP & Adobe Community Professional

                    There isn't really any way you can know the script has changed. What you

                    can do (but it's more complex) is create a script that reads in a text file

                    (where the button code exists) and then applies it to the button's MouseUp

                    action. You can ask the other people to only edit that file (and then

                    import it using the script), and not the actual code itself...

                    • 7. Re: I need help duplicating a button
                      T_Stevens Level 1

                      Thanks for all your help.

                      • 8. Re: I need help duplicating a button
                        try67 MVP & Adobe Community Professional

                        I just thought of possibly another way of doing it. You can place the

                        script code in a text field (hidden, if you like) and then in the button

                        itself just read the value of that text field and use eval() to execute

                        it...

                        • 9. Re: I need help duplicating a button
                          George_Johnson MVP & Adobe Community Professional

                          The advantage of using the template approach is you won't have to bother with specifying the script in code to be used with the setAction method. The button can be modified in any way and you don't have to bother updating the script when it changes. And it would just be a few lines of code.

                          • 10. Re: I need help duplicating a button
                            T_Stevens Level 1

                            I've never used template objects in my scripting before, George, which is why I was using try67's approach. I'm looking through the documentation, and I'm not sure I understand exactly how to go about creating the template. I assume that it's similar to this:

                             

                            var t = this.createTemplate({cName:"buttonTemplate", nPage:0}); //create template from button page

                            t.spawn(1,false,true); //overlay template on form page

                            this.deletePages({nStart: 0, nEnd: 0}); //delete button page

                             

                            Am I close?

                            • 11. Re: I need help duplicating a button
                              George_Johnson MVP & Adobe Community Professional

                              Yes, that's the idea.