Skip to main content
Participant
September 6, 2011
Question

HelloWorld Help Needed

  • September 6, 2011
  • 1 reply
  • 909 views

Hi Adobe Community,

I'm writing because I need some assistance with the HelloWorld example in the FMS 4 documentation.

My setup is as follows all on a local network:

Server

---------

Flash Media Server 4

Apache 2.2 (used FMS installer to set this up)

CentOS 5.3

Firewall Disabled (for simplicity at the moment)

Dev Machine

--------

Windows 7 Home Premium

Flash CS5

I installed FMS 4 just fine. I can reach the Administrator console, view the index.html, play the videos etc.

I created a folder called HelloWorld under the installpath/applications directory. I placed my HelloWorld.asc file as built and instructed by the documentation.

On the developement machine I have my HelloWorld.fla + HelloWorld.as script in the same directory.

I set the connection line HelloWorld.as to... :

nc.connect("rtmp://192.168.1.4/HelloWorld");


This way it would point out to the FMS server and I get the following from trace() after testing (aka building the swf):

Connecting...
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Connect.Failed
     at HelloWorld/connectHandler()

I found on here searching around that the following line needed to be added to HelloWorld.as:

import flash.events.NetStatusEvent;

Can an expert please assist me? Any responses are better than no response

Best,

AmarettoSlim

-----

Here is HelloWorld.as

/*
* (C) Copyright 2010 Adobe Systems Incorporated. All Rights Reserved.
*
* NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the
* terms of the Adobe license agreement accompanying it.  If you have received this file from a
* source other than Adobe, then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
* THIS CODE AND INFORMATION IS PROVIDED "AS-IS" WITHOUT WARRANTY OF
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
*  THIS CODE IS NOT SUPPORTED BY Adobe Systems Incorporated.
*
*/

package {

     import flash.display.MovieClip;
     import flash.net.Responder;
     import flash.net.NetConnection;
     import flash.events.NetStatusEvent;
     import flash.events.MouseEvent;


     public class HelloWorld extends MovieClip {

       // Represents a network connection.
       private var nc:NetConnection;

       // Responder for call to server's serverHelloMsg -- see onReply() below.
       private var myResponder:Responder = new Responder(onReply);


       // Constructor.
       public function HelloWorld() {
               // Set display values.
               textLbl.text = "";
               connectBtn.label = "Connect";

               // Register a listener for mouse clicks on the button.
               connectBtn.addEventListener(MouseEvent.CLICK, connectHandler);
        }


      // When button is pressed, connect to or disconnect from the server.
      public function connectHandler(event:MouseEvent):void {
               if (connectBtn.label == "Connect") {
                    trace("Connecting...");

                    nc = new NetConnection();

                    // Connect to the server.
                    nc.connect("rtmp://192.168.1.4/HelloWorld");

                    // Call the server's client function serverHelloMsg, in HelloWorld.asc.
                    nc.call("serverHelloMsg", myResponder, "World");

                    connectBtn.label = "Disconnect";

               } else {
                    trace("Disconnecting...");

                    // Close the connection.
                    nc.close();

                    connectBtn.label = "Connect";
                    textLbl.text = "";
               }
      }

      // Responder function for nc.call() in connectHandler().
      private function onReply(result:Object):void {
            trace("onReply received value: " + result);
               textLbl.text = String(result);
     }

   }
}

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    September 6, 2011

    I think problem here is that you have not defined at netstatus handler to capture NetConnection Status events. And looks like you are not able to reach FMS machine - either machine is unreachable or FMS is down as i see you are getting NetConnection.Connect.Failed.

    Participant
    September 7, 2011

    Thank you! :-)

    I added the following:

    // Add NetStatus Handler...
    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    // NetStatusHandler Function
          private function netStatusHandler(event:NetStatusEvent):void {
                switch (event.info.code) {
                    case "NetConnection.Connect.Success":
                        trace("Successful")
                        break;
                    case "NetConnection.Connect.Failed":
                             trace("Failed")
                             break;
                }
            }

    and have resolved the status handling...

    Are there any good steps to ensure that RTMP is working from my dev box to the development server. They are on the same LAN, and the destination server has no firewall on it.

    Looking forward to your response and thanks again for this previous helpful one!

    -AmarettoSlim

    Participant
    September 7, 2011

    I checked edge.00.log and don't see RTMP showing... rather RTMFP... I changed my nc.connect() to use rtmfp instead and it looks like it hangs now and finally shows a failure in the output of my test SWF....

    How would I get RTMP to be listed as listening in the edge log?

    AmarettoSlim


    package {

         import flash.display.MovieClip;
         import flash.net.Responder;
         import flash.net.NetConnection;
         import flash.events.NetStatusEvent;
         import flash.events.MouseEvent;


         public class HelloWorld extends MovieClip {

           // Represents a network connection.
           private var nc:NetConnection;

           // Responder for call to server's serverHelloMsg -- see onReply() below.
           private var myResponder:Responder = new Responder(onReply);


           // Constructor.
           public function HelloWorld() {
                   // Set display values.
                   textLbl.text = "";
                   connectBtn.label = "Connect";

                   // Register a listener for mouse clicks on the button.
                   connectBtn.addEventListener(MouseEvent.CLICK, connectHandler);
            }


          // When button is pressed, connect to or disconnect from the server.
          public function connectHandler(event:MouseEvent):void {
                   if (connectBtn.label == "Connect") {
                        trace("Connecting...");

                        nc = new NetConnection();
                        
                        // Add NetStatus Handler...
                        nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

                        // Connect to the server.
                        nc.connect("rtmfp://192.168.1.4:1935/HelloWorld");

                        // Call the server's client function serverHelloMsg, in HelloWorld.asc.
                        nc.call("serverHelloMsg", myResponder, "World");

                        connectBtn.label = "Disconnect";

                   } else {
                        trace("Disconnecting...");

                        // Close the connection.
                        nc.close();

                        connectBtn.label = "Connect";
                        textLbl.text = "";
                   }
          }

          // Responder function for nc.call() in connectHandler().
          private function onReply(result:Object):void {
                trace("onReply received value: " + result);
                   textLbl.text = String(result);
         }
         
         
          // NetStatusHandler Function
          private function netStatusHandler(event:NetStatusEvent):void {
                switch (event.info.code) {
                    case "NetConnection.Connect.Success":
                        trace("Successful")
                        break;
                    case "NetConnection.Connect.Failed":
                             trace("Failed " + event.info.code)
                             break;
                        case "NetConnection.Connect.Closed":
                             trace(event.info.code)
                             break;
                        case "NetConnection.Connect.Rejected":
                             trace(event.info.code)
                             break;
                        case "NetConnection.Connect.IdleTimeout":
                             trace(event.info.code)
                             break;
                }
            }

       }
    }