Flash Essential

AS3 Classes Beginners Guide Part 1

May 26th 2008
One Comment
respond
trackback

In this series of tutorials I'll be going through some of the basics of actionscript classes and how they work. So lets get started.

Step 1 Writing your first Custom Class

Open up Flash and select Actionscript File on the welcome screen. The first thing we do is save the file; I want you to save it as FirstClass. The file name you save it as is particularly important because the file name is the name of your class.

We start with our package and open and closed curly braces. Every class we write is wrapped inside a package. I’ll explain what packages are in later tutorials but for now it’s not important.

package{
}

Step 2 – Defining Our Class

Now we define our class inside our package. We do this by first typing class and then the name of our class file, which in this case is FirstClass. We end it by again having open and closed curly braces. Your code should now look like this;

package
{
class FirstClass
{
}
}

Step 3 Creating Our Constructer Function

Finally we create our Constructor Function, a constructor function is a function that runs automatically when our flash movie is played. We create our constructor function inside our class definition and give it some curly braces.

package
{
class FirstClass
{
function FirstClass()
{
trace("This is my first Class");
}
}
}

Recap

We wrap all our code inside a package

Then we define our class inside that package

Then we create our constructor function inside our class

Conclusion

Well done you’ve just created you’re first class, albeit it doesn’t do very much but still it’s a start! Now we’ll add to this Class in our next Tutorial.


This post is tagged ,



Sponsors

Explore Recent





Monthly Archives



Friends and Affiliates



One Comment

Leave a Reply