Author Message

Posted: Thu Aug 30, 2007 12:34 pm   Post subject: Loading FS SWF into movie clip using MovieClipLoader

I have built an engine in Flash that can display many different types of content that can be dynamically loaded from a database. One of the requirements is to publish PPT files to the Flash show on command.

I have chosen FlashSpring as my PPT converter.

Once converted, the SWF file is loaded into a movie clip in my show using the MovieClipLoader. The show however should advance to another content type when the external SWF is complete.

My question therefore is:
- How do I find out when the externally loaded FlashSpring SWF is complete?

Alternatively,
- How do I find the current frame of a FlashSpring SWF and;
- How do I find out the maximum number of frames in a FlashSpring SWF?

Many Thanks in advance


Profile profile test

Posted: Fri Aug 31, 2007 11:14 am   Post subject:

OK, read through the documentation and managed to figure it out.
Excellent API!

I am having a problem with the whole lifecycle of the script though.

Once the onLoadComplete of the MovieClipLoader runs, I try and pause the player immediately so that I can start it when I am ready.

Code:
function onLoadComplete(target_mc:MovieClip):Void
{
   var checkController:IPlayer = target_mc.getPlayer();
   trace(checkController); // returns undefined sometimes
   if(checkController)
   {
      var checkPlayerController:IPresentationPlaybackController = checkController.getPlaybackController();
      checkPlayerController.pause();
   }
}

Sometimes, getPlayer() returns "undefined" and sometimes it returns the player object.

At what point does the player initialize?
How can I always catch the player once it is initialised?

Thanks in advance...


Profile profile test

Posted: Fri Aug 31, 2007 12:44 pm   Post subject:

AndyPapa wrote:
OK, read through the documentation and managed to figure it out.
Excellent API!

I am having a problem with the whole lifecycle of the script though.

Once the onLoadComplete of the MovieClipLoader runs, I try and pause the player immediately so that I can start it when I am ready.

Code:
function onLoadComplete(target_mc:MovieClip):Void
{
   var checkController:IPlayer = target_mc.getPlayer();
   trace(checkController); // returns undefined sometimes
   if(checkController)
   {
      var checkPlayerController:IPresentationPlaybackController = checkController.getPlaybackController();
      checkPlayerController.pause();
   }
}

Sometimes, getPlayer() returns "undefined" and sometimes it returns the player object.

At what point does the player initialize?
How can I always catch the player once it is initialised?

Thanks in advance...


Thank you for your question.

When you use MovieClipLoader classm its events are generated in the following order:

onLoadStart() // loading has been started
onLoadProgress() // loading is in progress
onLoadProgress() // loading is in progress
...
onLoadProgress() // loading is in progress
onLoadComplete() // loading has been complete
onLoadInit() // actions at the first frame of loaded movie clip have been executed

onLoadComplete event is called when flash movie has been loaded.
getPlayer() is a function exposed by FlashSpring Server/Ultra generated movie clips. This function becomes visible only when actions on the first frame of Flash presentations were executed. This event is called onLoadInit().

FlashSpring generated presentations in solid flash clip mode have the following structure:

[Player][Slide1][Slide2][Slide3]...[SlideN]

When a Flash presentation is loaded from the internet, it start playing as soon as player and data of the first slide are loaded. To make this possible we generate "interleaved" Flash file where frames and actions are interleaved with slide objects, thumbnails etc. This means that actions on the first frame of the Flash movie can be executed BEFORE presentation is loaded. That's why we need to try to get player during presentation loading process. This can be achieved by getting the player using onLoadProgress() event handler.

Even when you get IPlayer interface you cannot use it until it gets initialized. The reason for it is that player can need some time to initialize its internal data structures or load presentation information from the internet. So you need to check if isInitialized() method of the player returns true. If it returns false - the player has not yet been initialized. We can add a listener to the player which will be notified about finish of player initialization.

We plan to develop and include into FlashSpring API a CFlashPresentationLoader class that will encapsulate the process of loading of FlashSpring generated presentations.

You can find samples illustrating this process in "C:\Program Files\FlashSpring Ultra 2\samples\samples\flash-player-samples" folder

Here is the code example:

Code:
import fsplayer.api.*

var presentation:MovieClip = this.createEmptyMovieClip("presentation", 1);
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(this);
loader.loadClip("presentation.swf", presentation);

var g_playerAPI:IPlayer;
var g_controller:IPresentationPlaybackController;

System.security.allowDomain("*");

function onLoadProgress(mc:MovieClip, loadedBytes:Number, totalBytes:Number):Void
{
   tryToInitPlayer(nc);
}

function onLoadInit(mc:MovieClip):Void
{
   tryToInitPlayer(mc);
}

// This function is called when player gets initialized.
// only when it is called, you can control the presentation playback.
function onPlayerInit(p:IPlayer):Void
{
   g_controller = g_playerAPI.getPlaybackController();
   
   // this movie clip will listen to events of playback controller
   g_controller.addListener(this);   
}

function tryToInitPlayer(mc:MovieClip):Void
{
   if (!g_playerAPI)
   {
      g_playerAPI = mc.getPlayer();
      if (g_playerAPI)
      {
         g_playerAPI.addListener(this);
         if (g_playerAPI.isInitialized())
         {
            // the player has already been initialized so it will not call onPlayerInit() function. we have to do it manually.
            g_playerAPI.removeListener(this);
            onPlayerInit(g_playerAPI);
         }
      }
   }
}


Profile profile test WWW www ICQ ICQ

Posted: Fri Aug 31, 2007 1:35 pm   Post subject: Presentation loader class

Here is the simple class that can be used for loading FlashSpring generated presentations.


CPresentationLoader.as

Code:

import fsplayer.api.IPlayer;
import fsplayer.api.IPlayerListener;

class CPresentationLoader implements IPlayerListener
{
   private var m_player:IPlayer;
   private var m_target:MovieClip;
   private var m_bytesLoaded:Number;
   private var m_bytesTotal:Number;
   private var m_listener:IPlayerListener;
   private var m_errorHandler:Object;
   
   function CPresentationLoader()
   {
   }
   
   function setListener(listener:IPlayerListener):Void
   {
      m_listener = listener;
   }
   
   function setErrorHandler(handler:Object):Void
   {
      m_errorHandler = handler;
   }
   
   function load(url:String, target:MovieClip):Void
   {
      m_target = target;
      var ml:MovieClipLoader = new MovieClipLoader();
      ml.addListener(this);
      ml.loadClip(url, target);
   }
   
   function get player():IPlayer
   {
      return m_player;
   }
   
   function onPlayerInit(player:IPlayer):Void
   {
      m_listener.onPlayerInit(player);
   }
   
