Be a Supporter!

As: Oop Classes For Morons.

  • 3,809 Views
  • 31 Replies
New Topic Respond to this Topic
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:25 AM Reply

AS:Main. My antiWork.

Preface

Basics of variables/functions and other mundane actionscript are recommended before reading.

Many of us know and understand how to create and utilize "Classes" in our flash, because we know what they are, how they work and we understand both the terminology and the amazing uses for them. Many people that are new to languages are scared shit face of these things though. This tutorial, part of the "for Morons" series aims to cut out all of the large words, strange syntax and scary symbols that make most people completely turn their back on OOP and continue coding "the old way." This is not an all in one tutorial for how classes and/or OOP work. It is stripped, bare bones about the uses of Classes in plain English for people that cry and cut themselves when they see anything that resembles an object. If you're afraid of Classes, and haven't used them in any of your programs, because you're a whiney little girly man, read on.

Once you have a strong grasp on "why" you'll better understand the "how" that both Authorblues and Inglor described in their tutorials, here...

OOP classes by AuthorBlues
OOP Overview by Inglor

Words that will NOT be used in this tutorial because of the nature of it (but should be learned immediately afterwards )

Encapsulation, Inheritance, derive, implement, delimit, instantiate, property, method,

Moron'd definition of Classes: Think of classes as stencils. You cut out a stencil one freaking time and you can use it over and over again.
Moron'd definition of Objects: Think of objects as what is created after you spray paint over the stencil.

You can have one stencil, and make the same design in 20 different colors. All of them are the basically the same, but different in their own way. Classes sounding pretty freaking sweet so far? Hoping to save your poor typing digits hours of agony? Good. Let's continue. Let's create a class... on ideas alone first.

First, we need something cool. How about Ninjas? Ninjas are freaking metal. So, we're going to start building our Ninja stencil. This will be our class.

Now, in order to create a class, we need to know what things that ninjas have in common. We need to separate these in cool shit they HAVE and cool shit they can DO.

So, things all good Ninjas HAVE...

A name
A certain color uniform
A weapon
A master
A certain type of martial art
A finishing move

Now, ALL good ninjas can DO the following things.

Be stealthy
Kick major ass
Assassinate Mo fos.

Alright, we have our list of what Ninjas have and can do. Guess what.

The stuff they HAVE… those are basically variables.
The stuff they can DO… those are basically functions.

Now, if you wanted to create 10 different ninjas, without classes, you would have like 60 variables, and maybe 30 functions. Screw that. We have ONE class, and TEN objects.

Now, I know we said we weren't going to get into the "how" of classes, but I lied. Don't cry, pussy. This will help you get a visual of the basic framework of what that class would look like in a very simple form. (keyword "var" and variable data identifiers, constructor and access properties left our purposefully)

class Ninja{

//variables (properties of a class)

name;
colorUniform;
weapon;
master;
martialArt;
finishingMove;

//functions (methods of a class)

beStealthy();
kickMajorAss();
assassinateMoFos();

}

Now, the question is this... "Dude, why the hell don't the variables equal anything?" It because we just built our template. Our stencil. Those don't have to be filled in. We haven't taken our paint to the stencil yet. Now, we can create all of our ninjas based on that one class we just created! Not that exact one. You still need to learn a few things, listed in the other tutes.

Alright, let's think of some other uses for classes, so you can first hand some of the uses of coding.

A car
Color;
Speed;
numberOfDoors;

Move();
Turn();
Stop();
Explode()

Hookers

breastSize;
numberOfDiseases;
homeCorner;
hookerName;

turnTricks();
bitchSlap();
explode();

Your main hero (because then all of his stuff is stored in ONE place)
strength;
defense;
magicPoints;
penisSize; (important for main characters)

Magic();
UseItem();
Attack();
Defend();
GetTheChicks();
Explode() (after getting the chicks)

Platforms in a game!

rotating = false
elevating = false
stationary = true

stopCharacterFromFalling();
explode();

some guns.

ammo;
range;
accuracy;
damage;

shoot()
reload()
explode()

Midgets for you midget punting game.

Size;
Weight;
Aerodynamics;

ScreamLikeAbitch();
Explode();

Now, every time you create an object, you use the class you created and just fill in the blanks! If you play table top role playing games (Such as D&D) think of classes as your character sheets. One sheet can be filled in thousands of ways to create thousands of different characters.

If you don't play, think of classes as the new ground's forums. The basic functions of general, flash, and where is/how to are the same. They all have places for you to click "reply" and flame me. They all have a list of posts, yet every forum has different posts in it, and concerns different topics. It's a stretch, but still a form of a class.

With all of these things listed, you should have no problem recognizing just a few of the VERY fundamental uses for classes and how they can not only help you organize your code, but also speed up your coding and reuse of the same code, over multiple games so you can crank out games that with some luck, and some skill won't get the big fucking blam. I now recommend reading Inglor's description of OOP which goes into the basic structure and then following that up with AuthorBlues Hella in-depth class tutorial, both listed at the top of this page.

I don't want any excuses from you newer folk for not submitting games with classes in them, and peppering the damned BBS with questions about OOP. No excuses!

(hopefully classes in actionscript work the same as C++ ones....)


Perpetually looking for time to return to the arts.

BBS Signature
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:30 AM Reply

In hindsight, I shouldn't have written this at 5:30am with no coffee. I should have slept first, and written it after a good night's sleep. Eh... maybe it'll help someone, somewhere.


Perpetually looking for time to return to the arts.

BBS Signature
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:31 AM Reply

nice ,has anyone actually covered getter/setters and static vars yet? i glanced at the other 2 and didnt see anything...

Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:34 AM Reply

At 2/13/06 05:31 AM, T-H wrote: nice ,has anyone actually covered getter/setters and static vars yet? i glanced at the other 2 and didnt see anything...

No, not yet. I was thinking about doing getters, setters, "simulating" multiple constructor functions (because AS doesn't allow it) and maybe pointers and derferencing later on down the line. Damnit, I like writing fun ones though.


Perpetually looking for time to return to the arts.

BBS Signature
Barbeq
Barbeq
  • Member since: May. 6, 2000
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 07:58 AM Reply

Remember kids!

The plural form of ninja is ninja, no s there

lol i had too!!!
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 08:06 AM Reply

Informative, and fun like hell. Good job =)


BBS Signature
Nick
Nick
  • Member since: Aug. 22, 2005
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 08:28 AM Reply

At 2/13/06 07:58 AM, Barbeq wrote: Remember kids!

The plural form of ninja is ninja, no s there

Really?

You learn something new everyday.
Barbeq
Barbeq
  • Member since: May. 6, 2000
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 08:34 AM Reply

At 2/13/06 08:28 AM, _Nick_ wrote: Really?

You learn something new everyday.

yepp, i just discovered that and i learn something new from the flash forum everyday!

The flash forum is like school but even better!

Devenger
Devenger
  • Member since: Dec. 24, 2004
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 08:53 AM Reply

At 2/13/06 08:34 AM, Barbeq wrote: The flash forum is like school but even better!

Piffle. 'The difference between here and school is, school has more morons, less teaching, and no purpose.' - Devenger, a second ago


I'm back! on a temporary basis. No-one can remember who I am! but I don't really mind.

authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 09:28 AM Reply

At 2/13/06 05:31 AM, T-H wrote: has anyone actually covered getter/setters and static vars yet?

keke, ill do it :) (do you mean getter/setters as in the "encapsulation" portion of my tutorial, or do you mean the technical version, which is bullshit really). i also just wrote a class the other day using static properties and methods, so ill punch out a tutorial for it later.


BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 10:57 AM Reply

At 2/13/06 09:28 AM, authorblues wrote: keke, ill do it :)

and so it shall be...
AS: OOP - Static Properties / Methods by authorblues


BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 02:34 PM Reply

dont all ninjas use the same martial art?

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 02:35 PM Reply

At 2/13/06 02:34 PM, Glaiel_Gamer wrote: dont all ninjas use the same martial art?

Noooo.. theres Ninja-Fu, Ninja-Kwan-d0, Ninjarate, the list is endless.


Sup, bitches :)

BBS Signature
Kirk-Cocaine
Kirk-Cocaine
  • Member since: Aug. 17, 2003
  • Offline.
Forum Stats
Moderator
Level 38
Programmer
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 02:38 PM Reply

At 2/13/06 02:35 PM, -liam- wrote:
At 2/13/06 02:34 PM, Glaiel_Gamer wrote: dont all ninjas use the same martial art?
Noooo.. theres Ninja-Fu, Ninja-Kwan-d0, Ninjarate, the list is endless.

I thought Ninja's were masters in every martial art.


The water in Majorca don't taste like what it oughta.

| AS3: Main | AS2: Main | Flash Tutorials |

BBS Signature
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 02:40 PM Reply

At 2/13/06 02:38 PM, Kirk_Cocaine wrote: I thought Ninja's were masters in every martial art.

No, Uber-Ninjas are masters in all martial arts.


Sup, bitches :)

BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 02:43 PM Reply

i thought it was ninjitsu or something

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 02:46 PM Reply

At 2/13/06 02:43 PM, Glaiel_Gamer wrote: i thought it was ninjitsu or something

Most ninja(plurial) practised ninjitsu, even I (toast teh ninja) have. :P It's kind of cool, if you're really good you can stick to walls just like spiderman :D My teacher can do that.


