Learn Actionscript - AHFX

Basic Actionscript - Introduction to Classes 

ahfx actionscript learning actionscript

AHFX Actionscript Home
Basic Actionscript
Intermediate Actionscript
Advanced Actionscript
About AHFX
Contact AHFX
Great Actionscript Links
 
 
 
 

Actionscript 2.0 Basics

In order to learn Actionscript 2.0, you must first learn some vocabulary. We will examine each of these in further detail. This is just a short list that we will add to as our discussion continues.

  • Class — encapsulates data (variables, attributes, etc.) and methods (functions, methods, etc).
  • Instance — the actual implementation of a class.
  • Method — a function inside of a class that performs a specific operation.

Classes in Actionscript 2.0

When learning, I like to have solid examples of code to work from. So here is your first code from the Product.as file:

class Product {

}

There are some important things to understand about this code:

  1. The name of the file Product.as is the same as the name of the class Product.
  2. You will want to put this code into a package to make it more user-friendly and easier to distribute.

Packages in Actionscript 2.0

A package is nothing more than a folder that contains one or more Actionscript 2.0 classes. Most packages are placed in multiple folders from generic to specific. For example, my package is com.ahfx.Product. I have a folder named com. In that folder I have another folder called ahfx. In that folder I have a class file, Product.as. When I distribute my Actionscript 2.0 classes, I will merely send the folder com to the organization that needs to use my classes. (If you notice you just invert your domain name ahfx.com to get your package name, com.ahfx. Packages also help distinquish between classes with the same name. For example if you wrote a class called Product, we could use the package to tell which Product we really wanted to use). To reflect the package change I will add that to my Actionscript 2.0 class code, Product.as.

class com.ahfx.Product {

}

Build It

We are now going to help you set up your very first Actionscript 2.0 class. We will first create the package, then start Flash MX 2004 and write our first actionscript.

  1. Browse on your computer to your Flash MX 2004 installation folder (for example: C:\Program Files\Macromedia\Flash MX 2004\en
  2. Go to the <—Macromedia install folder—>First Run\Classes\ folder
  3. In this folder (Classes) create a new folder named com
  4. Open the com folder you just created and create a new folder named ahfx
  5. I would now add a shortcut to this ahfx folder on you desktop.(Just for ease of access).
  6. Open Flash MX 2004
  7. Choose "Create New: Actionscript File"
  8. Copy the code from Product.as above into the new window
  9. Choose File|Save As and save it in the ahfx folder you created above.(If you added a shortcut to your desktop, click desktop, click the shortcut and it will take you to the correct folder).
  10. After saving, press Ctrl-t to check your syntax (Hopefully everything will be fine). If you get errors, make sure your file is named the same as the class name, and that you placed the file in the correct folder.
Continue to page 2
 

SUPPORT THIS SITE
If this tutorial helped you, show your support and send me something from my wish list.
Click on an item below and then choose
Adam Hayes (Gift Registry Address) for the Ship to Address.
It is that easy!
 

 

Featured Tutorials

Flash Shopping Cart Tutorial
Create a custom Flash Shopping Cart that will add, update, and show products.

Flash MX 2004 Custom Actions
Take your custom classes to the next level and have Flash treat them as built in classes.

Pass Variables to Flash
Quick and dirty way of passing variables to your flash animations.

Affordable Web Design and Hosting
Find out how you can cut your overhead by hosting with AHFX.net

Affordable Custom Art
Get your pictures custom framed. Amazing Prices. Outstanding Quality.


 
AH Digital FX Studios
Disclaimer | Site Map | Idaho Web Design