Contact Info / Websites

Afraid of Actionscript 3 OOP?

2010-10-05 15:39:31 by mwmdragon
Updated

Afraid of the whole Actionscript 3 OOP thing?

Don't worry it isn't as hard as these nerds make it out to be. OOP is basically just making a bunch of self contained functions in a cute little package (Class). You then use the class just like you would use a movie clip in your project with actionscript, by making a new instance of it and setting the properties for it, except the really cool part is that you get to make the properties yourself!

Replace the word (class) with "movie clip" and see how this looks...

Lets make a [giant dragon class], we want it to breath fire, bite and reward anyone who kills it with lots of gold! So we will give the [giant dragon class] a (breathe fire property) and let the programmer set how far the fire goes; A (bite property), and let the programmer set how much damage it does and a (gold property) and let the programmer set how much gold is rewarded.

Now we can make many different giant dragons with different fire breath distance, bite damage and gold rewards any time we want. Each new giant dragon we make from this class is it's own object.

So the class is the cookie cutter and the object is the cookie design it cuts out of the cookie dough.. each cookie made from this cookie cutter can have it's own amount of sprinkles and icing.. so the sprinkles and icing would be properties ;)

So now our [giant dragon class] properties look like this,

* giant_dragon_class.breathefire.(fire distance)
* giant_dragon_class.bite.(bite damage)
* giant_dragon_class.gold.(gold reward amount)

Which is extremely similar to this,

* movie_clip.x.(the movie clips x location on the screen)
* movie_clip.scale.(how big the movie clip is scaled in size)
* movie_clip.y.(the movie clips y location on the screen)

OMFG, now you can see you have been working with classes all along and might not have even known it!

Just think, if we built a monster class and let the programmer set the monster class's properties like... name, race, damage it does, and reward it gives.
The programmer could make an unlimited amount of different monsters with ease! (Each monster is a monster object like explained above with the cookies analogy).

And, if we want to add some armor to the monsters in the future, we would just add it to the monster class. It could then be used to make monsters with armor!

And all we had to make was one small addition in the entire games code to do it... *DROOL*... now you see why we are even bothering with learning OOP techniques ;)

You can more articles like this on our site as it gets bigger. No we are not trying to compete with any other site, it is only for our own use while learning Flash game design, but we also want to share it with anyone who is interested ;)


Comments

You must be logged in to comment on this post.