Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Is there a javascript for object CLICK and DRAG

Explorer ,
Oct 10, 2018 Oct 10, 2018

Greetings all,

I have been tasked with making an interactive map for a learning exercise course. This only needs to be a map base graphic with some icons simulating different modes of transportation (i.e. - trucks, trains, planes), different building types and so on). The participants just need to take a scenario and determine the most effective way to get resources A to destination B by collecting there icons and drag them around on the map until they figure a solution.

All I need to do is just have the icons CLICK and DRAGABLE...the problem is, IT CANNOT BE FLASH-BASED...argh! This is extremely easy to do in Animate but the Flash Player is required to display the SWF file in the PDF...which as I said, is not an option.

The client has requested a PDF and I'm hoping I can deliver...does anybody have add a CLICK and DRAG code snippet for objects in Acrobat?

And just in case you're wondering, I haven't asked if I can give them an EXE file...which would solve all of my problems...but EXE files are pretty much outlawed and probably not good to ask until I have exhausted every possibility.

Thanks all...I have all my fingers and toes crossed on this one!

TOPICS
Acrobat SDK and JavaScript
958
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 10, 2018 Oct 10, 2018

The Acrobat JavaScript model does not include click and drag functionality, but it does include enough functionality to create an effective click and drag.

There are two main tricks to doing this.

1. Create a page sized transparent button to capture mouse clicks.

    a) when the button is clicked, get the mouse coordinates with the doc.mouseX and doc.mouseY properties,

    b) and then look though the annotation list for the page to see if any of the graphics, which I'm assuming are stamp annots, match the click position

2. On detecting a mouse down on a graphic, start an interval timer (app.setInterval).

    a) This timer runs a function that captures the mouse position and moves the selected graphic annotation the same distance the mouse has moved since the mouse down.

     b) When the mouse up is detected, kill the interval timer.

And that's how its done.  It gets more complicated if you want to detect when the user changes pages. I've dealt with this before by using a different interval timer to watch for page changes and then move the button to the new page.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2018 Oct 10, 2018

Thanks for the reply, Thom...I must say your answer reads well but I think it might be a bit over my head. The good thing is, it will only be a ONE page PDF...just the map with all of the movable icons.

I'll put my thinking cap on and give your instructions a shot...

Is there any way you can create a PDF with the page sized transparent button with one-two movable items that I can study?

Again, thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 10, 2018 Oct 10, 2018

You can download a sample here that uses a very similar technique, only it's not page size buttons.

Download and examine the "Swat the Fly" game.

Free Sample PDF Files with scripts

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2018 Oct 10, 2018

Thank you, Thom, I'll take a look at it and let you know how it goes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2018 Oct 10, 2018

Thom,

This is way more complicated than what I need...which makes it practically impossible for me grasp. Thanks for the effort...I'll just have to see what I might be able to figure out from your original response.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 07, 2019 Nov 07, 2019
LATEST

If you are still looking then ....

 

It to create a button field and to allow the reader of the PDF document to move the button field using JavaScript and the Acrobat/JavaScript API. "Clicking and Moving a Button Field in PDF" includes an example with two fields that you can drag around. It also includes the JavasScript function (constructor) to realize this feature. You may also want to consier developing an authoring tool that would generate the draggable button automatically.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines