Obsolete ActionScript 3 API

This article describes the way of the iSpring generated presentations communication with Flash applications written in ActionScript 3 and Flex.

Table of contents:

ActionScript 3.0 and ActionScript 2.0 communication

iSpring generated Flash presentations provide ActionScript 2.0 API. Being loaded by Flash 9 or Flex applications which use ActionScript 3, this API is not accessible anymore - ActionScript 2 and ActionScript 3 object model are not compatible; Flash movies version 8 or below work in isolated environment within Flash 9 (AS3) and Flex applications.

However, there is a way AS2 and AS3 Flash movies can communicate. It is a LocalConnection class usage. One Flash movie creates a named LocalConnection object, defines some functions in it and calls connect() method:


var lc:LocalConnection = new LocalConnection();
lc.sayHello = function(name:String):Void
{
    trace("Hello, " + name + "!");
}

lc.connect("connectionName");
  

Another Flash movie calls these methods using send() method:

var lc:LocalConnection = new LocalConnection();
lc.send("connectionName", "sayHello", "John Smith");
   

The first Flash movie will receive and execute commands froth the second. When a two-way interaction is needed, each Flash movie must create 2 LocalConnection objects: one connection to send commands and another one to receive them.

There is one thing which must be taken into account. It is possible to create only 1 LocalConnection with a given name on the same PC. So it is recommended to generate connection name based on some random information such as date. The sending Flash movie needs a connection name of the receiving Flash movie. This connection name can be passed as an URL parameter:

var lc:LocalConnection = new LocalConnection();
lc.sayHello = function(name:String):Void
{
    trace("Hello, " + name + "!");
}

// generate connection name which is most likely unique
var connectionName:String = "conn" + (new Date().getTime());
lc.connect(connectionName);
var childMove:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());

// load child movie and pass the connection name in URL parameter
childMovie.loadMovie("someMovie.swf?lcid=" + escape(connectionName));
   

A child Flash movie gets the connection name from URL variables:

var lc:LocalConnection = new LocalConnection();
lc.send(this.lcid, "sayHello", "John Smith");
   

A similar way of Flash movies interaction can be used to establish communication between ActionScript 3 Flash movie and iSpring generated presentations. Flash9 / Flex application loads a special bridge SWF module written in ActionScript 2 which loads the presentation. This bridge module communicates with the presentation using its ActionScript API; from the other hand the bridge communicates with Flash 9 / Flex application using LocalConnection. This process is illustrated in the following diagram.

Figure 1. ActionScript 3 <-> iSpring presentation communication

ActionScript 3 bridge communication module API

A bridge communication module (with source code) is included in iSpring Presenter and iSpring SDK samples. There is also a set of ActionScript 3 classes providing ActionScript 3 API simplifying communication with iSpring presentations.

Figure 2. iSpring ActionScript 3 bridge API

Class name Description
AnimationStep Provides the information about animation step timing
AnimationSteps Stores a collection of the slide animation steps
BridgeEvent Stores the information about events occurring duriong presentation loading and playback
BridgeLoader Loads the presentation using bridge communication module.
PlaybackController Receives presentation playback event notifications
Player Provides an access to the presentation playback core
PresentationInfo Provides an access to the presentation information
PresenterInfo Provides the information about presenter
ReferenceInfo Provides the information about the particular presentation reference
ReferencesCollection Stores a collection of presentation references
SlideInfo Provides the information about the particular slide
SlidesCollection Stores a collection of slides
SoundController Provides sound control facilities

Integration with Flex applications

iSpring generated presentations can be easily integrated with Flex applications using ispring.flex.PresentationContainer class. This class extends the standard mx.core.UIComponent class.

Samples

The following example illustrates the usage of the AS3 bridge module in Adobe Flash CS3:


   import ispring.as3bridge.*;
   import flash.display.*;
   import flash.events.*;

   var player:Player;

   if (flash.system.Capabilities.playerType == "External")
   {
       writeLog("This example will work in browser plugin, ActiveX or Standalone Flash player");
       return;
   }

   // create target sprite
   var target:Sprite = new Sprite();
   addChild(target);

   // load bridge
   var loader:BridgeLoader = new BridgeLoader(target);
   loader.addEventListener(BridgeEvent.PLAYER_INIT, onPlayerInit);
   player = loader.loadPresentation("as3bridge.swf", "presentation.swf");

   function onPlayClick(e:MouseEvent):void
   {
       player.playbackController.play();
   }

   function onPauseClick(e:MouseEvent):void
   {
       player.playbackController.pause();
   }

   function onPlayerInit(e:BridgeEvent):void
   {
       writeLog("Player initialized");
       player.playbackController.addEventListener(BridgeEvent.SLIDE_CHANGE, onSlideChange);

       playButton.buttonMode = true;
       playButton.addEventListener(MouseEvent.CLICK, onPlayClick);
       pauseButton.buttonMode = true;
       pauseButton.addEventListener(MouseEvent.CLICK, onPauseClick);
   }

   function onSlideChange(e:BridgeEvent):void
   {
       writeLog("current slide: " + e.slideIndex);
   }

   function writeLog(txt:String):void
   {
       log.appendText((log.text.length == 0) ? txt : "\n" + txt);
       log.scrollV = log.maxScrollV;
   }

ActionScript 3 communication demo

Figure 3. ActionScript 3 Bridge Flash example

Adobe Flex communication demo

Figure 4. Flex example