Document Class in AS 3

A friend of mine from school send me an e-mail about how to set up the document class in Flash CS 5 & AS3. She is just starting out with flash, but I thought That I would write a blog about it as well in case anybody out their just starting out needs a demo.

Create a new AS 3 file in Flash CS 5

In the properties/publish panel settings click on the pencil to create a new actioscript class.

This window will pop u after you do this, call your class a name, I am calling it Main

Flash CS 5 will generate a as class for you that looks like:

package  {

	import flash.display.MovieClip;

	public class Main extends MovieClip {

		public function Main() {
			// constructor code
		}
	}

}

we will add a trace statement to the main function so the Main.as will become

package  {

	import flash.display.MovieClip;

	public class Main extends MovieClip {

		public function Main() {
			trace ("the main document class says hello");
		}
	}

}

Notice that thier is a default package, and that we imported the MovieClip class.
This is important as the Main Class extends the MovieClip class.
Document classes must either extend the MovieClip or Sprite class.

If they are animations with frames, or methods and functions of movie clips, the class will need to extend  the MovieClip class.
Otherwise, if you only need Sprite functionality, just use Sprite instaed.

in fact in this example I should have used Sprite instead of the MovieClip, but want to just use what Flash CS 5 generated.

save both files, and in the main fla use command +enter to test movie, and you will see the trace statement in the output window

Leave a Reply