AS3 – Object Oriented Programming – Intro
Programmers who are not-familiar with Object Oriented Programming, find it hard to understand and cope with the concepts of object oriented programming. And moving from function oriented programming to object oriented programming can be a real pain.
That’s because they don’t have the right thinking. They think, “hmm, so I have this instance of this class and i must call this function on this object; for that I must use the . (dot) operator…”.
Actually OOP tries to resemble nature. That’s right, nature proved us it’s way for millions of years, why not take after it?… or something like this
Let’s look at a nature example:
We have this big, beautiful apple. We look at it and we think “all apples look roughly the same”. So we take our apple, we look even closer to it and realize that even though it looks like all the other apples, there’s something particular about it: it’s a “Golden Delicious” apple. Now we know 2 things about it: it’s an apple, and furthermore it’s a Golden Delicious apple. We realize now that we can separate all the “Golden Delicious” apples from other classes of apples.
So here we are now:
We have the Apples class, which contains the Golden Delicious class and all the other apple classes: like Ultra Red Gala, Cameo, etc.
Furthermore, we can say: “but all the apples are fruits!”. Which is true.
This creates the next hierarchy:
- Fruit
- Apple
- Golden Delicious
- Ultra Red Gala
- Cameo
- Apple
Ok we know something about classes, but what is our apple? It’s not a class, it can’t be a class because it’s an object. That’s right: the class of our apple is “Golden Delicious”, the base class is “Apple”, but our apple is an instance of the class “Golden Delicious”.
Ok, that’s a very simplistic way of looking at Object Oriented programming.
This is only an introduction, as OOP is very complex, OOP in AS3 is complex too, so i’ll try to explain everything that’s needed to find your way into OO programming world.
I think it’s worth mentioning here that OOP concepts are common on all OO programming languages, however the syntax and features may differ from language to language.
Follow on to the first actual part of this tutorial: AS3 – Object Oriented Programming – Part1


OOP is definitely a hard thing to grasp at first, especially if you’re used to doing hack job “programming” in AS2. I caught on to OOP and it’s magic not too long ago, I’ll never go back, it’s amazing.
what would ‘Fruit’ be? A class? How deep can you go?
Thanks love the blog.
Hi,
Fruit yes it can be the base class of class Apple if you want.
How deep can you go?: you can go as deep as you want, but you should always think ahead how you’d be using, if you’d need all that inheritance, to keep things clean.
Fruit can extend Object or another base class of your choice (Object class is used in most OO languages as the base class for all other classes; this is true for AS3 also) if you’d like. And so on..
So you can have Object<–Fruit<–Apple<–RedGalaApple