There's a way to embed Flowplayer into another swf file using pure AS3, but it's not that easy. Here's the steps to get it working. I have received this info from a friend and this is him speaking:
- I load FP using the Loader class
- I inject the config when it's first loaded
- I create a plugin that will hold a static reference to the player when the player is loaded
- I wait for the plugin to be loaded, and get the player's reference
- I handle the resize of the player
Here's a code chunk that I used to load FP
In order to use the Flowplayer object (play, pause, ..), you have to create a FP plugin that will only hold a static reference to the FP object, with a getter.
My waitForPlayer method looks like :
Moreover, you might want to handle the resize of the player. By default, it will take the whole Stage's space. If you want to change its size, you have to specify the size of the Launcher class and call the draw() method of the Panel class. I did a little recursive function that will look for the Launcher & Panel DisplayObjects in the main Sprite children.
- I load FP using the Loader class
- I inject the config when it's first loaded
- I create a plugin that will hold a static reference to the player when the player is loaded
- I wait for the plugin to be loaded, and get the player's reference
- I handle the resize of the player
Here's a code chunk that I used to load FP
var context:LoaderContext = new LoaderContext();
context.securityDomain = SecurityDomain.currentDomain;
context.applicationDomain = ApplicationDomain.currentDomain;
Security.allowDomain("*");
Security.allowInsecureDomain("*");
var resourceLoader:Loader = new Loader();
var resourceRequest:URLRequest = new URLRequest(playerURL); // player url is FP's url
resourceLoader.contentLoaderInfo.addEventListener(Event.INIT, function(event:Event):void {
log.debug("Player INIT event");
var preloader:* = event.currentTarget.content;
preloader.injectedConfig = playerConfiguration; // playerConfiguration is a json string
_parent.addChild(preloader); // _parent is my main Sprite
});
resourceLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event):void {
log.debug("Player COMPLETE event");
var progressEvent:ProgressEvent = new ProgressEvent(ProgressEvent.PROGRESS);
progressEvent.bytesTotal = 100;
progressEvent.bytesLoaded= 100;
// fake event to tell FP that it's loaded
event.currentTarget.content.onLoadProgress(progressEvent);
waitForPlayer();
// this function will wait for player
});
resourceLoader.load(resourceRequest, context);
In order to use the Flowplayer object (play, pause, ..), you have to create a FP plugin that will only hold a static reference to the FP object, with a getter.
My waitForPlayer method looks like :
var player:* = null;
try {
var getterClass:Class = flash.utils.getDefinitionByName('com.yourstuff.getter.Getter') as Class;
player = getterClass.getPlayer.apply(null, []);
} catch(e:Error) {
// plugin not yet loaded.
log.debug("Plugin not yet loaded", e);
}
if ( player )
{
// call a callback or whatever
}
else if ( _waitCount++ > MAX_WAIT_COUNT )
throw new Error("Unable to load player");
else
setTimeout(waitForPlayer, 100);
Moreover, you might want to handle the resize of the player. By default, it will take the whole Stage's space. If you want to change its size, you have to specify the size of the Launcher class and call the draw() method of the Panel class. I did a little recursive function that will look for the Launcher & Panel DisplayObjects in the main Sprite children.