[ Team LiB ] |
Recipe 14.14 Implementing Server-Side ActionScript14.14.1 ProblemYou want to handle advanced FlashCom application needs with server-side functionality. 14.14.2 SolutionPlace the server-side code in a main.asc or [registered_app_name].asc file in the FlashCom application's root directory. 14.14.3 DiscussionServer-Side ActionScript must be placed within .asc files in the FlashCom application directory. FlashCom always looks for an .asc file named main.asc or [registered_app_name].asc (such as myApplication.asc) in the application's root directory. FlashCom also detects files named main.js or [registered_app_name].js as alternatives to the files with .asc file extensions. If none of these files exist, there is no custom server-side functionality. On the other hand, if FlashCom does find one of these files, it automatically looks for special application event handler methods when the corresponding events occur. Of these event handler methods, here are three of the most common:
Here is an example of a main.asc file, which can be placed in the FlashCom application's directory. It defines the three most common handlers you'll use to detect FlashCom events. application.onAppStart = function ( ) { // When the application starts up, create a server-side remote shared object and // save it to an application-wide property named mySsRso. application.mySsRso = SharedObject.get("mySharedObject"); // Create an application-wide property to keep track of the total number of users // that have connected since the application started. application.usersConnectedFromAppStart = 0; // Create an application-wide property to keep track of the total number of users // that have disconnected since the application started. application.usersDisconnectedFromAppStart = 0; }; application.onConnect = function (newClient) { // Accept the connection to the new client. application.acceptConnection(newClient); // Increment the number of connected users. application.usersConnectedFromAppStart += 1; }; application.onDisconnect = function (disconnectClient) { // Increment the number of disconnected users. application.usersDisconnectedFromAppStart += 1; }; 14.14.4 See AlsoRecipe 14.16. For more information about Server-Side ActionScript for FlashCom, see: |
[ Team LiB ] |