These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Javascript/Acticonscript communication between SWF and PDF - Acrobat 8

csol
Registered: Oct 29 2008
Posts: 3

Hi there,

I am having difficulty getting a javascript function to execute when a button in the SWF is clicked.

The following is my actionscript code trying to call the Javascript function defined in the PDF.

addEventListener(MouseEvent.CLICK, function(e:MouseEvent)
	{
 
		ExternalInterface.call("eval","bob()");
 
		g2_btn.x += 2;
});

Where bob() is document level defined javascript function which simple prints to the console

//<Document-Level>
//<ACRO_source>bob</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:bob ***********/
function bob()
{
    console.println("BOB");
}
//</ACRO_script>
//</Document-Level>

Is there something that i am missing?
Or is the above only possible in version 9 of Acrobat

Any ideas / help would be appreciated

My Product Information:
Acrobat 3D 8.1, Windows
graysonlang
Registered: Oct 31 2008
Posts: 1
Make sure that the "Local playback security" setting (under File > Publish Settings... > Flash Tab) for the swf file is set to "Access network only".As for the ActionScript call, it's probably clearer to write it as:
ExternalInterface.call( "bob" );

If you want to have any arguments, just pass them as additional arguments to the call method. Such as:
ExternalInterface.call( "hello", "Bob", 2 );

With the Acrobat document-level JavaScript here:
function hello( name, times )
{
if ( name && times )
for ( var i = 0; i < times; i++ )
console.println( "Hello, " + name + "!" );
}

- grayson [at] adobe [dot] com
marblegravy
Registered: Nov 25 2008
Posts: 14
Same problem, and unfortunately the "Local playback security" setting didn't change anything. Tried it both ways, no love.

I also have Acrobat 8, and am trying to get an embedded swf to interact with the pdf.

[b]I've started simple just to try and get it all working:[/b]

In the swf, I have a button and a single function:
alert1.onRelease = function(){ExternalInterface.call("rar");}

And in the pdf, a single function as well:
function rar(){app.alert("RAR!");}

But I have no love. Any ideas? Am I missing something critical?

I'm placing the swf in the pdf using the movie tool...
alexpapa
Registered: Nov 25 2008
Posts: 68
Hi marblegravy, I have tried the same thing as you - also no luck, have you managed to find a solution?
marblegravy
Registered: Nov 25 2008
Posts: 14
Nope - still having trouble.

I'm starting to think that it's just not possible in Acrobat 8, and without a copy of Acrobat 9 around to test on, I can't even confirm if it would work in that. Though all the articles around the place seem to suggest that it would.

It's frustrating too, because I can get it all to fire off in a web page no problems. I guess that's what it was built for, but no luck with it embedded in the pdf.

If I do come up with a fix, I'll definitely come back and post up a solution.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
I believe this is only possible with version 9. Thom Parker wrote an article on using the new RMA that discusses the Acrobat JavaScript/ActionScript link that's now possible: http://www.acrobatusers.com/tutorials/2008/08/js_flash_buttons/

Also, check out Dr. Story's blog: http://www.math.uakron.edu/~dpstory/pdfblog.php

George
marblegravy
Registered: Nov 25 2008
Posts: 14
OK, attempt number two then - simply trying to get it to move to another page. I've tried a few things like:

> layering links over the top of the movie clip, but they fall underneath it and you can't click them.> using URL calls for "#page=3" to try and jump to page 3but neither of those fire.

Any ideas? Surely it has to be possible?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, The Rich Media annot is only in Acrobat 9. You can play a flash in earlier versions of Acrobat/Reader, but communication between Flash and Acrobat is only in version 9 with the Rich Media Annotation. And the Flash has to be Flash 9/ActionScript 3.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

marblegravy
Registered: Nov 25 2008
Posts: 14
Thomp - you're a legend.

Thanks for coming in and giving us the authoritative answer. I can now sleep better knowing it was the limitations of the software, not my lack of skill!
alexpapa
Registered: Nov 25 2008
Posts: 68
Is it true that functions like ExternalInterface are only available with a hosted PDF?

I.e. I distribute documents via email, so all local files - am I still able to use these features?
marblegravy
Registered: Nov 25 2008
Posts: 14
Nope, from what I've gathered you can use ExternalInterface in any pdf whether it is hosted or local provided you are using Acrobat 9.
alexpapa
Registered: Nov 25 2008
Posts: 68
Sorry for my ignorance, I am fairly new to this type of technology. When you say Acrobat 9, do you mean the reader it is viewed in eventually or do you have to use Acrobat 9 to create the PDF?

I use BFO to create PDF's and have access to Acrobat Javascript, so want to know if I am able to do the same thing or if I have to rather make the move to different software now.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Adobe Reader cannot be used for Document creation. You have to use some other tool.

The Flash integration into Acrobat/Reader is brand new, so as it stands now, to put a Rich Media annotation onto a PDF you either have to have Acrobat 9 Pro or build your own custom tool.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

jmccoy
Registered: May 27 2009
Posts: 1
Is it possible to have a Flash file running separately in the Flash player (projector) (not embedded in the pdf) open up a pdf document to a bookmarked page that is in the pdf?

If this is possible, is it also possible to have the same Flash file open up multiple bookmarked pages by navigating from within the initial pdf document and not open a new document each time?

Any information or nudging in the right direction would be greatly appreciated.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well, hmm, yes this is possible. A Flash file can open a PDF into an HTML container. And that PDF can contain a Flash. You can also have communication between JavaScript in the PDF and JavaScript in the HTML container and ActionScript in the PDF. So you can cause all sorts of trouble. But of course something like this takes a good bit of knowledge of Acrobat, Flash, and JavaScript to pull off.

You can get started by looking at these:

http://www.windjack.com/WindJack/Browser2PDF/brwsr2acroJS.htm

http://www.acrobatusers.com/tutorials/2008/08/js_flash_buttons

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script