NAVIGATION:

 

SUPPORTERS:

FlashComponents
  Flash Templates
  Flash Gallery
  Flash Slideshow
  Flash Menu
  Flash Design
  Flash Video
  User Interface

 

FOLLOW:

RSS it down! Twitter it up! Facebook it like a fiend!

 

 

Classes in ActionScript 3
       by kirupa  |  24 December 2008

An application is not one giant chunk of functionality. Under the hood, applications are made up of many moving parts. One of the basic moving parts is the class:

If you have some familiarity with programming in ActionScript, the chances are very high that you have used classes such as String, Number, MovieClip, etc. before. Despite how common classes are to use, writing your own class is not a walk in the park.

In this article, you will learn what classes are, how classes can be used with Flash, and how to create your own class.

What are Classes?
Fundamental to object oriented programming is the concept of objects. These objects have to be defined somewhere, and that "somewhere" is where classes come in. Let's take a look at the example where you have an application that is made up of ten blue circles:

Each blue circle is an object, and each object is created from some sort of a template. This template specifies the type of your object and any characteristics this object exhibits, and these templates are known as....classes! For example, all of your circle objects could be based on a BlueCircle class that defines the various characteristics of the circle itself:

In the example I have provided, each of your circle objects was built from a class that contained information about your object's characteristics. Digging one level deeper, the following is an example of what a class defined in code vaguely looks like:

package {
import flash.display.*
 
public class BlueCircle {
 
private var someVariable:uint;
 
public function Circle() {
//initial tasks
}
 
public function SetColor(newColor:uint) {
 //code for setting the color
}
 
public function SetSize(newSize:uint):
{
 //code for setting the size
}
}
}

Don't worry if the above code doesn't make sense. By the end of this tutorial, the brief overview you just saw above will make more sense as more details and layers are revealed to you...starting on the next page!

Onwards to the next page.


1 | 2 | 3 | 4

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)