"function" and "new"

okay, i can use function functionname (){…} fine and then call the function later in my flash game. i can also do function functionname(variable){…} and get it to work. but what i can’t seem to do is use “function” to make my own types of variables like this:

function funcname(var1,var2,var3){
this.var1=var1;
this.var2=var2;
this.var3=var3;
}
newvariable1 = new funcname(“value of var1”,“value of var2”,“value of var3”);
newvariable2 = new funcnam(“value of var1”,“value of var2”,“value of var3”);

shouldn’t newvariable1.var1 be “value of var1”? i cant seem to get it to work.

anyone know what i’m talkin about? if so, please reply. here’s the parts of my code that involve this type of command (parts that i think mite have probs are underlined):

function Car(Name, Maxspeed, Accel, Turbo, Handling, Turns, Maxhealth, Health, Power, Offroad, Gas, Price, Unlocked) {
this.Name = Name;
this.Maxspeed = Maxspeed;
this.Accel = Accel;
this.Turbo = Turbo;
this.Handling = Handling;
this.Turns = Turns;
this.Maxhealth = Maxhealth;
this.Health = Health;
this.Power = Power;
this.Offroad = Offroad;
this.Gas = Gas;
this.Price = Price;
this.Unlocked = Unlocked;
}
car1 = new Car(“car1”, 180, 1, 1, 100, 20, 100, 100, 2, 0.6, 65, 0, true);
car2 = new Car(“car2”, 240, 1.25, 1.5, 300, 60, 150, 150, 3, 0.7, 80, 0, false);
car3 = new Car(“car3”, 120, 1, 1, 250, 40, 100, 100, 1, 0.9, 40, 0, false);
car4 = new Car(“car4”, 220, 1, 1, 500, 90, 100, 100, 2, 0.5, 70, 0, false);
car5 = new Car(“car5”, 200, 1, 1, 250, 60, 200, 200, 5, 0.1, 80, 0, false);
car6 = new Car(“car6”, 320, 1.75, 2, 200, 40, 125, 125, 1, 0.5, 120, 0, false);
car7 = new Car(“car7”, 240, 1.5, 1.5, 200, 60, 1000, 1000, 10, 0.8, 150, 0, false);
car8 = new Car(“car8”, 280, 1.75, 1.75, 370, 60, 100, 100, 2, 0.5, 100, 0, false);
function currentCar(currentcar) {
Accel = currentcar.Accel;
Turns = currentcar.Turns;
Handling = currentcar.Handling;
Offroad = currentcar.Offroad;
}
currentCar(car1);

/*

later in the code

*/

[U]Handling[/U] = ([U]Handling[/U]/4)*[U]Accel[/U]+([U]Handling[/U]*3/4);
this.leftWheel._rotation = this.steering/2;
this.rightWheel._rotation = this.steering/2;
speed = Math.sqrt(this.velX*this.velX+this.velY*this.velY);
this.velR += this.steering*speed/[U]Handling[/U];

// this.stuff refers to the actual movie clip of the car

if (Key.isDown(Key.LEFT)) {
	car.steering = [U]-Turns[/U];
} else if (Key.isDown(Key.RIGHT)) {
	car.steering = [U]Turns[/U];
}
if (Key.isDown(Key.UP)) {
	car.accel = [U]Accel[/U];
} else if (Key.isDown(Key.DOWN)) {
	car.accel = [U]-Accel/2[/U];
}

// car.stuff refers to the actual movie clip of the car

(end of significant part)

if you need the whole code to help me please ask.

It’s possible that it’s not working because you are not associating your new “class” with a prototype object:

function MyNewClass(a,b,c) {
this._a = a;
this._b = b;
this._c = c;
}
MyNewClass.prototype = new Object();

Google “Flash MX OOP” or “Flash MX prototype” - there are a lot of great tutorials on this subject. I’m sure there’s one here on Kirupa.

Yes, there is a very good one on Kirupa…