Section 2.6. Forgoing the SimpleConnect Component

2.6. Forgoing the SimpleConnect Component

If you are building your own custom FlashCom applications and Flash client movies, you'll likely have your own login systems and user interface elements, complete with username and password fields. In such cases, you'll need to connect communication components to your FlashCom applications without the use of the SimpleConnect component. In this last section, you will learn how to enable the ConnectionLight component for an application by using your own custom client-side ActionScript code.

First, create a new server-side application. On the computer running the FlashCom Server, browse to the applications folder and create a new folder named test_app at this location. In the next section, you will create a client-side NetConnection object that connects to this application space.

2.6.1. Building the Client Movie

  1. Create a new Flash document (File New), and save the document as no_simpleconnect.fla .

  2. Rename Layer 1 to light_mc . On frame 1 of this layer, drag an instance of the ConnectionLight component from the Components panel to the Stage. Name the instance light_mc using the Properties panel.

  3. Create a new layer, and name it actions . Place this layer above the light_mc layer.

  4. Select the first frame of the actions layer, and open the Actions panel (F9). Add the following code:

     app_nc = new NetConnection(  ); app_nc.onStatus = function (info) {   trace("app_nc: info.code = " + info.code);   if (this.initLight == null) {     light_mc.connect(this);     this.initLight = true;   } }; app_nc.connect("rtmp:/test_app"); 

  5. Here, you create a new NetConnection object that invokes connect( ) on light_mc when the onStatus( ) event handler is invoked. An internal property named initLight is used to track whether the light_mc instance's connect( ) method has been invoked, as the onStatus( ) handler will likely execute more than once during the session of the application. You may need to alter the RTMP URI to include the full domain name of your FlashCom Server.

  6. Save your Flash document and test it. When the Flash movie loads, you should see the trace( ) message from the app_nc.onStatus( ) handler. If the connection was successful, the light_mc instance's status color should turn green. If the connection failed, the indicator will turn red.

You can continue to modify this example by adding more communication components. As you add component instances, you can simplify the code of the onStatus( ) handler by creating an array to store object references to your component instances. For example, the following code creates a component_array object that connects three communication components to the app_nc connection:

 app_nc.onStatus = function (info) {   trace("app_nc: info.code = " + info.code);   if (this.initComponents == null) {     var components_array = [light_mc, bandwidth_mc, av_1_mc];     for (var i in components_array) {       components_array[i].connect(this);     }   this.initComponents = true;   } }; 



Programming Flash Communication Server
Programming Flash Communication Server
ISBN: 0596005040
EAN: 2147483647
Year: 2003
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net