All right, so what exactly are classes? I’ve heard about them in PHP and flash, and i’d really love to know what they’re useful for and how you use them.

thanks in advance


Best bet is do a google search. It’s not a quick topic to understand.

Basically, a Class is a broad definition for a series of complex objects. Just like all the students in a class are not the same, but they have something in common - which is why they are in the same class.

A class is basically a custom data type.

Here’s a simple class:

class Simple
    private var simpleVar:Number;

    public Simple(s:Number)
        simpleVar = s;

    public getSimpleVar()
        return simpleVar;

then to use it:

var mySimpleClass:Simple;
mySimpleClass = new Simple(420);
trace(mySimpleClass.getSimpleVar()); //420

that’s all there is to it!

so is that flash? and what are the : for? are they identifiers?


Carixpig is right definately not a simple subject to understand. But in my opinion one of the most fundamental ideas that is required to do anything in programming today, whether that be C++, Java, or Kernel OS programming.

Classes are one model (basically the back-bone) that helps to make up the OOP (object oriented programming) idea. Classes in the most simplest form define an object, so there-fore a class is a object definition.

Objects are anything that you can think of, the string attribute in flash is an object of type string. The idea stems from the real world. You have before you a monitor, that monitor is by definition an object (in the real world). But progmatically it could also be an object. For instance, when you talk about that monitor you would say it has certain qualities (or attributes :slight_smile: ) to define it specifically like: size, color_depth, resolution, and model_type.

So to write that progmatically we would do this.

class monitor {
	 [color=darkorange]public [/color][color=royalblue]var [/color][color=lime]size[/color]:[color=purple]Number[/color];  
	 //What was done here was i declared an attribute of the class, monitor.  //That attribute is accessable from anywhere in the class or outside it ([color=darkorange]public[/color]).  
//Then I declared it to be a attribute of the class monitor ([color=blue]var[/color]).  
//I then gave that attribute a name: [color=lime]size[/color]
[color=black]//I then gave that attribute the type: [/color][color=purple]Number[/color]
	 function monitor() {
		  //What I am doing here is defining the original state of the
		  //monitor classes, attribute of size to 26 inches.[/color]
		  //this function is called when you define an object of monitor in
		  //your main FLA.  ie  gateway = new monitor();
		  //trace(gateway.size) will show 26!  
		  size = new Number(26);

This is a real basic example and the kirupa site has a real good tut on the new AS2 OOP programming model (btw this is AS2 only script). Hope this illustrates what Classes are!


wow, thank you sooper much! that makes SO much sense! i will definetly check out the tute.

thanks for explaining that so well!


Your welcome!