Loading FS SWF into movie clip using MovieClipLoader
Author | Message |
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.
|
OK, read through the documentation and managed to figure it out.
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...
|
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); } } } }
|
Here is the simple class that can be used for loading FlashSpring generated presentations.
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); }
|
Thanks, excellent information!
|
hello,
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
|
hello,
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
|
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.
|
||||
|
Who is online | |
---|---|
![]() |
In total there are 12 users online :: 2 registered, 0 hidden and 10 guests (based on users active over the past 5 minutes) Most users ever online was 803 on Sat Dec 12, 2020 9:21 am Registered users: Bing [Bot], Majestic-12 [Bot] |