Application Development Tips and Tricks > Application design and development > Using multiple files

 

Using multiple files

As your application increases in complexity, don't 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 optimize performance by using a "once-only inclusion" definition to prevent a file from being evaluated more than once.

 
On the client side

For example, on the client side, if you want a file named my_file.as to be 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
}

Then, 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.

 
On the server side

On the server side, you must implement slightly different code; there is no global object in server-side ActionScript. Here, assume you want to include a file called my_file.asc.

if (_my_file_asc == null) {
	_my_file_asc = true;
	// All the code for myfile.asc goes here
}

Also, instead of using the #include command, the server-side script uses a load command:

load("my_file.asc");