title: Set Button icon using attached file
body: <p>I'm creating a kind of template for users to fill out in Adobe Acrobat Pro X, but they also need to attach photos. I've created a button based on <a href="https://forums.adobe.com/thread/1813729" rel="nofollow noreferrer">this thread here</a> which, when clicked, prompts the user to select a file and then attaches the file to the PDF. It works beautifully, except the template pdf has multiple pages with multiple locations for photos.</p>
  
  <p>I need a way to keep track of which (picture) attachment belongs to which location. My main idea so far is to simply insert code that will take the file and use it as the button's icon. (This is also good in the case where the user accidentally attaches the wrong file, then goes and uploads the right one without deleting the old one; I'll see the most recent choice and assume it's the correct one). </p>
  
  <p>The other idea would be to rename the files as they get attached (to Attachment1, etc.) but this doesn't seem to be as feasible.</p>
  
  <p>There are 2 different functions for the button depending on if the users are using Reader 11 or not.</p>
  
  <p>When they are not using Reader, the main code looks like this:</p>
  
  <pre><code>app.alert({
          cMsg: "Please select a file to attach.",
          cTitle: "Attach File",
          nIcon: 3,
          nType: 0
      });
  
      try {
  
          var rc = this.importDataObject("Attachment" + attachment_num);
          if (rc) {
              attachment_num += 1;
              app.alert({
                  cMsg: "Attachment successful.",
                  cTitle: "Attachment Successful",
                  nIcon: 3,
                  nType: 0
              });
  </code></pre>
  
  <p>I was thinking as the first line of the <code>if</code> statement, I could insert code to change the icon of the button that this code is running from, but I can't figure out the right thing to try. I was looking at using <code>buttonSetIcon</code> based on <a href="http://help.adobe.com/livedocs/acrobat_sdk/11/Acrobat11_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat11_HTMLHelp&amp;file=JS_API_AcroJS.89.746.html" rel="nofollow noreferrer">here</a> but I'm doing something wrong, probably because of my lack of JavaScript knowledge.</p>
  
  <p>What I was trying was something along the lines of this</p>
  
  <pre><code>var f = this.getField("ImageButton");
  f.buttonSetIcon(rc);
  </code></pre>
  
  <p>It doesn't work though. I am not sure what exactly <code>importDataObject</code> returns in the variable <code>rc</code> but I was hoping it would be the file itself.</p>
  
  <p>When the user is using Reader 11, this gets even more confusing because everything seems to just be one line of code, <code>annot.cAttachmentPath;</code>, but I'll focus on the other version first.</p>
  
  <p>Any ideas?</p>