Hello Class
This is my first tutorial and I would like to start by creating a class using ActionScript 3.0 file. Start Flash CS3 Professional (that’s the version I’m using so far), create a new flash file then save it in a folder of your choice, I gave it a name of hello with small letter. Afterthat, create a new actionscript file and save in the same folder or place you saved your flash file and give it a specific name starting with a capital letter, for example, Hello.
So now we have two files: hello.fla and Hello.as
By the way you can even use note pad or simple word document to write actionscript files, I prefer to use flash actionscript because of the working environment.
When working with ActionScript 3.0 external file you must put our class inside a package, so we begin our scripting by typing the following:
1 2 3 | package { } |
Now that the file is created we need to create the main class that is the Hello class. We do that by declaring it between the two curly braces inside the package. It is essential to declare the class public so it can be accessed by other classes, just a note for future reference.
1 2 3 4 | package { public class Hello { } } |
We also need a constructor function to make this work this is the first starting point for executing the code.
1 2 3 4 5 6 | package { public class Hello { public function Hello() { } } } |
Important note to remember after creating your script file you need to link it to flash file by going back you flash file (hello.fla) and in the properties box find Document class field and type the name of the class you are linking to. In this case we will type (Hello) without the (.as) at the end
If you try to test your files by pressing Control/Enter you will receive an error
5000: The class ‘Hello’ must subclass ‘flash.display.MovieClip’ since it is linked to a library symbol of that type.
The way to solve that problem is that we need to import some classes to our file and also extend our class. We do that as shown below in bold:
1 2 3 4 5 6 7 8 | package{ import flash.display.MovieClip; public class Hello extends MovieClip{ public function Hello(){ trace("hello world"); } } } |
Now when you test your movie it should work fine and “hello world” will appear on your screen. I hope you are as excited as I am when I first saw that “hello world” on the screen I felt there is so much I want to do and nothing can stop me, except maybe I need to stop here and go to sleep
Next I’m going to delve into the world of programming by learning variables, math, functions, arrays …etc. stay tuned.







This is actionscript 3.0 101 more tutorials coming on this subject
Great kickstart to the world of AS3, Thank you very much!
Thanks I’m glad you liked the tutorial
Great minds think alike.