powerpoint+flash interaction

One of the cool things I learned about Powerpoint the other day is that it’s possible to create interactions between an embedded Flash movie and the presentation itself.  This allows you to coordinate animations across the movie and the slide, e.g. to have a mouse click sometimes advance the slide and sometimes trigger some action in the movie.

The reason all this works is because you can do function calls up from the Flash movie, through the ActiveX container and into VBA code attached to the Powerpoint presentation.   You can also call down from Powerpoint into Flash in a similar manner, though I haven’t experimented with this.

The Easy Part

Perhaps surprisingly, writing the code is the easy part.  The Visual Basic code attached to the Powerpoint slide looks like this:

Private Sub ShockwaveFlash1_FlashCall(ByVal request As String)
  'request looks like:
  '<invoke name="foo" returntype="xml"><arguments></arguments></invoke>;
  If InStr(request, "gotoNextSlide") > 0 Then
  ElseIf InStr(request, "gotoPrevSlide") > 0 Then
  End If
End Sub

ShockwaveFlash1 is the name of the ActiveX control for the Flash movie. If you only have one of these on a slide, this will be its name. But if you have more than one, the names will be ShockwaveFlash2 and so on.

In ActionScript land, the code that calls out of the Flash movie looks like this:

import flash.external.ExternalInterface;

if ( ExternalInterface.available ) {
   ExternalInterface.call( "gotoNextSlide" );

The Hard Part

Unfortunately, this code won’t do anything out of the box.

This is because of the Flash player security model, with which I became overly familiar over the course of this project. There are several different security sandboxes in which a Flash movie can potentially be running.  In order for ExternalInterface function calls to work, the movie needs to be, sensibly, in the most trusted sandbox: the LOCAL_TRUSTED sandbox. Fortunately, a movie can check what sandbox it’s running in with the following code:

import flash.system.Security;
trace( Security.sandboxType );

If you run a Flash movie in the standalone Flash player, it runs with LOCAL_TRUSTED privileges. However, if you run that same movie via an ActiveX control in Powerpoint, the default security settings put it in the LOCAL_WITH_NETWORK sandbox, which is insufficiently privileged to allow Powerpoint-Flash interaction to work. Instead, things will fail silently.  And no amount of tinkering with Powerpoint’s security settings (trusting ActiveX content, macros, etc.) will fix things. After much anguish, I discovered that you have to talk directly to the Flash runtime to get a movie into the LOCAL_TRUSTED sandbox when running inside an ActiveX control.

There are several ways of telling the Flash runtime to put a particular movie in the LOCAL_TRUSTED sandbox, all of them documented at the Adobe link above. Probably the easiest way is via the Flash Security Settings Manager gui: it’s a Flash applet that runs in your browser to control your local Flash settings – spooky!  You can decide to trust particular .swf files, or directories, or even the Powerpoint executable itself which will automatically trust all movies that are included in Powerpoint slides.  I’ve blogged previously about how to do this, but there are a few tricky parts I haven’t covered before.

If you’re embedding Flash movies into Powerpoint (as opposed to just linking to the movies), then you have to trust the Powerpoint binary, as the Flash movies don’t have a real filesystem location – if you check where an embedded movie lives via root.loaderInfo.url you will get the path to the Powerpoint binary. Trusting the Powerpoint binary is a hack that allows the movie, indirectly, to be trusted as well.  Trusting Powerpoint will also enable non-embedded Flash movies to run in the LOCAL_TRUSTED sandbox.

If your Powerpoint slides just link to the Flash movies, then you can have finer-grained control over security, but of course you have to ensure the links are always valid or the movies won’t work.

Other security considerations

Getting the Flash player security settings right was definitely the trickiest part, because they’re a bit out of the way and not terribly popular topics of conversation according to Google.  But to make Powerpoint and Flash play nice together you also need to (clearly) enable macros in Powerpoint and allow ActiveX controls to run.  ActiveX controls don’t need any special treatment however: they can run in Safe Mode with privileges that prompt you before they are enabled with “minimal restrictions”.  I never saw a prompt, because I don’t think the Flash ActiveX control requires any special privileges.

Once you get the security settings resolved things work great. It is highly unlikely, however, that things will work out-of-the-box if you move the presentation to a new computer, due to the default security settings. But once you get things integrated, you get the power of Flash for doing complicated animations with the ease of Powerpoint for the simple stuff. Pretty much the best of both worlds!


6 thoughts on “powerpoint+flash interaction

  1. Hi Joe,
    This post of yours has really intrigued me as I’m looking to achieve something very similar. I want to create a powerpoint presentation which uses a flash navigation to jump between slides. Some slides would have flash embedded animations on them also. Is it possible to get a working example from you so I can see how you apply the funtionality to both the flash elements and powerpoint document?
    Thanks, Alex

    • Hi Alex,

      The Powerpoint+Flash road has many pitfalls, but the end results can be very nice. I’m happy to hear someone else is trying this path!

      There is a working example with a presentation I made (apologies if you’ve already seen this). This source code for the Powerpoint side of things is in the macros attached to each slide, and the source code for the flash movies is included in the archive as well.

      I can try to dig up the IDE project files, too, if that would be helpful. I used FlashDevelop.


  2. Joe:

    I’m noticing when I embed swf files into PPT, if I view the slide with the swf it works fine, but if I navigate to the next slide and then come back, the swf timeline/playhead doesn’t get rewound or the swf file doesn’t get reset. I want it to reset every time I view the corresponding slide. How can I achieve this if it’s possible?


    • One thing that would probably work is to trigger the reset from the Flash movie (i.e., have it reset itself). You could do this just before advancing to the next slide, i.e. before the ExternalInterface.call( "gotoNextSlide" ); call. There might be some visual artifacts that appear from the reset redrawing the canvas, however. They might be quite minor, depending on how fast the reset happens.

      A more complicated workaround for these artifacts would be to advance to the next slide and then, from the ShockwaveFlash1_FlashCall Visual Basic code, trigger the reset on the (now) previous slide. So Flash calls into VB to advance to the next slide and then VB calls back to Flash to do the reset. I’m not sure that you can interact with Flash movies on non-visible slides, but if possible this should be a clean-looking solution.

  3. Hello Mister Devietti,

    I was looking the interwebs up and down for a solution to a “powerpoint vs flash” problem. As I am not a programmer it was better described by a fellow person also plagued by the same bug:

    Flash AS3 movie animations (and Events) freeze when embedded in PowerPoint 2007


    Can you, with your in-depth knowledge of the flash player, tell me if it is possible to reset the flash player from within powerpoint and reload the swf in a working state?

    Thanks for your feedback!

    • Hi Bernd,

      Thanks for bringing this up! This is indeed a tricky problem. I responded to your thread on the Adobe forums directly, to keep the conversation in one place.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s