FCS reading note 17 application design and development
This content mainly tells some suggestions and techniques of the FCS application development process, including server compatibility, interdependence, multi-file management, bandwidth management, double byte support, uninstall, and heavy-duty applications and dynamics Access control, etc. I. Suggestions for server compatibility Use your lowercase way you are named your directory and file name Macromedia. You recommend you to name the directory and file in the Flashcom development project in your lowercase, so that you can better working between different servers. Using a relative path or absolute path connection server in the NetConnect.connect command in FCS development, you can use the absolute and relative path to connect the specified application. If your SWF file and the Flashcom server run in the same machine, you can use the relative path RTMP: / appname / instanceName instead of RTMP: //server.domain.com/appname/instancename If your development your application is in a development server, and does not use the relative path in the SWF file, move your SWF file to Product servers will bring some additional work because you have to change the URL parameters in each NetConnect.connect statement. If your SWF file is not in the same machine with the Flashcom server, you must add an absolute path, (Author Note: Of course, you can set the variable) Second, interdependence because the client and server-side ActionScript script code It is part of the application that they must work together and interdependent. One most typical example is to use the call command between the client and the server side, because the way the call may be customized by the client or server. There is an example below to explain:
01:
// ActionScript code for client FLA files
02: MY_NC =
NEW NETCONNECTION ();
03: my_nc.someclientMethod = function ()
04: {
05:
/ / Add your processing code here
06:}
07: my_nc.connect ("RTMP: // Hostname: Port / AppName");
08:
09:
/ / ActionScript code in main.asc in server-side
10: ClientObj.call ("SomeClientMethod");
The parameters passed in the server-side clientobj.call method must be a NetConnect object method that has been defined on the client, because any client needs to be called by the server to be connected to the server via the NetConnect object. Instead, you call the server-side method on the client
01:
// Client code
02: NetConnection.call ("SOMESERVERMETHOD");
03:
04:
// server-side code
05: client.prototype.someserverMethod = function ()
06: {
07:
/ / Here is processing code
08:}
09:
/ / Or use the following call mode is also effective
10: OnConnect (NewClient)
11: {
12: NewClient.SOMSERVERMETHOD = Function ()
13: {
14:
// Code
15:}
16:}
In this case, the parameter of the NetConnect.connect method must be a server-side (typically main.asc) that has defined a good method because any server-side can be called by the client must be the client's client object. . Third, use multi-file management When your application is increasing, do not try to complete all things through a single script. Divide your functions into different files, each with a certain set of functions. If you use multiple files, you can also use the included way to optimize performance, so that the same segment code does not need to be executed multiple times. The client is, for example, in the client, if you want to call my_file.as files to be called in other files in the application, just write the following code at my_file.as file: 1:
IF (_root._my_file_as ==
NULL) {
2: _Root._my_file_as = true;
3:
// all the code for myfile.as goes here
4:}
Then, in other files, include the following code: #include "my_file.as"; Note: The include instruction is executed when compiling instead of running. Some of the way the server-side server side is somewhat different because global objects are not supported at the server-side ActionScript. For example, you have to include a my_flie.asc file, and the file is still included in the following code:
1 :
IF (_my_file_asc ==
NULL) {
2: _MY_FILE_ASC = True;
3:
// all the code for myfile.asc goes here
4:}
The difference is that other files do not use the #include directive when the file contains the file, but use the LOAD instruction load ("my_file.asc"); four, using the unique entity named usual development environment is multiple users to connect to the same Server, in order to avoid data stream conflicts or shared objects, you can use unique entity names in the NetConnect.connect command. If you want to use the NetConnect debugging tool, you must contain the NetDebug.as file in the first line of the client code, (FlashCom1.5 version does not include NetDebug.as files, you can download this here) NetDebug.as file The method is not in the description of this article, and it will be restored later. 5. Forced Display Flash Settings Panel When an application attempts to access the user's camera or microphone, Flash will display the setup dialog to get allowed when you store data locally. Users can also click the right mouse button to open the setup panel. If you want to force the Settings panel, you can use the following code: // Do not use the parameter to indicate the setting panel of the user's last browse
1: system.showsettings ();
2 :
/ / Open the confidential setting panel
3: System.ShowSettings (0);
4:
/ / Open the local storage setting panel
5: System.ShowSettings (1);
6:
/ / Open the microphone setting panel
7: System.ShowSettings (2);
8 :
// Open the camera setting panel
9: System.ShowSettings (3);
For example, if your application needs to use a camera, you may need to prompt users to select Allow in the Popked Confidential Settings panel. You must use System.ShowSettings (0) 6. Bandwidth Management You can control the amount of data to each client by calculating the approximate bandwidth tolerance. There are many ways to do, a method is to config to config.xml files for flashcom server; another method is to specify the transfer rate using the NetStream.ReceiveVideo method; the third method is to set the client Camera.quality property and The server-side Client.setBandWidthlimit method. The third method will be described in detail below. The DOC_BANDWIDTH sample program comes with FCS demonstrates how to choose a different bandwidth setting. After selecting different bandwidth settings, the client's microphone and camera settings are also updated according to the user's selection, and the server-side bandwidth limit will be updated. The client's ActionScript provides a user interface to allow users to choose three different bandwidth settings: Modem, DSL, and LAN. When the user changed the bandwidth limit, the camera and microphone setting will also be updated, and there is a place where the UpdateBandWidth method will change the size of the screen according to the selection of settings. 01: _root.modem_btn.onpress = function () {
02:
// Call UpdateBandWidth to change
03:
// Camera and Mic settings and inform
04:
// the server
05: _Root.UpdateBandWidth (1);
06:}
07: _root.dsl_btn.onpress = function () {
08: _Root.UpdateBandWidth (2);
09:}
10: _Root.lan_btn.onpress = function () {
11: _Root.UpdateBandWidth (3);
12:}
In the first frame of the FLA file, you can find the following segment to initialize the camera and microphone, and play streams from the server and update the camera, the microphone settings.
01:
#include
"NetDebug.as"
02: STOP ();
03:
// Initialize Movie by getting a camera and microphone, and
04:
// Configure the initial camera and microphone settings
05: Client_cam = Camera.get ();
06: Client_cam.SetMode (150, 120, 5);
07: Client_cam.Setquality (0, 90);
08: Client_mic = microphone.get ();
09: Client_Mic.Setrate (22);
10:
// Get the stream to public and play
11:
Function getPlayStream () {
12:
// Get New Net Connection
13: Client_nc =
NEW NETCONNECTION ();
14:
// Handle Status Message
15: Client_nc.onstatus = function (info) {
16: TRACE ("Level:
" Info.Level Newline
"Code:" Info.code;
17:}
18: Client_nc.connect ("RTMP: / DOC_BANDWIDTH / ROOM_01"); 19:
// Create a stream to which to public
20: OUT_NS =
NEW NETSTREAM (Client_nc);
21: OUT_NS.AttachVideo (Client_CAM);
22: OUT_NS.ATTACHAUDIO (Client_Mic);
23: OUT_NS.PUBLISH ("Myav");
24: CHAPTER 5 70
25:
// Create a stream to receive the public data
26: in_ns =
NEW NETSTREAM (Client_nc);
27: Output_mc.fromsrvr.attachvideo (in_ns);
28: Output_mc.fromsrvr.attachaudio (IN_NS);
29: In_ns.play ("myav");
30:}
31:
// Called from the bandwidth buttons
32:
Function updateBandWidth (b) {
33:
// Respond to a change in the bandwidth
34:
// if "modem" WAS SELECTED
35:
IF (b == 1) {
36: Client_cam.SetMode (160, 120, 2);
37: Client_Cam.Setquality (0, 75);
38: Client_cam.setKeyFrameInterval (3);
39: Client_mic.Setrate (5);
40:
// for Demonstration Purposes, Change Size of Screen
41: OUTPUT_MC._HEIGHT = 100;
42: OUTPUT_MC._WIDTH = 150;
43:
// if "DSL" WAS SELECTED
44:}
Else
IF (b == 2) {
45: Client_cam.seTmode (160, 120, 5);
46: Client_cam.Setquality (0, 85);
47: Cam.SetKeyFrameInterval (5);
48: Client_mic.setrate (11);
49:
// for Demonstration Purposes, Change Size of Screen
50: OUTPUT_MC._HEIGHT = 130;
51: OUTPUT_MC._WIDTH = 175;
52:
// IF "LAN" WAS Selected
53:}
Else
/ * if (b == 3) * / {54: client_cam = camera.get (); 55: client_cam.setMode (160, 120, 15); 56: Client_cam.setquality (0, 90); 57: Client_cam.setKeyFrameInterval 10); 58: Client_Mic.Setrate (22); 59: // for Demonstration Purposes, change size of screen60: Output_mc._height = 150; 61: Output_mc._width = 200; 62:} 63: // Call The Server Function SetBandWidth and Pass the User's64: // Selection, B.65: Client_nc.call ("SetBandWidth", 0, B); 66:}
67:
// Get the stream to play
68: getPlayStream ();
In the main.asc file of the server, the setBandWidth method is included and is called by the client.
01:
// if Server-Side Code is Part of the Application,
02:
// it must define an onconnect function trata acception
03:
// The client connection.
04: Application.onConnect = function (client) {
05:
// establish the connection
06: Application.acceptConnection (client);
07:}
08:
// Called WHEN USER PRESSES A BANDWIDTH Choice (MODEM = 1, DSL = 2, LAN = 3)
09: Client.prototype.setBandWidth = Function (BW) {
10:
// set the bandwidth for the client
11:
IF (bw == 1) {
12:
// Modem Settings
13: this.SetBandwidthlimit (35000/8, 22000/8);
14:}
Else
IF (bw == 2) {
15:
// DSL settings
16: this.setBandwidthlimit (800000/8, 100000/8);
17:}
Else {
18:
// lan settings
19: this.setBandWidthlimit (400000, 400000);
20:}
twenty one : }
7. Develop Double-byte Applications If you need to use double-byte text in the development environment of the server, your server-side ActionScript code must use UTF-8 encoding. This means you have to write code with an editor that supports UTF-8, and then you can use built-in JavaScript methods, such as Date.Tolocalstring to convert cost-coding. If you use double-byte characters as a method name, you must use an object array operation method without using a point mode.
1 :
// Method format using double-byte named
2: OBJ ["method name"] = function () {}
3:
// Use a single-byte named method format
4: obj.methodname = function () {}