There are situations where it is necessary to call a server side method on FMS. Some CDNs, for example Limelight, used to or maybe still do require you to call the FCSubscribe method in order to request a live stream. This send a signals to the Edge server to pull the live stream from the Origin server if it is not already being delivered to that Edge. While this delivery method and stream setup routine is being phased out across most CDNs I thought it may be useful to post a (slightly hackish) workaround to make this setup work with the FLVPlayback component.
The problem with the FLVPlayback component is that there is no obvious, simple way to obtain a reference to the NetConnection Object it uses under the hood. Sure, the ncMgr.getNetConnection let's you grab it but only once the connection is established, and while you can implement a custom NCManager class, this is not trivial and after all a NetConnection is being maintained already by the component, so why reinvent the wheel?

The following code is clearly not something I am proud of, but it worked at the time when I needed it. It was used to get a live stream working with the FLVPlayback component streaming from Limelight about a year or two ago.

view plain
1// listen to player events and kill manual connection once we're streaming
2    player.addEventListener("playing", playListener);
3    player.addEventListener("stateChange", stateListener);
4    player.addEventListener("ready", readyListener);
5        
6/* this is the hack: check once every frame if the NC has been defined inside the FLVPlayback component */    
7    this.onEnterFrame = function()
8    {
9        if (player.ncMgr.getNetConnection() != undefined)
10        {
11            this.onEnterFrame = null;
12            delete this.onEnterFrame;
13            trace("got NC");
14            //subscribe(streamName);
15        }
16    }
17            
18    var nc:NetConnection;
19    var serverName:String = "server.llnwd.net";
20    var appName:String = "account_name/_definst_";
21    var streamName:String = "live";
22    
23    var source_Str = "rtmp://" + serverName + "/" + appName + "/" + streamName;
24    
25    // start up by setting the contentPath (now called source in newer versions of the component)
26    
27player.contentPath = source_Str;    
28    
29    function subscribe(name:String)
30    {
31        nc = player.ncMgr.getNetConnection();
32            
33        nc.onFCSubscribe = function(info:Object)
34        {
35            trace("onFCSubscribe: " + info.code);
36            clearInterval(int_id);
37
38            if (info.code == "NetStream.Play.StreamNotFound")
39            {
40                // handle error, retry after a few secs or similar
41            }
42            else if (info.code == "NetStream.Play.Start")
43            {
44                // we're successfully subscribed
45            }
46            else
47            {
48                // handle error
49            }
50        };
51            
52        
53// not used right now
54        
55nc.onFCUnsubscribe = function(info:Object)
56        {
57        }
58            
59        trace("subscribing to " + name);
60        nc.call("FCSubscribe",null,name);
61    }
62    
63    // can be used to unsubscribe from stream
64    
65function unsubscribe(name:String)
66    {
67        nc.call("FCUnsubscribe",null,name);
68    }

Hopefully this is helpful to someone.