14.14. Implementing Server-Side ActionScript

Problem

You want to handle advanced FlashCom application needs with server-side functionality.

Solution

Place the server-side code in a main.asc or [registered_app_name].asc file in the FlashCom application’s root directory.

Discussion

Server-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:

application.onAppStart( )

This method is automatically called when the application first starts. You should place all your application initialization code within this method.

application.onConnect( )

This method is automatically called when a client connects to the application. FlashCom creates a new client object on the server and passes a reference to that object to the onConnect( ) method. Additionally, if the client-side connect( ) method includes any extra parameters, those values are also passed to onConnect( ). The onConnect( ) method ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.