PDA

View Full Version : AS2.0 classes understanding pb



Uli
October 13th, 2005, 09:49 PM
Hello fellas,

I'm new to AS2.0 so i'm trying to figure it out...
so i was making a class and creating an instant out of it see how it works.
Here's my human class (human.as)


class human {
var age:Number;
var name:String;
var sex:String;
var analysis:String = "none";
function human(a:Number, n:String, s:String) {
age = a;
name = n;
sex = s;
}
function analyseIf******(sex) {
if (sex == "female") {
analysis = "Human is named"+name+" and is a chick";
} else {
analysis = "Human is named"+name+" and is an dude";
}
}
function analyseIfOldFoo(age) {
if (age>40) {
analysis += " and is an old sh1t";
} else {
analysis += " and has some more time before getting seasoned";
}
}
function traceStuff(analysis) {
trace(analysis);
}
}
---------------------------------
then in my flash movie:
var myHuman:human = new human(45 , "Tonia", "female");
myHuman.traceStuff();
stop();

But it traces analysis as undefined...
What am i doing wrong?

TiA :)

e.s.x.s
October 14th, 2005, 03:04 AM
you didin't call your functions analyseIf****** and analyseIfOldFoo from the constructor function..
if you create a class instance in the flash, it runs automatically the constructor function of the class. you should call other fuctions manually by yourself or use the constructer to run them ;) :hair: