How Do You Close a Floating Rich Media Flash Window?


I got a question this morning that got me thinking about some other issues I’ve had with Rich Media Annotations as well. Here’s the question…

I have a swf file created in Flex running in a PDF which opens in a floating window when clicked.

I can get the floating window to close by allowing “Disable Content” in the context window, but I’m trying to achieve the same effect when an “OK” button is clicked in the swf file. This button calls a function in the PDF and should ideally then close the floating window.

Any idea how to do this?

My first response was “No – no idea”. Since the Rich Media Annotation will be listening for a response from Acrobat, Acrobat will crash if you try to close the window programmatically. The same thing happens when you try to programmatically change pages in a PDF. I tried working around this issue myself multiple times, filed bug reports and then finally gave up. After the above question came in from an earlier post, I decided to try again and I asked the engineer who actually wrote the code for some suggestions on how to work around the problem. Bingo! After a pretty short email thread we got it.

Closing a Floating Rich Media Flash Window:
The solution involves decoupling the two events, A) clicking the button and B) having Acrobat execute the JavaScript that normally would cause the crash. A combination of an in the Flex application and the Acrobat JavaScript method app.setTimeOut will let you do this. Basically, you use to send Acrobat the JavaScript that you need to execute but you send it inside the app.setTimeOut method with a slight delay; my example uses 250 milliseconds or 1/4 second. In Flex Builder 3 or Flash CS3, if you want to close the first Rich Media Flash Annotation on the first page, that ActionScript code might look like this… “eval“, “app.setTimeOut(‘rm = this.getAnnotsRichMedia(0)[0]; rm.activated=false;’,250);“);

There are four layers you need to punch through to get the code you actually want to run to work:

  1. The code in red is the Acrobat JavaScript code required to close the first Rich Media Flash Annotation on the first page.
  2. The code in blue is the Acrobat JavaScript code required to set the 1/4 second delay before executing the code in red.
  3. The code in green is an Acrobat JavaScript function that will treat it’s string parameter as code to execute.
  4. Finally, the ExternalInterface
    allows us to pass all that to Acrobat.

  This example PDF demonstrates the ability to flip pages and close the floating Rich Media Flash Annotation using this work-around.

  The MXML Source – You’ll need to supply your own bitmap for the embedded image before compiling.


Sorry, the comment form is closed at this time.