BBS Signature
Kirk-Cocaine
Kirk-Cocaine
  • Member since: Aug. 17, 2003
  • Offline.
Forum Stats
Moderator
Level 38
Programmer
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 02:48 PM Reply

At 2/13/06 02:40 PM, -liam- wrote: No, Uber-Ninjas are masters in all martial arts.

I refuse to believe that Uber-Ninjas are called Chantelle.


The water in Majorca don't taste like what it oughta.

| AS3: Main | AS2: Main | Flash Tutorials |

BBS Signature
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 03:54 PM Reply

1) I had no freaking idea that the plural of ninja was "ninja." Woot! Learn something new every day.

2) I have no idea if ninja know various martial arts.

4) Authorblues, that tutorial came out fast as hell!


Perpetually looking for time to return to the arts.

BBS Signature
jmtb02
jmtb02
  • Member since: Mar. 1, 2004
  • Offline.
Forum Stats
Member
Level 29
Game Developer
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 03:56 PM Reply

Pirates are much better than ninja, however, that goes without saying. Great job on this.


Hi there!

BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 04:58 PM Reply

At 2/13/06 03:54 PM, Johnny_Krysys wrote: 1) point A
2) point B
4) point C?

dear god, i think you should all be paying more attention to number 3? you guys are blathering on about ninjas and spiderman, and chantelle, but no one seems to care that number 3 has gone missing. you ignorant fools...


BBS Signature
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:14 PM Reply

At 2/13/06 04:58 PM, authorblues wrote: you ignorant fools...

You number muncher...


BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:15 PM Reply

At 2/13/06 05:14 PM, Rantzien wrote: You number muncher...

dont even. at least i can get into my school without getting laughed at from the inside.


BBS Signature
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:16 PM Reply

At 2/13/06 05:15 PM, authorblues wrote:
At 2/13/06 05:14 PM, Rantzien wrote: You number muncher...
dont even. at least i can get into my school without getting laughed at from the inside.

You mean, they're not laughing "with" me, like they said they were?


Perpetually looking for time to return to the arts.

BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:20 PM Reply

At 2/13/06 05:16 PM, Johnny_Krysys wrote: You mean, they're not laughing "with" me, like they said they were?

rantzy got locked out of the building at his school. its okay, we both had dumb days. (by the way, rantzy, the classroom was empty because they were all taking a test in the lab, which i missed and had to make up at 2pm)


BBS Signature
Kirk-Cocaine
Kirk-Cocaine
  • Member since: Aug. 17, 2003
  • Offline.
Forum Stats
Moderator
Level 38
Programmer
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:24 PM Reply

At 2/13/06 04:58 PM, authorblues wrote: dear god, i think you should all be paying more attention to number 3? you guys are blathering on about ninjas and spiderman, and chantelle, but no one seems to care that number 3 has gone missing. you ignorant fools...

3 is busy getting his grove on with < in preparation for tomorrow:

As: Oop Classes For Morons.


The water in Majorca don't taste like what it oughta.

| AS3: Main | AS2: Main | Flash Tutorials |

BBS Signature
Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:26 PM Reply

My threads always turn into free for alls. I could post "My family just died in a car accident" and people would be in here joking.

That's fucking awesome.

I <3 you guys.

Laughs cure all diseases.

Except AIDs.

Trust me, I know.


Perpetually looking for time to return to the arts.

BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:40 PM Reply

At 2/13/06 05:26 PM, Johnny_Krysys wrote: Except AIDs.

but thats because no one ever tried. because theres nothing funny about AIDs.
now leprosy. that is a fucking hilarious disease. id scare children with that.


BBS Signature
Kirk-Cocaine
Kirk-Cocaine
  • Member since: Aug. 17, 2003
  • Offline.
Forum Stats
Moderator
Level 38
Programmer
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 05:46 PM Reply

At 2/13/06 05:40 PM, authorblues wrote: but thats because no one ever tried. because theres nothing funny about AIDs.
now leprosy. that is a fucking hilarious disease. id scare children with that.

Pssh, scaring children is so 1994. It's all about bursting into song:


Leprosy, why do bits keep falling off of me?
Now I'm not half the man I used to be.
Oh I believe I've got leprosy

Sung to the tune of Yesterday.

The water in Majorca don't taste like what it oughta.

| AS3: Main | AS2: Main | Flash Tutorials |

BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to As: Oop Classes For Morons. Feb. 13th, 2006 @ 06:33 PM Reply

At 2/13/06 05:46 PM, Kirk_Cocaine wrote: Leprosy, why do bits keep falling off of me?
Now I'm not half the man I used to be.
Oh I believe I've got leprosy

OMG *bursts into laughter*