ActionScript 3 and Flex support in iSpring

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 + "!");


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());
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");

The similar way of Flash movies interaction can be used to establish communication between ActionScript 3 Flash movie and iSpring generated presentations.

iSpring Presenter and iSpring SDK products allow embedding a special ActionScript communication module (AS3 Connector) into the generated flash presentation. This communication module provides presentation playback control facilities via LocalConnection protocol accessible from Flash applications written in ActionScript 3.

iSpring SDK and iSpring Presenter products include a set of AS3 classes and interfaces which simplify communication between AS3 applications and iSpring generated presentations with embedded AS3 connector. These classes and interfaces provide facilities for presentation loading and playback control. They can also broadcast notifications about various events during presentation playback.

The communication between ActionScript 3 application and iSpring generated presentation is illustrated in the following diagram.

Figure 1. ActionScript 3 <-> iSpring presentation communication

ActionScript3 Connector

ActionScript3 Connector (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 API
Class name Description
AcquireFocusEvent Creates acquire keyboard focus event objects.
IAnimationStep Provides the information about animation step timing.
IAnimationSteps Stores a collection of the slide animation steps.
ICompanyInfo Stores the information about company.
ICompanyLogo Stores the information about company logotype.
IPlayer Provides an access to the presentation playback core.
IPresentationInfo Provides an access to the presentation information.
IPresentationPlaybackController Provides presentation playback and navigation control.
IPresenterInfo Stores the presenter information.
IPresentersCollection Stores a collection of presentation presenters.
IPresenterVideo Stores the information about presenter video.
IReferenceInfo Provides the information about the particular presentation reference.
IReferencesCollection Stores a collection of presentation references.
ISlideInfo Provides the information about the particular slide.
ISlideResources Provides the information about resources associated with particular slide.
ISlidesCollection Stores a collection of slides.
ISoundController Provides sound control facilities.
PlaybackEvent Creates playback event objects.
PlaybackPositionEvent Creates playback position event objects.
PlayerEvent Creates player initialization event objects.
PresentationLoader Simplifies the process of iSpring generated Flash movies loading.
SlidePlaybackEvent Creates slide playback event objects.
SoundEvent Creates sound event objects.
StepPlaybackEvent Creates animation step playback event objects.


The following example illustrates the usage of the ActioScript3 API module in Adobe Flash CS3:

       import ispring.as2player.*;

       var g_player:IPlayer;

       // load presentation
       var loader:PresentationLoader = new PresentationLoader();
       loader.addEventListener(PlayerEvent.PLAYER_INIT, playerInit);
       loader.load(new URLRequest("presentation1.swf"));

       // send after presentation loaded and initialized
       function playerInit(e:PlayerEvent):void
       g_player = loader.player;
       g_player.playbackController.addEventListener(SlidePlaybackEvent.CURRENT_SLIDE_INDEX_CHANGED, onSlideChange);

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

       function onSlideChange(e:SlidePlaybackEvent):void
       trace("current slide: " + e.slideIndex);

       function onPlayClick(e:MouseEvent):void

       function onPauseClick(e:MouseEvent):void

ActionScript 3 communication demo

Figure 3. ActionScript 3 example

Adobe Flex communication demo

Figure 4. Flex Example