2.3. Creating an Application that Monitorsa Connection
Now that you have a basic overview of the
communication components, let's see how to use them
to create an application. We'll build a Flash movie
that connects to a FlashCom application using the SimpleConnect and
ConnectionLight components. The SimpleConnect component will specify
the URI of the FlashCom application, and the ConnectionLight instance
will display the statistics of the connection.
Make sure you have installed the latest communication components for
Flash MX or Flash MX 2004, as cited at the beginning of the chapter,
before you begin this exercise.
2.3.1. Making the FlashCom Application Folder
First, set up the basic_app application as
follows:
On the computer running FlashCom Server, browse to the
applications folder. Create a new folder named
basic_app at this location. In Flash Pro or your preferred text editor, create a new ActionScript
Communication document. Add the following code to the document: load("components.asc");
This line of code instructs the FlashCom application to load the
components.asc document from its
scriptlib folder, which in turn loads the
.asc files for each communication component. Save the text document as main.asc in the
basic_app folder you created in Step 1.
Your FlashCom application is now prepared to use communication
components.
2.3.2. Building the Flash Client Movie
Now
that
the server-side .asc code is complete, we have
to create the client (.swf) movie:
Create a new Flash document
(File New). Save this
document as component_connection.fla. Rename Layer 1 to
connect_mc. This layer will be used to hold an
instance of the SimpleConnect component. Open the Components panel (Ctrl-F7 or Cmd-F7), and
open the Communications Components set as shown in Figure 2-1. Drag an instance of the SimpleConnect
component to the first frame of the connect_mc
layer. Place the instance near the top-left corner of the Stage. Select the new instance, and use the Properties panel to give it the
instance name connect_mc. In the Parameters tab of
the Properties panel, enter the path to the
basic_app FlashCom application in the
Application Directory field. For example, if you are using the
Developer edition of FlashCom on the same machine as your web server,
enter rtmp:/basic_app. Otherwise, specify the
full RTMP path to your FlashCom Server and application, such as
rtmp://fcs.mydomain.com/basic_app. Create a new layer in the Timeline panel, and name the layer
light_mc. On frame 1 of this layer, drag an
instance of the ConnectionLight component from the Components panel
to the Stage. Place the instance to the right of the
connect_mc instance. In the Properties panel, name
this instance light_mc, and leave the default
values for the component's parameters. Select the connect_mc instance, and in the
Properties panel, click the Communication Components field. In the
Values list, click the + button and enter
light_mc in the field labeled 0, as shown in
Figure 2-19. Click OK to close the dialog box. By
specifying the light_mc
instance's name, the SimpleConnect instance knows to
notify it of the connection to the basic_app
application.
 Save your document, and test the movie
(Control Test Movie). As
soon as the Flash movie connects to the
basic_app application, the ConnectionLight
instance turns green. If the connection fails, the light turns red.
If the connection latency threshold is reached, the light turns
yellow.
 |