Flash to Storyline communication

I've seen that there is a lot of examples for Storyline to set variables in an embedded Flash SWF file. But what if you want the Flash SWF to listen for a change in a Storyline file?

I was asked to simulate a car braking scenario. Audio in Storyline played on the time line, then when it was finished, the embedded Flash SWF, which was a scene of a driver driving down a road, would attach a rapidly approach stop sign movieclip to the timeline. The user had to click on a "brake pedal" button, and the Flash would then calculate stopping distance. When this interactive was over, we needed Storyline to play an end audio file.

So initially I needed to have the Flash SWF "listen" for the audio file triggering a change in a Storyline variable ('myStorylineVar'), and then do the braking action in the SWF file.

I accomplished this by extending my main Flash file with a Document class at the root:

package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.external.ExternalInterface;

import DocClass;
import Model;

public class Main extends MovieClip {

  private var aDocClass:DocClass;

  public var theStopSignChange:String = "false";

  public function Main() {
    aDocClass = new DocClass(this);
    this.addEventListener(Event.ENTER_FRAME, this.myFunction);

  function myFunction(e:Event):void {
    if (theStopSignChange=="false") {
      theStopSignChange =  ExternalInterface.call('GetPlayer().GetVar',"myStorylineVar");
    } else if (theStopSignChange=="true") {
      // the variable has changed
      aDocClass._model.changeVar="New Stuff";
      theStopSignChange = "false";
      this.removeEventListener(Event.ENTER_FRAME, this.myFunction);


This is a bit messy, using an ENTER_FRAME event to listen for the change. But it has the positive advantage of working.

I also engaged a DocClass and a Model class to facilitate firing off a custom event that told the Flash file to attach and start the stop sign down it's path. I may not have had to do this, but decided to to try & keep to best practices.

After the interactive was finished, I had the Flash file signal back to the host Storyline file to trigger an ending audio file to play.

I don't know whether or not this is helpful to you, but it certainly was an adventure. I had an option to just encase the entire interactive within a SWF file and be done with it. But integrating it into Storyline in this manner left the audio to be able to play back and be controlled within the Storyline framework, and the whole frame to stay controllable and replayable with no hiccups.

I would like to try this kind of set up controlling SVG/Javascript animation, but I'm sure that brings with it it's own set of issues. Gonna try it at some point though. 


2 Replies
onEnterFrame (James Kingsley)

Nice Job!

Another way to handle the change in Storyline's variable would be to add an ExternalInterface.addCallback to your AS. Something like:

function slVarChanged(newValue){
//new value is true 
//lets do stuff

Then in SL have a js trigger to call your AS function and pass the value. 

This eliminates the cpu cycles needed for that onEnterFrame