A few months ago I wrote about the dilemma of trying to load Captivate SWFs into an ActionScript 3-based parent SWF.
I present to you the ActionScript 3 class LegacyCaptivateLoader. This class utilizes ExternalInterface and a proxy SWF to facilitate sending commands to and querying data from an ActionScript 2-based Captivate SWF.
How it works
The LegacyCaptivateController class extends sprite, and is basically a Loader with Captivate-specific methods. It uses ExternalInterface to facilitate synchronous communication between the AS3 SWF and the Captivate (AS2) SWF.
(Note: I previously created a LocalConnection workaround for AS3-to-Captivate communication, but the asynchronous nature of LocalConnection made it very difficult to work with, and ExternalInterface is more reliable.)
- The AS3 SWF calls the class LegacyCaptivateLoader.
- The LegacyCaptivateLoader class automatically creates a Loader instance and loads a proxy SWF (AS2).
- The proxy SWF in turn contains a MovieClipLoader that loads the Captivate SWF.
- The queries and commands from AS3 go to the browser, where they are then routed to the proxy SWF via ExternalInterface. The proxy then sends commands directly to the Captivate SWF via direct ActionScript 2 communication.
Here hacky, hacky hacky!
As I mentioned, this system requires a few hacks. Here are the main ones:
Hack #1: The external proxy SWF. The AS3 SWF must load the proxy SWF for this system to work. The proxy SWF acts as a relay, which is necessary since we can’t add custom ActionScript ExternalInterface code directly to the Captivate SWF.
eval() hacks in the ExternalInterface calls, we have to use the non-standard global namespace method of grabbing the SWF. So instead of using a DOM method such as
we simply use
Standardistas cringe (me, too!), but in my mind it’s the least evil, most compatible, most secure and easiest to use hack of the bunch.
Hack #3: Because of hack #2, the HTML file must be in quirks mode (no DOCTYPE) to work in Firefox. Note that in my testing, the standards mode version (XHTML transitional) works in IE6 and Safari 3.1.
Give it a spin!
Please give the class a try and let me know how it works for you… success stories and bugs! (Please add comments to this thread or post at the eLearning Technology and Development Google Group). Thanks!
New SCORM ebook coming soon!
I'm writing an ebook explaining how to build an HTML-based SCORM course. Subscribe to be notified when it's ready, as well as receive early bird pricing and some free goodies!