Skip to main content
Participant
August 24, 2009
Answered

FLVplayblack

  • August 24, 2009
  • 2 replies
  • 1061 views

hi,

i'm trying to use this code but i can't to access to function nc.onFCSubscribe. how can i do it? someone know about that?¿ the original site of the code is http://www.flashcomguru.com/index.cfm/2009/8/14/flvplayback-obtain-nc-reference

thanks.

// listen to player events and kill manual connection once we're streaming
    player.addEventListener("playing", playListener);
    player.addEventListener("stateChange", stateListener);
    player.addEventListener("ready", readyListener);
      
/* this is the hack: check once every frame if the NC has been defined inside the FLVPlayback component */  
    this.onEnterFrame = function()
    {
       if (player.ncMgr.getNetConnection() != undefined)
       {
          this.onEnterFrame = null;
          delete this.onEnterFrame;
          trace("got NC");

         subscribe(streamName);
       }
    }
         
    var nc:NetConnection;
    var serverName:String = "server.llnwd.net";
    var appName:String = "account_name/_definst_";
    var streamName:String = "live";
   
    var source_Str = "rtmp://" + serverName + "/" + appName + "/" + streamName;
   
   // start up by setting the contentPath (now called source in newer versions of the component)   
player.contentPath = source_Str;  
   
    function subscribe(name:String)
    {
       nc = player.ncMgr.getNetConnection();
         
       nc.onFCSubscribe = function(info:Object)
       {
          trace("onFCSubscribe: " + info.code);
          clearInterval(int_id);

          if (info.code == "NetStream.Play.StreamNotFound")
          {
             // handle error, retry after a few secs or similar          }
          else if (info.code == "NetStream.Play.Start")
          {
             //  we're successfully subscribed          }
          else
          {
             // handle error          }
       };
         
      
// not used right now      
nc.onFCUnsubscribe = function(info:Object)
       {
       }
         
       trace("subscribing to " + name);
       nc.call("FCSubscribe",null,name);
    }
   
   // can be used to unsubscribe from stream   
function unsubscribe(name:String)
    {
       nc.call("FCUnsubscribe",null,name);
    }

    This topic has been closed for replies.
    Correct answer

    Are you using actionscript 2 or 3? If you're using AS3, I the problem is that you're trying to define methods on the NetConnection. You can't do that, as the NetConnection class is not dynamic.

    Instead, you'll need to use the client property of the Netconnection

    nc = player.ncMgr.getNetConnection();

    nc.client = this;

    function onFCSubscribe(info){

        // function body

    }

    I don't use the FLVPlayback component, so I don't know if it already defines itself as the NetConnection's client or not.

    2 replies

    Participant
    August 25, 2009

    Also, check out the NetConnection docs in the ActionScript 3.0 reference. The example at the bottom of the page demonstrates use of the client property:

    http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/NetConnection.html

    Correct answer
    August 24, 2009

    Are you using actionscript 2 or 3? If you're using AS3, I the problem is that you're trying to define methods on the NetConnection. You can't do that, as the NetConnection class is not dynamic.

    Instead, you'll need to use the client property of the Netconnection

    nc = player.ncMgr.getNetConnection();

    nc.client = this;

    function onFCSubscribe(info){

        // function body

    }

    I don't use the FLVPlayback component, so I don't know if it already defines itself as the NetConnection's client or not.