Lab: Adobe Captivate-to-Flash ActionScript Communication

Workaround 1: Embed Flash SWF into Captivate

How it works

The key to this workaround is importing an 'ActionScript SWF'—a Flash SWF containing one line of ActionScript—into the Captivate movie.  The imported Flash SWF's ActionScript will be executed when the Captivate play head reaches the imported SWF.

Screenshot of Captivate's timeline

It's important to note that Captivate's handling of the imported ActionScript is best described as temperamental, and should be limited to a single, simple function call, such as _root.unloadMe().

Files required

  1. HTML file.
  2. Flash "player" FLA.
  3. Captivate file.
  4. Flash "ActionScript" FLA containing one line of ActionScript (will be embedded into Captivate file prior to publishing).

 

Instructions

1. In player.fla, create the function you'd like the Captivate SWF to invoke

Open player.fla and write a function that you would like your Captivate SWF to invoke. The function should be contained in the first frame of the FLA's timeline. For this example, we'll write a function named "unloadMe" that does exactly what the name implies:  when invoked, it will unload the Captivate SWF from the player.

function  unloadMe(){
   unloadMovie("swfHolder");
}

 

2. Add the loadMovie code

While we still have player.fla open, let's add the loadMovie code we'll need to automatically load our Captivate SWF for us. We also need to add the stop() command to prevent the player.swf from looping.

loadMovie("sample-captivate-movie.swf",  "swfHolder");
stop();

Screenshot of Flash's "Actions" window

 

3. Publish player.fla

Publish the file.  Turn off the HTML option, since we don't need any HTML generated for this SWF. Also make sure the SWF is published as Flash Player v7 for maximum compatibility (this demonstration uses ActionScript 2.0).

 

4. Create the "ActionScript SWF"

Create a new, blank FLA in Flash.  Add the following line of ActionScript to the first frame:

_root.unloadMe();

Note: I've named the default layer "actions"; this isn't a requirement, but it's a good practice. 

Screenshot of Flash's "Actions" window

Save the FLA file as "unloadMe", which is the same name as the function it contains. This makes identifying "ActionScript" SWFs much easier if you're using more than one in your Captivate file.

Publish the file.  Turn off the HTML option, since we don't need any HTML generated for this SWF. Also make sure the SWF is published as Flash Player v7 for maximum compatibility (this demonstration uses ActionScript 2.0).

 

5. Import the ActionScript SWF into the Captivate movie

Open the Captivate file and navigate to slide two. Note: The file provided for this demonstration is a Captivate 3 file.

Choose Insert > Animation from the menu at the top of the screen.  Select the unloadMe.swf file.  You will see a warning about using "root".  This is safe to ignore (see A word about _root); click Yes.

Screenshot of Captivate's "root" warning

The New Animation window will appear. Leave the settings in the Animation tab as-is.  Go to the Options tab; under Display for, select "rest of slide". Under Effect, select "No transition."  Click OK.

Screenshot of Captivate's "New Animation" window

 

The ActionScript is now a part of your Captivate movie.  Save the Captivate file, but don't publish it yet.

 

6. Turn off skinning

Since this Captivate movie will be loaded into another SWF (our custom player.swf), it's safe to turn off Captivate's skinning feature.  Go to Project > Skin and uncheck "Show playback control" — we don't need Captivate's playback controller — then uncheck "Show borders".

Screenshot of Captivate's skin editing options

 

Note: If you preview the new Captivate SWF in Captivate or anywhere outside of the player SWF, nothing will happen when Captivate plays the ActionScript SWF.  If you recall, this is because the function unloadMe() does not exist in the Captivate file; the function is stored in the player SWF.  It can only be executed if the Captivate SWF has been loaded into the player SWF.

 

7. Publish the Captivate file

Click the Publish button.  The Publish window will appear. Use the following settings:

  • Flash SWF as the output type.
  • Uncheck "Export HTML" (you will get a warning, but it's safe to ignore it).
  • Select Flash Player 7 as the Flash Player Version.  This example will work in Flash Player 7 and higher. In some of your own projects, you may need to choose a higher version of Flash Player.

 

8. Test it!

Now that your files are ready, test them out! Make sure the following files are in the same folder:

  • index.html
  • player.swf
  • sample-captivate-movie.swf

Open index.html in your web browser.  The sample Captivate movie should automatically load.  Click the Click here to go to the next slide button. You should see the countdown, followed by the SWF unloading itself.

Workaround notes

Pros

  • Easy to send pure ActionScript calls from Captivate SWF directly to Flash "player" SWF.
  • Works with older versions of Flash Player.
  • Can be easily used in local environments, such as on a hard drive or CD-Rom.
  • Easy to control timing for invoking the ActionScript.
    • The ActionScript isn't bound to Captivate objects (such as buttons) or events (such as the 'end of slide' event), which enables you to invoke ActionScript at almost any time during the movie.

Cons/limitations

  • Bulky: this workaround requires creating and importing a new SWF for each custom ActionScript call.  This gets tedious when using a large number of imported SWFs.
  • Limited usefulness: The embedded Flash SWF can't do much within the Captivate SWF beyond calling a function stored in the player SWF.  For example, Flash-based forms and components won't work when imported into a Captivate movie, and conditional statements often fail due to scope issues.
  • This workaround is restricted to nested SWFs (a Captivate SWF loaded into a container/player SWF); the Captivate SWF cannot send ActionScript calls to any other SWFs.

 

< Go back to intro | Continue to next section: Workaround 2 >