User Guide

Using multiple script files 85
In contrast, suppose you use the call() method from the client, to call a method on the
server side:
// This is client-side ActionScript in the FLA file.
NetConnection.call("someServerMethod");
// This is server-side ActionScript in the main.asc file.
client.prototype.someServerMethod = function(){
// code here
}
// The following code would also work.
application.onConnect = function(newClient) {
newClient.someServerMethod = function(){
// code
}
return true;
}
In this case, the parameter passed to NetConnection.call() must be a method of the server-
side Client object that was previously defined in the main.asc file. This is because any method
in the server code that the client can call must be a property of a server-side Client object.
Using multiple script files
As your application increases in complexity, dont try to use a single script to do everything:
break your functionality up into multiple scripts, each of which provides a specific set of
functionality. If you do use more than one file, you can use a “once-only inclusion” definition
to optimize performance and to prevent a file from being evaluated more than once.
For example, on the client side, to make a file named my_file.as available to other files in your
application, include the following code in my_file.as:
if (_root._my_file_as == null) {
_root._my_file_as = true;
// All the code for myfile.as goes here
}
In your other files, issue the following command:
#include "my_file.as";
NOTE
The #include happens at the time code is compiled, not at runtime.