Creating an application



Writing client-side code

A client has code written in ActionScript that connects to the server, handles events, and does other work. With Flash, you can use ActionScript 3.0, 2.0, or 1.0, but ActionScript 3.0 offers many new features. With Flex, you must use ActionScript 3.0.

For information about learning ActionScript and working with video, see the following resources:

Writing server-side code

In general, applications require server-side code written in Server-Side ActionScript if they need to do any of the following:

Authenticate clients
By user name and password, or by credentials stored in an application server or database.

Implement connection logic
By taking some action when a client connects or disconnects.

Update clients
By calling remote methods on clients or updating shared objects that affect all connected clients.

Handle streams
By allowing you to play, record, and manage streams sent to and from the server.

Connect to other servers
By calling a web service or creating a network socket to an application server or database.

Place the server-side code in a file named main.asc or yourApplicationName.asc, where yourApplicationName is a folder in the RootInstall/applications folder. For example, to create an application called skatingClips, create the folder RootInstall/applications/skatingClips. The server-side code would be in a file called main.asc or skatingClips.asc in the skatingClips folder.

The server-side code goes at the top level of the application directory, or in its scripts subdirectory. For example, you can use either of these locations:

RootInstall/applications/appName

RootInstall/applications/appName/scripts

By default, the applications folder is in the root installation folder (C:\Program Files\Adobe\Flash Media Server 3.5\applications, on Windows). To configure the location of the applications folder, edit the fms.ini or the Vhost.xml configuration file. In the fms.ini file, edit the following parameter: VHOST.APPSDIR = C:\Program Files\Adobe\Flash Media Server 3.5\applications. In the Vhost.xml file, edit the AppsDir element.

Client and application objects

Server-side scripts have access to two special objects, the client object and the application object. When a client connects to an application on Flash Media Server, the server creates an instance of the server-side Client class to represent the client. An application can have thousands of clients connected. In your server-side code, you can use the client object to send and receive messages to individual clients.

Each application also has a single application object, which is an instance of the server-side Application class. The application object represents the application instance. You can use it to accept clients, disconnect them, shut down the application, and so on.

Writing double-byte applications

If you use Server-Side ActionScript to develop an application that uses double-byte text (such as an Asian language character set), place your server-side code in a main.asc file that is UTF-8 encoded. Use a JavaScript editor, such as the Script window in Flash or Adobe® Dreamweaver®, that encodes files to the UTF-8 standard. Use built-in JavaScript methods, such as Date.toLocaleString(), to convert the string to the locale encoding for that system.

Some simple text editors might not encode files to the UTF-8 standard. However, some editors provide a Save As option to encode files in the UTF-8 standard.

Set UTF-8 encoding in Dreamweaver

  1. Check the document encoding setting by selecting Modify > Page Properties, then Document Encoding. Choose Unicode (UTF-8).

  2. Change the inline input setting by selecting Edit > Preferences (Windows) or Dreamweaver > Preferences (Mac OS), and then click General. Select Enable Double-Byte Online Input to enable double-byte text.

Use double-byte characters as method names

 Assign method names using the object array operator, not the dot operator:
// This is the CORRECT way to create double-byte method names 
obj["Any_hi_byte_name"] = function(){}  
 
// This is the INCORRECT way to create double-byte method names. 
obj.Any_hi_byte_name = function() {}