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
- ActionScript 3 bridge communication module API
- Integration with Flex applications
- Samples
- References
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");
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.
| 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.
| iSpring ActionScript 3 API |
| Class name | Description |
|---|---|
|
Creates acquire keyboard focus event objects. |
|
|
Provides the information about animation step timing. |
|
|
Stores a collection of the slide animation steps. |
|
|
Stores the information about company. |
|
|
Stores the information about company logotype. |
|
|
Provides an access to the presentation playback core. |
|
|
Provides an access to the presentation information. |
|
|
Provides presentation playback and navigation control. |
|
|
Stores the presenter information. |
|
|
Stores a collection of presentation presenters. |
|
|
Stores the information about presenter video. |
|
|
Provides the information about the particular presentation reference. |
|
|
Stores a collection of presentation references. |
|
|
Provides the information about the particular slide. |
|
|
Provides the information about resources associated with particular slide. |
|
|
Stores a collection of slides. |
|
|
Provides sound control facilities. |
|
|
Creates playback event objects. |
|
|
Creates playback position event objects. |
|
|
Creates player initialization event objects. |
|
|
Simplifies the process of iSpring generated Flash movies loading. |
|
|
Creates slide playback event objects. |
|
|
Creates sound event objects. |
|
|
Creates animation step playback event objects. |
Samples
The following example illustrates the usage of the ActioScript3 API module in Adobe Flash CS3:
import ispring.as2player.*;
import flash.events.*;
var g_player:IPlayer;
// load presentation
var loader:PresentationLoader = new PresentationLoader();
addChild(loader);
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
{
g_player.playbackController.play();
}
function onPauseClick(e:MouseEvent):void
{
g_player.playbackController.pause();
}
ActionScript 3 communication demo
| ActionScript 3 example |
Adobe Flex communication demo
| Flex example |
References
AcquireFocusEvent
IAnimationStep
IAnimationSteps
ICompanyInfo
ICompanyLogo
IPlayer
IPresentationInfo
IPresentationPlaybackController
IPresenterInfo
IPresentersCollection
IPresenterVideo
IReferenceInfo
IReferencesCollection
ISlideInfo
ISlideResources
ISlidesCollection
ISoundController
PlaybackEvent
PlaybackPositionEvent
PlayerEvent
PresentationLoader
SlidePlaybackEvent
SoundEvent
StepPlaybackEvent
iSpring ActionScript API