Understanding Flash Objects
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 to “Understanding Flash Objects”
Leave a Reply
Trackbacks
-
From zero to Bombuzal - step 3 : Emanuele Feronato - italian geek and PROgrammer on
February 26th, 2008 5:41 pm
[...] I’ll create an object to store all its information. If you have troubles with objects, refer to Understanding Flash Objects [...]
- Citrus Engine released for free for learning
- My epic fail with ClickBank
- Get up to $100,000 for your next Flash game with Mochi GAME Developer Fund
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Triqui MochiAds Arcade plugin for WordPress official page
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.88/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a survival horror game in Flash tutorial – part 1 (4.74/5)
- Create a flash artillery game – step 2 (4.74/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 1 (4.71/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)





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
@Rick: Correct.