Flash Document Class

Although, I have been creating Flash Classes for some time, I had never created a class for my main Flash document – it has always been just a bunch of ActionScript functions. This wasn’t the OO way, so I decided to use the Document Class for the current application that I am working on. I was easy to set up.


When developing Flash applications, I generally store my ActionScript Classes in two locations:

  1. Any ActionScript class that can be used with multiple applications, I store under a folder named com. Any Class that I create (that can be used with multiple applications, I store under com/grasshopper.
  2. Any ActionScript class that is specific to the application that I am working on, I generally store in folder named ‘classes’. This folder is located under the main application folder (myapp/classes/). Other developers do not create a sub-folder to store their application specific classes, but rather create the classes under the main application folder (myapp/). This is a matter of preference.

When storing application specific classes under a sub-folder (myapp/classes/), you have to set the classpath under your Publish settings. Open your publish settings, and click on the ‘Flash’ tab. Then click the ‘Settings’ button located adjacent to the ActionScript version. Set the Classpath:

Document Classpath

Now create a new AS3 file and save it under your classes folder. I give the .as file the same name as my application, but other developers name the main class ‘MainClass.as’.

Now enter the name of the file in the Document Class entry on your Properties tab in your Flash IDE.

Document class

Now create the class:

package {
	import flash.display.MovieClip;
	public class portfolio extends MovieClip {
		public function portfolio() {
		private function init():void {

Note: The main document class must extend MovieClip. I received an error when I attempted to extend a Sprite.

That’s it. Now you can create methods of the class instead of a just a bunch of functions. One of the advantages of developing Flash applications with a Document class is that if you ever begin to develop your code in a different IDE (like Flex), you main application code will be available to you. Enjoy.

Be Sociable, Share!

Checkout My New Site - T-shirts For Geeks