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

How to close a floating rich media window automatically

csommer
Registered: Jun 11 2006
Posts: 28
Answered

I've got a Flex based swf file embedded as a Flash object in PDF. It has to be clicked for activation, causing it to open as a large floating window.

The swf has an "OK" button which initiates an interaction with the PDF. What I am trying to achieve its that the floating window is automatically closed, and the swf inactivated again, after the interaction is complete. So far I can only achieve this by selecting "Disable Content" in the context menu (which becomes available when the "Disable When" setting is set to such in the Flash object properties). I would like this action to be included in the script that is executed in the Flex button.

Is there perhaps a JavaScript that can achieve this (which could in turn be called by ActionScript in the Flex button)?

Many thanks.

My Product Information:
Acrobat Pro 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Closing a floating RichMedia Annot is done by setting the "activated" property of the annot to false. I've set this up where I have a PDF form button that activates the flash. Then I make the annot on the page really small and hide it underneath the button. The code in the button just sets "activated" to true.

Now for the diffucult part. Closing the floating player from a button on the SWF. The problem is that when the SWF ActionScript calls a JavaScript functon, the Flash player waits for a response from Acrobat JavaScript. If the call closes the Flash player then all heck breaks loose and Acrobat hangs or crashes. The trick is to decouple the actions with a timout script. I've been trying to figure this one out for a while and this solutions was just provided to me today by Joel Geraci, the Acrobat Technical Evangelist.

Use this line of code from the close button in the SWF
ExternalInterface.call("eval","app.setTimeOut('this.getAnnotRichMedia(this.pageNum,\"RM0\").activated=false;',100);");
The setTimeOut fucntion returns right away so the player is happy. Then the deactivation happens outside the context of the call for the RichMedia, making Acrobat happy.

Make sure you get all the quotes right, and the Annot name right. I've got this set up in one of my examples so that when the Rich media annot is setup, it finds it's own name and page number. Then sets them as persistent values. That way nothing needs to be hard coded in the SWF and it can be used on any PDF by just copying the RichMedia annot from one PDF to another.

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/]http://www.adobe.com/devnet/acrobat/[/url]

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

csommer
Registered: Jun 11 2006
Posts: 28
Thanks Thom, this works very well now.

I had tried setting the "activated" property before, but in the wrong context. Also, the setTimeOut method is crucial!
patra
Registered: Oct 19 2006
Posts: 270
In the Code:
1. What is "eval" and "RMO\" ?

2. Where is the name of the Annotation?

Thanks for your help
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
"eval" is a function in Core JavaScript. It evaluates JavaScript code formatted into a string. Very useful.

Acrobat automatically names the Rich Media Annotations starting with "RM0", "RM1", etx.

In the code, there are quotes, within quotes, within quotes. As you can imagine, this is a can be a bit of a problem. So I used single quotes for the first pair of embedded quotes. But for the 3rd level I had to do something different, so I used escaped quotes. That's what the \" is. The backspace or escape character nullifies the special meaning of the quote. So it's just another character to the First Level use of the string.

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/]http://www.adobe.com/devnet/acrobat/[/url]

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

patra
Registered: Oct 19 2006
Posts: 270
Thanks Thom for all your Help!

One more thing just to verify. The name of my Annotation is Photos.swf
So the code for the Close button in Flash(Action Script) will be:ExternalInterface.call("eval","app.setTimeOut('this.getAnnotRichMedia(this.pageNum,\"Photos.swf\").activated=false;',100);");

Is that correct?

Also with what Version of Reader works?

THANKS for all your help again
Have a great weekend!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If the name of the Annot really is "Photos.swf" then yes, you have the correct code. However, if you added the RichMedia Annotation with the "Flash Tool" in Acrobat 9, then I seriously doubt that is really the name.

You can get the name of a rich media annot by running this code from the console window.

this.getAnnotsRichMedia(this.pageNum)[0].name

which gets the 0th annot on the current page.

