Using Communication Components > ConnectionLight component > Using the ConnectionLight component

 

Using the ConnectionLight component

This simple, useful component can be used in any application. It is a standard component for all your communication applications.

The ConnectionLight component is simple to use. Drag it onto the Stage and make sure components.asc is loaded in the server script. If you use this component with the SimpleConnect component, no other steps are necessary. Without the SimpleConnect component, you need to add the following line of client-side ActionScript:

light_mc.connect(nc);

In this ActionScript, light_mc is the instance name of the light that is being dragged into the movie, and nc is a NetConnection object.

 
To use the component in your application:

1

Make sure Flash Communication Server is running.

2

Create a directory in the Flash Communication Server MX applications directory, and name it connect_test.

3

Create a file named main.asc in the connect_test directory with the following code:

load("components.asc");

Note: You can also copy the main.asc file from another application directory to this application's directory.

4

In Flash MX, if you do not see the Communication Components panel, select Window > Components and then select Communication Components from the Components pop-up menu.

5

From the Components panel, drag the ConnectionLight component onto the Stage. In the Property inspector, name this instance light_mc. For additional parameters, see ConnectionLight component Property inspector.

6

To connect to the server, select the first keyframe in the Timeline, and in the Actions panel for the frame, provide the following code:

nc=new NetConnection();
nc.connect("rtmp:/connect_test");

7

Use the nc NetConnection instance to connect the light_mc movie clip to the server, as shown in the following example:

light_mc.connect(nc);

8

Save and publish this test file as connect_test.swf.

9

Open the SWF file in the connect_test directory or, in the Flash MX authoring environment, select Control > Test Movie. Click the green button.

You should see your connection values, as shown in the following figure.