   private function onLoadProgress(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void
   {
      m_bytesLoaded = bytesLoaded;
      m_bytesTotal = bytesTotal;
      tryToInitPlayer();
   }
   
   private function onLoadError(target:MovieClip, errorCode:String, httpStatus:Number)
   {
      m_errorHandler.onLoadError(target, errorCode, httpStatus)
   }
   
   private function onLoadInit(target:MovieClip):Void
   {
      tryToInitPlayer();
   }
   
   private function onLoadComplete(target:MovieClip):Void
   {
      tryToInitPlayer();
   }
   
   private function tryToInitPlayer():Void
   {
      if (!m_player)
      {
         m_player = m_target.getPlayer();
         if (m_player)
         {
            if (!m_player.isInitialized())
            {
               m_player.addListener(this);
            }
            else   // the player has already been initialized. we need to call onPlayerInit manually
            {
               onPlayerInit(m_player);
            }
         }
      }
   }
}




This class can be used in the following way:

Code:
import fsplayer.api.*

var presentation:MovieClip = _root.createEmptyMovieClip("presentation", 1);
var loader:CPresentationLoader = new CPresentationLoader();
loader.setListener(this);
loader.load("presentation.swf", presentation);

var g_playerAPI:IPlayer;
var g_controller:IPresentationPlaybackController;

function onPlayerInit(p:IPlayer):Void
{
   trace("onPlayerInit");
   
   g_playerAPI = p;

   g_controller = g_playerAPI.getPlaybackController();
   
   g_controller.addListener(this);   
}



Profile profile test WWW www ICQ ICQ

Posted: Mon Sep 03, 2007 10:09 am   Post subject:

Thanks, excellent information!


Profile profile test

Posted: Mon Mar 09, 2009 3:51 am   Post subject: getPlayer() returns undefined

hello,
I am a developer in Boston, MA USA, trying to utilize the API so I can listen for events. I have implemented as directed in the documentation, but, have not been able to see anything but 'undefined' from the getPlayer() call in CPresentationLoader. The presentation loads and plays, but the tryToInitPlayer() in CPresentationLoader only ever gets 'undefined' when it attempts to getPlayer().

My implementation looks like this:

I have a main.fla that compiles:

Code:
import fsplayer.api.CPresentationLoader;
import MyPlayerListener;

System.security.allowDomain("*");

trace("main.as");

var playerListener:MyPlayerListener = new MyPlayerListener();
var presentation_mc:MovieClip = this.createEmptyMovieClip("presentation", 1);

var loader:CPresentationLoader = new CPresentationLoader();
loader.setPlayerListener(playerListener);
loader.loadClip("av.swf", presentation_mc);


MyPlayerListener has:
Code:
function onPlayerInit(player:IPlayer):Void
   {
      trace("MyPlayerListener.onPlayerInit");
      playbackListener = new MyPlaybackListener();
      player.getPlaybackController().addListener(playbackListener);
   }


Please let me know what else I can tell you that will help diagnose. Thank you!
Chris


Profile profile test

Posted: Mon Mar 09, 2009 3:51 am   Post subject: getPlayer() returns undefined

hello,
I am a developer in Boston, MA USA, trying to utilize the API so I can listen for events. I have implemented as directed in the documentation, but, have not been able to see anything but 'undefined' from the getPlayer() call in CPresentationLoader. The presentation loads and plays, but the tryToInitPlayer() in CPresentationLoader only ever gets 'undefined' when it attempts to getPlayer().

My implementation looks like this:

I have a main.fla that compiles:

Code:
import fsplayer.api.CPresentationLoader;
import MyPlayerListener;

System.security.allowDomain("*");

trace("main.as");

var playerListener:MyPlayerListener = new MyPlayerListener();
var presentation_mc:MovieClip = this.createEmptyMovieClip("presentation", 1);

var loader:CPresentationLoader = new CPresentationLoader();
loader.setPlayerListener(playerListener);
loader.loadClip("av.swf", presentation_mc);


MyPlayerListener has:
Code:
function onPlayerInit(player:IPlayer):Void
   {
      trace("MyPlayerListener.onPlayerInit");
      playbackListener = new MyPlaybackListener();
      player.getPlaybackController().addListener(playbackListener);
   }


Please let me know what else I can tell you that will help diagnose. Thank you!
Chris


Profile profile test

Posted: Tue Mar 10, 2009 3:19 pm   Post subject:

The piece of code you submitted looks correct. Please, send the whole code listing to our Support Team at support@ispringsolutions.com and specify the product and version you use.

Please notice that ActionScript API is provided by iSpring Presenter while it's not supported in iSpring Pro.


Profile profile test
Display posts from previous:  Sort by  

  


Who is online
Who is online In total there are 7 users online :: 1 registered, 0 hidden and 6 guests (based on users active over the past 5 minutes)
Most users ever online was 108 on Thu Nov 21, 2013 3:41 pm

Registered users: Bing [Bot]


cron