Getting Started With AS3 and Flash CS3

Create a new Document Class

Figure 2-1: Create new ActionScript File.
Now we need to save this new AS file in a package. Packages are a tiddy way to put our Classes into folders. It is common to create your custom Classes in a directory that is the reverse order of your website or company website name. My company name is IdentityMine.com so I saved my AS file in a directory called com\identityMine\documentClass\ and named it DocumentClass.as (see Figure 2-2).

Figure 2-2: Save your new AS file in a package or directory structure of com\identityMine\documentClass\DocumentClass.as
Now we need to do something that was introduced in AS3 and that is to create a namespace. A namespace of an AS file is the same as the package that the AS file is in. So in our DocumentClass.as file put in the namespace like I did in the code below:
package com.identityMine.documentClass
{
}
Now we need to declare the class. This is the same name as our AS file, see the code below:
package com.identityMine.documentClass
{
public class DocumentClass extends MovieClip
{
}
}
In the code above we declared our class as a public class that extends a MovieClip which means it now will inherit all of the properties of a MovieClip. We need to do this because our DocumentClass is the main Class for our movie.
Something also new to AS3 is that if we want to extend our new DocumentClass to a MovieClip we need to import the Flash MovieClip Class. I have done this in the code below:
package com.identityMine.documentClass
{
import flash.display.MovieClip;
public class DocumentClass extends MovieClip
{
}
}
Notice that the import statement is above the class declaration.
Now we need to create a Contructor for our DocumentClass. A contructor is not new to AS3 as AS2 Classes need them as well. A Constructor is basically a function or method that is called whenever the DocumentClass gets instantiated. In the case of a Document Class it will get instantiated when our movie first runs. I have created my constructor in the code below:
package com.identityMine.documentClass
{
import flash.display.MovieClip;
public class DocumentClass extends MovieClip
{
public function DocumentClass()
{
}
}
}
Note: a Contructor must never have a return type such as "void"
Now, lets add a trace statement into our Constructor so we can tell when it is instantiated:
Now let's move onto the next phase and hook our DocumentClass up to our Main.fla

