3.2 Document Class

In this exercise, we will bypass the methodology we have been using for coding, of introducing code in the timeline, and will create a document class, using our very first exercise – “Hello World!”.

1. Flash is not the only authoring platform for ActionScript files (Flash Builder, formerly Flex Builder, being another notable one). You can bypass the Flash authoring environment entirely by creating document class files, which are similar to the class definition files we saw in the previous exercise.

You can specify the document class in File > Publish Settings > Flash > ActionScript Version > Settings > Document class or in the properties inspector:

In the “Class” box write “Hello”. Save the Flash file.

2. Now let’s create a new ActionScript file, and type the following code there:

package {
import flash.text.TextField;
import flash.display.Sprite;
public class Hello extends Sprite {
public function Hello() {
var myTextField:TextField = new TextField();
myTextField.text="Hello world!";

The code is similar to the class definition on previous exercise, mixed with our first “Hello world” exercise.

If you need to include any time line elements (which we haven’t been exploring), the document class should extend (and import) the MovieClip class. If not, the more lightweight Sprite class should be enough.

3. Let’s save it as “Hello.as” in the same folder as the Flash file.

4. The end result should look like our first “Hello world!” exercise.

Download files: ex16-document_class.zip


About Nuno Correia

This entry was posted in 3. Project Management and tagged . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s