Linux is for Lovers

powerpoint+flash interaction

Posted by: Joe Devietti on: April 17, 2009

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
    ActivePresentation.SlideShowWindow.View.Next
  ElseIf InStr(request, "gotoPrevSlide") > 0 Then
    ActivePresentation.SlideShowWindow.View.Previous
  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!

Leave a Reply


  • Joe Devietti: Hi Rahul, Yes, Lockfox is open source: it's all written in Javascript, and licensed under the GPLv3. A few ways to peek at the code: 1. Create your
  • Rahul: Hey guys! Great job making lockfox. Is it open source by any chance? Where can i get the source code?
  • ross: When lockfox runs the first time, it asks if it is allowed to access my passwords. If I click the YES bar, nothign happens. Clicking no makes the firs

Categories