# "function" and "new"

**URL:** <https://forum.kirupa.com/t/function-and-new/118751>\
**Category:** Uncategorized\
**Created:** [August 8, 2004, 10:21pm UTC](https://forum.kirupa.com/t/function-and-new/118751 "2004-08-08T22:21:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilayeggs](https://avatars.discourse-cdn.com/v4/letter/i/4af34b/32.png) [@ilayeggs](https://forum.kirupa.com/u/ilayeggs)\
**Post date:** [August 8, 2004, 10:21pm UTC](https://forum.kirupa.com/t/function-and-new/118751/1 "2004-08-08T22:21:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tompatros](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@tompatros](https://forum.kirupa.com/u/tompatros)\
**Post date:** [August 13, 2004, 3:24am UTC](https://forum.kirupa.com/t/function-and-new/118751/2 "2004-08-13T03:24:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [August 13, 2004, 10:30am UTC](https://forum.kirupa.com/t/function-and-new/118751/3 "2004-08-13T10:30:48Z")

</div>

> [@tompatros](#):
>
> - 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…

> **[kirupa.com - Object Oriented Programming](https://www.kirupa.com/developer/oop/)**
>
> An introduction to object-oriented programming in Flash.
