Using Communication Components > Using the SimpleConnect component |
![]() ![]() ![]() |
Using the SimpleConnect component
When you create applications using communication components, you usually add several components, and each one needs to establish a connection to the server. You can use the same network connection instance and connect all the movie clips in your application to the server. The SimpleConnect component handles all your communication objects' connections. In addition, SimpleConnect provides an interface for users to log in to your application.
The following example uses the com_test application to show how SimpleConnect works. The PeopleList component does not use a NetConnection object but communicates with the server using the SimpleConnect connection. Besides making your code more efficient by managing the server connections, SimpleConnect also reduces the amount of ActionScript you need to provide. In the example, SimpleConnect handles the connection to the server and associates the PeopleList component to that connection, which eliminates the need for ActionScript. Instead of hard-coding the user name into the nc.connect
call, you provide it at runtime.
To connect using the SimpleConnect component:
1 |
Make sure that Flash Communication Server is running. |
2 |
Create a directory in the Flash Communication Server MX applications directory, and name it com_test_simcon. |
3 |
Create a new file in com_test_simcon, and name it main.asc. Add the following line of code to load the components.asc file: |
load("components.asc"); |
|
Note: Alternatively, you can name your main ASC file com_test_simcon.asc. |
|
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 PeopleList component onto the Stage. |
6 |
In the Property inspector, name this instance of the PeopleList component |
7 |
To set up a connection to the Flash Communication Server, drag the SimpleConnect component onto the Stage. |
8 |
In the Property inspector, provide the following two parameters: |
![]() |
In the Application Directory text box, type |
Note: If your Flash Communication Server is not running on |
|
![]() |
Double-click the Communication Components text box. In the Values dialog box that appears, click the plus sign (+), type |
By providing this value, the SimpleConnect component handles the connection for the PeopleList component. When the SimpleConnect component successfully connects to the server, the PeopleList component automatically connects to the server. |
|
9 |
Save and publish this test file as com_test_simcon.swf. |
10 |
Open the SWF file, or in the Flash MX authoring environment, select Control > Test Movie. Log in with any user name. |
The user name you entered appears in the PeopleList component, as shown in the following figure. |
The SimpleConnect component provides a login interface. To increase the list of active users, open multiple instances of this application and enter a new user name for each instance.
Adding the SimpleConnect component to the first example of com_test might seem excessive because you simply dragged the PeopleList component onto the Stage, named it peopleList_mc, and added the following code:
nc = new NetConnection(); nc.onStatus = function(info) { trace(info.code); } peopleList_mc.close(); // optional, cleanup call nc.connect("rtmp:/com_test","Jane"); peopleList_mc.connect(nc);
The SimpleConnect component, however, is recommended and is convenient to use as your application grows. For each new communication component that you add, simply go to the Property inspector of the SimpleConnect component, double-click the Communication Components text box, and add the instance name of the new component.
![]() ![]() ![]() |