Rich Media Annotations are New for Acrobat 9, so they will only run in Adobe Reader 9, and presumably later versions.

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/]http://www.adobe.com/devnet/acrobat/[/url]

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

patra
Registered: Oct 19 2006
Posts: 270
THANKS Thom for all your help!
luckyp
Registered: Nov 20 2008
Posts: 1
Hello all, this is my first post, and at this moment, I'm feeling a bit clumsy.

Basically, I want to do the above, I'm sure I'm close, but bits are missing.
I have a flash file (action script 2), I've created a normal button in the flash file, and added the script above to that button.

Then, in acrobat 9, I create a flash tool button, add the swf file in the properties, select floating window and then cross my fingers...
I click the "close button" within the swf - nothing happens. I have to right click the swf and "disable content".

Thanks in advance for your patience in answering this question, I'm a technical illustrator and not a developer, so as soon as i looked at Flex, a hot sweat over took me and my head started hurting.

Regards,

Mark
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
PDF/SWF interactivity will only work with Flash 9/ActionScript 3 compatible SWF files. The Rich Media Annot will display any flash file, but the communication between Acrobat JavaScript and Flash ActionScript is only in the lastest versions of both.

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/]http://www.adobe.com/devnet/acrobat/[/url]

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

Koen_Wyckmans
Registered: Feb 9 2009
Posts: 18
Ever tested to embed a swf file with a closing button that is not on the first page?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, In fact I created a general methodology (and SDK) where the ActionScript code in the SWF figures out which page the RMA on and what its name is. Then it can turn itself off or write code into button that turns it on and off.

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

pfigueiredo
Registered: Mar 12 2009
Posts: 4
Could someone upload an example to the site?

I've tried adding the code below to the swf file button but it didn't work.

I create a demonstration video using Adobe Captivate. Added a button on the last slide. In the properties of the button, I selected "Execute JavaScript". Added the following code:

ExternalInterface.call("eval","app.setTimeOut('this.getAnnotRichMedia(this.pageNum,\"RM2\").activated=false;',100);");

Published the project as a SWF file (AS3).

Embedded the SWF file in a PDF document. The flash video played fine in a floating window but when I clicked the button I inserted within the SWF file, nothing happened.

Can anyone help?

Thank you in advanced.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are several rules you have to follow when setting up communication between Acrobat JavaScript in a PDF and ActionScript in a SWF that is embedded in that PDF using a RichMedia Annotation. You can find info in this Aritcle:

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

And in Joel's blog:

http://blogs.adobe.com/pdfdevjunkie/

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

tallmediaman
Registered: Mar 22 2010
Posts: 2
Hey all

I am kind of a newbie to the Acrobat and it's new features. I really need some guidance on how to pull off the "close button" thing--but can't seem to get it to work.

What I need to know is where I put this code:

ExternalInterface.call("eval","app.setTimeOut('this.getAnnotRichMedia(this.pageNum,\"RM0\").activated=false;',100);");

I am familiar with Flash, but not a hardcore programmer(mostly good at dissecting it).

My task is to launch a video in a floating window from a button on the pdf. I've got that down no with problem. I've got a custom video player that plays the videos nicely. What the client is asking for is more of a visible close button.

In Flash, where do I put the code? With AS3, you can't attach code to the button like you could with AS2, correct?

Once I get the button set up and the SWF published, I bring it in to Acrobat and what do I do next?

Sorry if this is a bloated post, I just can't seem to get this to work. What do I need to get both files to talk to each other?

Thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In order for Flash/Flex to work with Acrobat it has to be setup properly. Acrobat presents a slightly different player environment that HTML does. You can find lots of details on Joel Geraci's blog.

http://blogs.adobe.com/pdfdevjunkie/

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.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

BrendanEllis
Registered: Mar 30 2010
Posts: 7
great! try this one

“Don't just dream of success, work hard for it”
Calgary corporate training | Calgary management training