Understanding Flash Objects
- February 6, 2008 by Emanuele Feronato
- Filed under Flash | 10 Comments
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
1 2 3 | sphere_weight = 100; sphere_speed = 100; sphere_stamina = 100; |
or using Objects in this way
1 2 3 4 | 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:
1 2 3 4 | 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.
They can be easily customized to meet the unique requirements of your project.
10 Responses
Leave a Reply
TUTORIAL SERIES:
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online



hmmm, I wonder how you are going to use this code….hmmmmmmmm
hi
this tut talks about objects, but i saw on some forums that we shouldn’t use movieclips in games and every tutorials you make uses only movieclips.
could you make a tutorial teaching how to make a game without movieclips, using bitmap?
on the forums they were saying we should use copypixel.
here is the link to the subject
http://www.kirupa.com/forum/showthread.php?t=276114
interest tutorial
can’t wait for the fifth part of the Metro Siberia tutorial
Woah, same name as me… I’d better change my name :S
Still… This is quite interesting.
………… I don’t understand O.o
Am I stupid or something?
What do you use objects for?
What do you mean?
“this tut talks about objects, but i saw on some forums that we shouldn’t use movieclips in games”
You say this goes about objects(something the most people wil notice)
than you start talking about movieclips… not very logical.
That forum goes about as3 and as2 as standalone script. It’s better than with movieclips etc. but a lot harder it takes like 20 times as long as a normal .fla
sorry for the strange thing.. it was a reply for the “quentin | Feb 6, 2008″ message
Question:
In this example
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};
are each element of the array defined as an object even if new Object isnt used, because of the {name:value, name2:value} for each of them?
how do you get the speed of sphere[2]?
like this?:
sphere[2].speed
[...] I’ll create an object to store all its information. If you have troubles with objects, refer to Understanding Flash Objects [...]
@Rick: Correct.