Forum Topic: As: Oop Classes For Morons.

(2,221 views • 31 replies)

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
None

Johnny

Reply To Post Reply & Quote

Posted at: 2/13/06 05:25 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,429

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....)

All sites currently down. Deal with it. <3

BBS Signature

None

Johnny

Reply To Post Reply & Quote

Posted at: 2/13/06 05:30 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,429

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.

All sites currently down. Deal with it. <3

BBS Signature

None

T-H

Reply To Post Reply & Quote

Posted at: 2/13/06 05:31 AM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

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


None

Johnny

Reply To Post Reply & Quote

Posted at: 2/13/06 05:34 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,429

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.

All sites currently down. Deal with it. <3

BBS Signature

None

Barbeq

Reply To Post Reply & Quote

Posted at: 2/13/06 07:58 AM

Barbeq LIGHT LEVEL 16

Sign-Up: 05/06/00

Posts: 3,221

Remember kids!

The plural form of ninja is ninja, no s there

lol i had too!!!

None

Rantzien

Reply To Post Reply & Quote

Posted at: 2/13/06 08:06 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

Informative, and fun like hell. Good job =)

BBS Signature

None

Nick

Reply To Post Reply & Quote

Posted at: 2/13/06 08:28 AM

Nick FAB LEVEL 23

Sign-Up: 08/22/05

Posts: 1,977

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.

None

Barbeq

Reply To Post Reply & Quote

Posted at: 2/13/06 08:34 AM

Barbeq LIGHT LEVEL 16

Sign-Up: 05/06/00

Posts: 3,221

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!


None

Devenger

Reply To Post Reply & Quote

Posted at: 2/13/06 08:53 AM

Devenger NEUTRAL LEVEL 09

Sign-Up: 12/24/04

Posts: 1,103

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.


None

authorblues

Reply To Post Reply & Quote

Posted at: 2/13/06 09:28 AM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 2/13/06 10:57 AM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 2/13/06 02:34 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,053

dont all ninjas use the same martial art?


None

liaaaam

Reply To Post Reply & Quote

Posted at: 2/13/06 02:35 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

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.


None

Kirk-Cocaine

Reply To Post Reply & Quote

Posted at: 2/13/06 02:38 PM

Kirk-Cocaine EVIL LEVEL 36

Sign-Up: 08/17/03

Posts: 17,842

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.


None

liaaaam

Reply To Post Reply & Quote

Posted at: 2/13/06 02:40 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

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.


None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 2/13/06 02:43 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,053

i thought it was ninjitsu or something


None

Toast

Reply To Post Reply & Quote

Posted at: 2/13/06 02:46 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,921

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.


None

Johnny

Reply To Post Reply & Quote

Posted at: 2/13/06 03:54 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,429

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!

All sites currently down. Deal with it. <3

BBS Signature

None

jmtb02

Reply To Post Reply & Quote

Posted at: 2/13/06 03:56 PM

jmtb02 LIGHT LEVEL 29

Sign-Up: 03/01/04

Posts: 5,842

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

Hi there!

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 2/13/06 04:58 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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...

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

Rantzien

Reply To Post Reply & Quote

Posted at: 2/13/06 05:14 PM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

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

You number muncher...

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 2/13/06 05:15 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

Johnny

Reply To Post Reply & Quote

Posted at: 2/13/06 05:16 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,429

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?

All sites currently down. Deal with it. <3

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 2/13/06 05:20 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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)

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

Happy

Kirk-Cocaine

Reply To Post Reply & Quote

Posted at: 2/13/06 05:24 PM

Kirk-Cocaine EVIL LEVEL 36

Sign-Up: 08/17/03

Posts: 17,842

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.


None

Johnny

Reply To Post Reply & Quote

Posted at: 2/13/06 05:26 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,429

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.

All sites currently down. Deal with it. <3

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 2/13/06 05:40 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

Kirk-Cocaine

Reply To Post Reply & Quote

Posted at: 2/13/06 05:46 PM

Kirk-Cocaine EVIL LEVEL 36

Sign-Up: 08/17/03

Posts: 17,842

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.

None

Glaiel-Gamer

Reply To Post Reply & Quote

Posted at: 2/13/06 06:33 PM

Glaiel-Gamer NEUTRAL LEVEL 27

Sign-Up: 12/28/04

Posts: 8,053

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*


All times are Eastern Standard Time (GMT -5) | Current Time: 03:13 AM

<< Back

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!