00:00
00:00
Newgrounds Background Image Theme

kkolo just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As: Basic Oop

7,731 Views | 33 Replies
New Topic Respond to this Topic

Response to As: Basic Oop 2007-03-17 19:49:59


i would have posted this sooner but comcast shit on me

At 3/17/07 06:22 PM, sniffy-gerbil wrote: Would this be a valid code?

you should try as3, its basically the same but more java like. but for this code to work in as2 it would need some slight changes

class Character extends MovieClip {
public var name:String;
//needs "var" identifier before variable name
public var age:Number;
//int is in as3 not as2
private var items:Array = new Array(20);
//arrays get their own datatype and one array can handle multiple types
/*you dont need functions to set/get variables, just make them public and change them outside the class, like:
myCharacter.name = "";
your way works though*/
public function addItem(item:String):Void {
//put private/public/super on everything
items.push(item);
}
}

if i missed anything im sure gust will be all over it. also i took put "public" before "class" im not sure if it matters so test out both

Response to As: Basic Oop 2007-08-10 02:14:10


I'm just getting into OOP and I can already see the advantages to it. Say you have a game with several types of enemies. All you have to do is create an Enemy superclass and then create subclass enemy types that inherit methods. Also, if you were to make a sequel to this game, instead of copying and pasting enemy functions, all you have to do is refer to the enemy classes you made earlier. It is also very organized because all the classes' properties and methods are made in a separate .as file.

I do sort of mismatched programming right now, but OOP is awesome because it's cleaner and it's very fun to write.

:)


:D

Response to As: Basic Oop 2009-10-04 13:23:45


I'm coming from C++...

so, if I want to create a class, I really NEED to create a .as file and write the whole methods, constructors and variables inside it?

Response to As: Basic Oop 2009-10-04 15:13:48


At 10/4/09 01:23 PM, SkratorvanKernel wrote: so, if I want to create a class, I really NEED to create a .as file and write the whole methods, constructors and variables inside it?

Yes. There's only one way to declare things in AS. Look up a description.


BBS Signature