8 Replies
Mark Ramsey

I just did a proof of concept for this idea.

I create a Flash file with a button, and add an Event Listener to capture the button's CLICK events. The function tied to the button click event increments a "count" variable by 1 every time it gets clicked. I then use the ExternalInterface class to send this value out to a Javascript function. I export this file as a SWF.

Here is the button CLICK event code:

function doMouseClick(e:MouseEvent):void {
  ExternalInterface.call("changeSLVar", String(count));

I then creat a Storyline file, and import the SWF file into it. Within the Storyline file, I creat a "count" variable that will eventually get the value sent by the SWF button. I save this file and publish it.

In the published folder I open up the story_content/user.js file and put in this SWF-receiving Javascript function:

function changeSLVar(aValue) {
  var player = GetPlayer();

This function gets the "count" value (by way of the "aValue" parameter), accesses the Player, and sets the Storyline variable to the new value.

One thing to keep in mind if you are planning to use something like this to facilitate Flash-To-Storyline communication: every time the Storyline file gets published, the story_content/user.js file gets overwritten, because it is derived file. So you will have to replace the Javascript edit to the story_content/user.js file every time you publish.

Also, I used a String to send this parameter value over to Storyline from Flash.  I think you could probably send over an integer or a Boolean for that matter. I kind of depends how Javascript treats the paramter. Since Javascript is loosely typed, I just stuck with Strings for this demostration.

Rick Pruitt

Mark, I really appreciate your post. To make this loop as intended I had to add a reset to the counter for the last frame of the swf. Beyond that each frame also had a unique image I used as a button rather than just one button.

function toRestart(e:MouseEvent):void {
   ExternalInterface.call("changeSLVar", String(count));
   if (count > 7) {
   ExternalInterface.call("refresh");//to refresh the counter
   count = 0;//to set the counter value
   trace("Now the count is " + count);
   } else {
   trace("The Count is " + count)

I left the counter visible in the published file here as a demo in case it is of interest to others.