Skip to main content
Participating Frequently
September 2, 2010
Answered

How can I display a message to the client connecting?

  • September 2, 2010
  • 2 replies
  • 1326 views

Hello,

I am fairly new to FMS and really am trying to learn about it. My question is simple I hope;

I would like a message to pop up to a client when they connect that the max users has been reached. I have it set for 5 users and so I would like when the 6th user tries to connect to watch the video, a little box will pop up and say "Sorry, Max users has been reached. Please try again in a few minutes."

I was able to develop something and get it output through trace commands by following a tutorial I saw online, but I could never get any sort of message box I built to pop up.

Please help anyone??

    This topic has been closed for replies.
    Correct answer amit_kr

    I hope you don't mind that this is actually going to continue

    I get the following ArgumentError after following your code and digging into the flash.media Beta website.

    ArgumentError: Error #2126: NetConnection object must be connected.

    It seems like this is way easier in AS2


    Your code was not correct try this one.

    var ns:NetStream;

    var nc:NetConnection = new NetConnection();

    nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

    nc.connect("rtmp://fms");

    function onNetStatus(event:NetStatusEvent):void {

      trace(event.info.code);

      switch (event.info.code)

      {

      case "NetConnection.Connect.Success":

      ns = new NetStream(nc);
      ns.setBufferTime(2);

      myVideo.attachVideo(ns);

      ns.play("mp4:BYN_e06_1.f4v");

      status_txt.text = "You are: Connected";

      where_txt.text = "From:"+Num;

      break;

    default :

      status_txt.text = "Sorry, the maxmimum users has been reached. Please try again.";

      break;

      }

    I would suggest you to go through the documentation which comes with FMS as there are lot of examples on how to create netconnection and netstream and then stream videos. It will really help you.

    Regards,

    Amit

    2 replies

    Greekie10Author
    Participating Frequently
    September 3, 2010

    I found a working code for AS2 if anyone is interested -

    nc.onStatus = function(ncObj:Object) {

    trace(ncObj.code);

    if (ncObj.code == "NetConnection.Connect.Success") {

    ns.setBufferTime(2);

    myVideo.attachVideo(ns);

    ns.play("mp4:BYN_e06_1.f4v");

    status_txt.text = "You are: Connected";

    where_txt.text = "From:"+Num;

    } else if (ncObj.code != "NetConnection.Connect.Success"){

    status_txt.text = "Sorry, the maxmimum users has been reached. Please try again.";

    }

    };

    If anyone can help me translate this into AS3 I would be forever grateful

    Adobe Employee
    September 3, 2010

    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

    function onNetStatus(event:NetStatusEvent):void {
      trace(event.info.code);
      switch (event.info.code)
      {
      case "NetConnection.Connect.Success":
      ns.setBufferTime(2);
      myVideo.attachVideo(ns);
      ns.play("mp4:BYN_e06_1.f4v");
      status_txt.text = "You are: Connected";
      where_txt.text = "From:"+Num;
      break;
    default :
      status_txt.text = "Sorry, the maxmimum users has been reached. Please try again.";
      break;
      }
    }

    Enjoy!!

    Amit

    Greekie10Author
    Participating Frequently
    September 3, 2010

    Thanks Amit for your help so far. It seems like something is wrong still as I get "Call to a possibly undefined method" for setBuffer and attachVideo.

    Here is the code I am using again now with AS3

    var nc:NetConnection = new NetConnection();

    nc.connect("rtmp://fms");

    var ns:NetStream = new NetStream(nc);

    nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

    function onNetStatus(event:NetStatusEvent):void {

      trace(event.info.code);

      switch (event.info.code)

      {

      case "NetConnection.Connect.Success":

      ns.setBufferTime(2);

      myVideo.attachVideo(ns);

      ns.play("mp4:BYN_e06_1.f4v");

      status_txt.text = "You are: Connected";

      where_txt.text = "From:"+Num;

      break;

    default :

      status_txt.text = "Sorry, the maxmimum users has been reached. Please try again.";

      break;

      }

    }

    Any ideas on this one?

    Petro_O__Bochan
    Inspiring
    September 2, 2010

    Your setup mimics almost 100% to the excellent tutorial from the Prog FlashCom book. I suggest that you read the first chapter of it, in particular pp.19-30. Your "case" is described on p.26.

    http://oreilly.com/catalog/progflashcs/chapter/ch01.pdf