A colleague (Brad) is trying to get his Flex application to talk to a PDF through the HTML wrapper and asked me if I knew how to set up communication between Flex and the browser. I don't know if it will help him much, but I wrote up an e-mail with what I knew and sent it along. Once I was done, I thought that it might just be of help to someone else out there so here is a beefed-up version of what I sent to him (with added home-made diagrams!)
(I apologize ahead of time if the source code formatting isn't ideal... I cut and pasted it from my original e-mail and Outlook really mangled it.)
Flex and Javascript Getting Chatty: The ExternalInterface Class
The ExternalInterface
class provides a few static methods that allow both Flex to invoke
Javascript functions and Javascript to invoke Flex functions. In usual
practice, when run on the web, a Flex SWF is embedded in an HTML
document (a.k.a. the HTML "Wrapper"). This document is like any other
HTML document, and can therefore include CSS information and
Javascript. Thanks to the Flex ExternalInterface class, the Javascript
inside the HTML wrapper is exposed to the SWF. The ExternalInterface
also allows the SWF to expose a public interface to the HTML wrapper's
Javascript code.

If
you take a moment to think about the possibilities, you quickly realize
that you can accomplish many powerful things using this functionality...
- Flex to AJAX communication
- Flex to Flex
communication (within a single HTML wrapper)
- Flex to Acrobat communication (as in
Brad's case)
- Flex to anything else that exposes
functionality to Javascript code in the HTML wrapper (i.e. other plug-ins)
