PDA

View Full Version : Cross-Platform Devel. (AS 2 OOP vs. AS 1 Procedural)


BroCaptRace
02-01-2006, 07:16 PM
I am trying to make my first game. However, at work I have Flash MX (AS 1.0) and at home I have Flash MX 2004 (AS 2.0). So far I've just been working on images and animation, so there haven't been too many problems.

But soon I would like to start coding and I've been thinking about trying an OOP approach - which restricts me to working on the project only at home.

Would it be easier/just as good to take a procedural approach and code for AS 1.0, or can anyone recommend sticking with the OOP approach that AS 2.0 allows for?

I have a lot of functions that will be used and reused by both the player and the enemy instances.

dijiyd
02-01-2006, 10:36 PM
Well, you CAN code OOP for as 1.0, although it might not be as organized. Unfortunately, there are some features in FP 7 and 8 that you might need for your game, you should look at those first.

senocular
02-02-2006, 09:20 AM
Just use OOP in AS1. AS2 compiles to AS1 anyway, so its not like theres much in AS2 you dont have in AS1. AS2 is just a syntactical change. There's very few differences functionally.

BroCaptRace
02-02-2006, 03:39 PM
Just use OOP in AS1. AS2 compiles to AS1 anyway, so its not like theres much in AS2 you dont have in AS1. AS2 is just a syntactical change. There's very few differences functionally.I'm pretty new to Actionscript (beyond simple animation), but I thought that AS1 did not support classes. How do you code in an object oriented style without classes?

What I thought I had to use was a class like the pseudocode example below. With the intention of implementing it for both the player and the enemies (just attaching different MC's):

Class gameMan(){
//===variables====
health
speed
power
underAttack

//===functions===
checkLOS()
move(speed)
attack(power)
takeDamage(enemy.power)
}

Is this possible with Flash MX (AS1) ?

senocular
02-02-2006, 03:57 PM
it just doesnt support the class syntax.


// AS2
class MyClass(){}

// AS1
_global.MyClass = function(){}

// AS2
class MyClass(){
var myVar = 1;
}

// AS1
_global.MyClass = function(){}
MyClass.prototype.myVar = 1;

// AS2
class MyClass(){
var myVar = 1;
function MyClass(param){
myVar = param;
}
}

// AS1
_global.MyClass = function(param){
this.myVar = param;
}
MyClass.prototype.myVar = 1;

// AS2
class MyClass(){
static var myStatic = 2;
var myVar = 1;
function MyClass(param){
myVar = param;
}
function myMethod(){
return myVar*myStatic;
}

}

// AS1
_global.MyClass = function(param){
this.myVar = param;
}
MyClass.myStatic = 2;
MyClass.prototype.myVar = 1;
MyClass.prototype.myMeth = function(){
return this.myVar*MyClass.myStatic;
}
Also, with AS1 you have to include external AS files manually using #include or create these classes within the FLA itself. Also, Object.registerClass is required for associating classes with Movie Clip symbols (as opposed to using the library option)

cancerinform
02-02-2006, 04:15 PM
Here is a different example.

http://www.flashscript.biz/MX2004/speech/speech.html

Sen, I did not know you prefer AS1 - prototype syntax. :rolleyes: How about AS3?;)

BroCaptRace
02-02-2006, 04:55 PM
Senocular, that is both helpful and interesting - have you considered doing a tutorial on this topic?

Cancerinform, thanks for the link. I must admit though, that "lady" kinda creeps me out.

senocular
02-02-2006, 05:18 PM
Senocular, that is both helpful and interesting - have you considered doing a tutorial on this topic?

Cancerinform, thanks for the link. I must admit though, that "lady" kinda creeps me out.
I have one:
http://www.kirupa.com/developer/oop/index.htm
http://www.kirupa.com/developer/oop2/AS2OOPindex.htm

I'm currently updating it to be more descriptive and to fix a few errors (esp AS2 part)

cancerinform
02-02-2006, 05:32 PM
that "lady" kinda creeps me out

No insults to the nice lady....:D