Do you like my tutorials?

Then consider supporting me on Ko-fi

Talking about Flash.

I know people usually get scared when someone talks about Objects. Object always mean OOP and tt sounds very hard to understand, and all in all you can code everything you want without using objects.

That’s true, but let me clarify some concepts:

1) Using basic Flash Objects is much easier than OOP
2) You can code everything without Objects, but with Objects your life will be easier
3) Basic Objects work both in AS2 and AS3
4) Never be afraid of new techniques (print this one)
5) I will use Objects in some future tuts so it’s time to learn them

Usually Objects tutorials start with the classic phone book where you can store name, address, and so on.

You can find such examples elsewhere.

In our case, let’s suppose we have a sphere (I told I will use Objects for a game in the near future…).
The sphere has a weight, a speed and a stamina.

You can declare it in the old way

sphere_weight = 100;
sphere_speed = 100;
sphere_stamina = 100;

or using Objects in this way

sphere = new Object();
sphere.weight = 100;
sphere.speed = 100;
sphere.stamina = 100;

“hey”, you may say, “you used four lines to do the same thing you did with 3 lines”

That’s right, but let me show you something:

var sphere = {weight:100,speed:100,stamina:100}

in just one line… this should sound familiar to you since it’s the same declaration to initialize movieclips attributes like

_root.attachMovie("obj","obj",1,{_x:100, _y:100});

Obviously Objects aren’t intended to write more code in less lines, so I am going to jump to the point of this tutorial.

The most interesting thing about objects is you can create an array of objects. Let’s suppose we have three spheres.

You can declare them with an array of objects in this way:

var spheres = new Array();
spheres[1] = {weight:100, speed:100, stamina:100};
spheres[2] = {weight:100, speed:100, stamina:100};
spheres[3] = {weight:100, speed:100, stamina:100};

That’s all you need to know at the moment… but during next tutorials I am going to use Objects a lot, and you will see how simple can be our life with Objects.

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.