To develop the FCS Application, you must install Macromedia Flash MX, Flash Communication Server, and the recently released Flash Player. If the app needs to capture video or audio, you also need to install the microphone and camera. In addition, if the application needs to write server scripts like Macromedia dreamweavermx, a javascript editor supporting UTF-8 encoding will also need to be installed.
Next let's take a look at how to set up the development environment of flashcommunicationserver, how to deploy your application, and finally let's create a simple application that connects to the server. Next let's take a look at how to set up the development environment of flashcommunicationserver, how to deploy your application, and finally let's create a simple application that connects to the server.
The following knowledge is required before you start to develop the FCS Application.
Is the FCS server running? To publish or test an application, the FCS server must run.
Specify the server Uri. If Flash MX and FCS are installed on the same computer, you can specify the URI to connect to the server as follows:
New_nc.connect ("rtmp:/doc_record/room_01 ");
Otherwise, you need to specify the actual server uri (for example, the server runs on myserver.mydomain.com). You can specify the FCS connection as follows:
New_nc.connect ("rtmp: // myserver.mydomain.com/doc_record/room_01 ");
Note: It is determined that rtmp is followed by a double slash. A single slash can be used only when the SWF file and the FCS are on the same computer.
Specify the publishing format. Flashmx can publish an application as a SwF or HTML file. Select File> release settings to specify the release format at the time of release.
Write client as code. Unless otherwise stated, the client as code should be written on a layer at the first frame of the FLA file, rather than a separate object.
Write the server segment as code. If the application has a server segment code, it should be placed in the server segment script file. This file is usually named main. ASC (or a file name similar to registered_app_name.asc ). Use dwmx or other JavaScript editors to write the server segment code. Note that the server segment code is also case sensitive.
Load component. ASC. If the communication component is used in the application, you must load comatrix onents. ASC in the scriptlib directory.
So how to load the file? First, create a server segment script file and save it as a proper file name (such as main. ASC). Then add the following code at the top of the file:
Load ("components. ASC ");
Tip: You can copy the component files of an application to the application directory.
Initialize client code: Add the following code to the first line of each FLA file:
# Include "netdebug."
It allows us to use the netconnection debugger to track the use of streams or shared objects in applications. You can delete this line of code at any time.
Respect user privacy. At the beginning of recording or broadcasting any image or sound, you should be permitted by the image/sound owner.
Monitor the running program: If you are the server administrator, you can view the program details, such as log information and so value, during the running of the program. Open the communictaion app Inspector panel in flashmx, connect to the FCS, select the application instance to be viewed, and select View Detail.
Next we will understand the development process of the FCS Application by actually creating a FCS Application.
The following table lists the tasks required to develop the application:
1. Name the application and register the application on the server. For example, if the application name is my_app, create a directory named my_app under the application directory of the FCS. my_app is the name of the application registered on the FCS, the my_app directory is the registered application directory.
2. In flashmx, create a FLA file that should contain a connection to the URI of the newly registered application my_app. Follow these steps to create a new netconnection.
My_nc: netconnection = new netconnection ();
My_nc.connect ("rtmp: // mydomain/my_app ");
3. Save the FLA file. You can save it anywhere. When deploying an application, you only need the SWF file released by Fla.
4. if it includes the server-side as, you need to put the script file in the my_app directory on the FCS server or in the/scripts directory of the directory. This file should be named main. ASC or my_app.asc.
5. Publish the SWF file. SWF files do not need to be placed on the FCS server. You can store the file in any place that customers can access. For example, you can send the file to your customers by email.
Or, there are more steps for your application, but in any case, the above steps are required for any FC application.
TIPS: Macromedia recommends naming applications with lowercase letters that do not contain spaces, so that your applications can be used on any platform (Windows/Linux/MACOs.
The following describes how to make the data of the FCS Application available to the server and how to run the application instance.
Save server files and client files
The default location of the Application Server File is in C:/program files/Macromedia/Flash Communication Server MX/applications on Windows. Generally, the FCS Application should be placed in a subdirectory with the same name as the application under this directory. Place the application data-ASC file, saved stream file (FLV), and remote so file (FSO) in this subdirectory ).
As for client files (SWFs and htmls), they can be stored anywhere (usually on Web servers). For FLA files, they are only required when developing applications, this file should be excluded during release-it is best to put it in a safe place.
During development, all these files can be put in one piece. When publishing an application, ASC, FSO, and FLV files must be stored in the application directory on the server, and only SWF and HTML files must be distributed to the customer.
In any case, you must create a directory with the same name for the application under the applications directory (even if the application does not have a server-side script, because the FCS needs to store stream files or shared object files in this directory), when the client sends netconnection. you can find the application when running the connect command.
In the following example, we assume that the user calls the chat_app application.
Netconnection. Connect ("rtmp: // mydomain/chat_app ");
Note: the extension of the server-side script file can also be. js. In this case, you can place the server-side script file in the scripts directory under the application directory.
Use Application Instances
The instance of the FCS Application is similar to the session in the ASP application. The application runs by creating an application instance. When a client connects to an application, it is actually an instance connected to the application. For example, the client connects to an application named chat_app:
NC. Connect ("rtmp: // mydomain.com/chat_app ");
Because no instance is specified, the client actually connects to a default instance named _ definst.
Of course, you can also connect the client to the specified instance:
NC. Connect ("rtmp: // mydomain.com/chat_app/instance1 ");
The instance to which the client connects is named instance1.
By specifying the Instance name, the client can "group activity" under the application ". In chat programs, different customers are divided into different rooms based on different themes, as shown in the following example:
My_nc.connect ("rtmp: // mydomain/chatapp/room_01 ");
My_nc.connect ("rtmp: // mydomain/chatapp/room_02 ");
Each application instance name is unique. Unlike the application where the instance is located, you do not need to define your own directory on the server to obtain an instance separately. However, application resources, such as streams and shared objects, are independent of all instances, and stored in your own directory (the application can set the directory for storing streams and so.
Another reason for using the instance is that it can avoid conflicts between applications when creating streams or so. In the preceding example, the streams and so created by room_01 are different from the stream and so created by room_2, and vice versa, even if both instances run in the chatapp application at the same time.
For example, although the following code in the support application creates two so statements with the same name as customertinfo, different instances of the support application only access their own customerinfo objects. Similarly, the customerinfo data in session1 and session2 is different.
First_nc = new netconnection ();
First_nc.connect ("myserver.mydomain.com/support/session1 ");
First_so = export dobject. getremote ("customerinfo", first_nc.uri, false );
First_so.connect (first_nc.uri );
Second_nc = new netconnection ();
Second_nc.connect ("myserver.mydomain.com/support/session2 ");
Second_so = export dobject. getremote ("customerinfo", second_nc.uri, false );
Second_so.connect (second_nc.uri );
In fact, you can use any string to name an instance in the application. An example of dynamically creating an Instance name is provided in the course provided by the FCS. For more information about the code, see tutorial_textchat.fla in the tutorial_textchat directory.
You can adjust the settings related to the application instance. Modify the application. xml file, such as the instance timeout setting. In the vhost. xml file, you can set the number of customers that can connect to applications on this virtual host.
In addition to the file types (FLA, SwF, and SWD) created by Flash MX, the following file types are used or created by the FC:
ASC and JS files: server-side script files created by the user and provided to the FCS, such as components. ASC.
The/scriptlib Directory provides a script library that contains components and server scripts used by flash remoting services. When you use the FCS together with comatrix ontent or flash remoting services, please include or load it from the/scriptlib directory) appropriate scripts are included in the server-side script file of the application. The path of the/scriptlib directory is specified by the <scriptlibpath> label in the application. xml configuration file.
FLV and idx files: the files that record streams (streams) and the index files (idx) associated with FLV ). When the server starts recording the stream, it creates a subdirectory for the specified application instance and stores the FLV and idx files in this directory, for example,/applications/chat_app/streams/instance2
Sol, SOR, and FSO files: So files that record the client status, server status, or both statuses. The location of so file storage depends on the different categories of So objects.