So a while back, this thread was started:
http://board.flashkit.com/board/show...93#post3801593

In response to it, this thread (as in the one you are reading) was started.

Purpose:
The purpose of this thread is to provide resources, tips and best practices for those interested in learning more about Object Oriented Programming (henceforth OOP).

Mostly we want to focus on OOP in relationship to ActionScript, but references to general OOP best practices are welcome as well.

Expectations:
People are going to differ as to what they regard as best practices. So what you are going to get are a collection of opinions on best practices. The thread is by no means meant to be gospel.

If you are referencing some external resource or book please provide a reference or link.

Hopefully we will have enough experience collectively to make this a useful thread.

So let's kick it off:

Resources: (Here is where I go/ I will add more to this later.)

General OOP:
Wikiversity School of computer Science:
http://en.wikiversity.org/wiki/Topic...ed_Programming


OOP in a Nutshell (for which I may be accused of being a nut):
So this is meant to be a very basic introduction, so I am going to be abstract (something those of you familiar with OOP should know the benefits of, so go easy on me).

Basically put, Objects are related pieces of code in a specified syntax that perform a set of related tasks. Objects are created by creating class files (in AS these are external ActionScript files). If you have done even simple coding in Flash, you have probably done something like:

var myVariable = new MovieClip();

In this case we have created a variable myVariable that is an instance of the MovieClip object. We know this because of the new key word. When you use the new keyword you are creating and instance of an object. So what exactly go created? Well take a look at (assuming you are on a Windows Machine with Flash 8) C:\Program Files\Macromedia\Flash 8\en\First Run\Classes\FP8\MovieClip.as. , BUT DON’T EDIT IT. Notice it is more or less a collection of variables and functions (in this case mostly abstract methods, but more on that in a later post)

So why do this, well I can create multiple instances of a movie clip from the same AS file without having to reproduce the code in that file. All instances of this object will have the same variables (aka properties) and functions (aka methods). Once I have multiple instances of a class (aka object) . I can then apply different properties (e.g., set different alpha levels) and call specific behaviors (via methods) for each instance. I can do this because of the design of the MovieClip class. Basically, the MovieClip class defines all of the properties and behaviors expected of a MovieClip. Once I have created and instance of one, I can then set those properties and call the behaviors for each instance of that object.

So what does a class look like?
Well you can take a look the classes in C:\Program Files\Macromedia\Flash 8\en\First Run\Classes (Again DON’T EDIT them). These are the basic classes that come with Flash and these are actually what you are calling when you use that new keyword (there’s more to it, but we will get to that in a later post).

The basic syntax of a class is:

AS 2.0: File Name would Be ClassName.as
class ClassName {

function ClassName(){

}
}

AS 3.0 File name would be ClassName.as (and located in foldername under the root class path, more on this in some later post as well)

package foldername {
class ClassName{
function Classname(){

}
}
}

Few things to note and then I will sign off for this post:

The name of the AS file, the class name and the constructor function name (the one I bothered to write out in the examples - this can be one of many functions) must all match. These will also match how you use the keyword new. So for these examples you would create an instance by:

var myVar = new ClassName();

which actually ends up calling the constructor method. By having all those names match, Flash knows what file to refer to and what method to call.

OK I know that was really abstract (and long) and I left a bunch of things out (like data typing and what a class that actually does something looks like), but hopefully this will be the first post of many.

Bye for now and feel free to contribute.