# Object inheritance?

**URL:** https://forum.kirupa.com/t/object-inheritance/20311
**Category:** Uncategorized
**Created:** [May 7, 2003, 12:16pm UTC](https://forum.kirupa.com/t/object-inheritance/20311 "2003-05-07T12:16:50Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![oscar\_alexander](https://avatars.discourse-cdn.com/v4/letter/o/e5b9ba/32.png) [@oscar\_alexander](https://forum.kirupa.com/u/oscar_alexander)
#### Post date: [May 7, 2003, 12:16pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/1 "2003-05-07T12:16:50Z")

</div>

Here’s a bit of code I’m having trouble with:

[AS]  
Recipe = function() {  
this.ingredientPref = 1;  
}

\_global.Pancake = new Recipe();  
[/AS]

As you can see, I’m creating a new instance off the Recipe class, named “Pancake”. Later on, a dialog box will show up (using attachMovie - I’ll save you the code) asking wether or not the user is a vegetarian. In other words, the “ingredientPref” variable should be set from an already existing clip.

**The problem I’m having is this:**

How can I set ingredientPref without referring to the Pancake instance (i.e. Pancake.ingredientPref = 2)? Is there a smart way to change ingredientPref for ALL instances of Recipe at once?

I’ve read something about inheritance, but it didn’t make much sense to me 😉 Thanks!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 12:34pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/2 "2003-05-07T12:34:28Z")

</div>

```auto
Recipe.prototype.ingredientPref = 1;

```

😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 12:38pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/3 "2003-05-07T12:38:05Z")

</div>

_DOH_

_[FONT=courier new][COLOR=green] Oscar Alexander slaps himself around a bit with a large trout[/COLOR][/FONT]_\*

Thanks! 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 12:40pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/4 "2003-05-07T12:40:32Z")

</div>

::slaps oscar alexander with a large trout again:: :trout:

😛

no problem. =)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 12:42pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/5 "2003-05-07T12:42:03Z")

</div>

One more thing though… is any instance of the Recipe class global by default?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 12:45pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/6 "2003-05-07T12:45:12Z")

</div>

nope… :-\

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 12:47pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/7 "2003-05-07T12:47:23Z")

</div>

Ok. Making the constructor global would?

```auto

_global.Recipe = function() { }

Recipe.prototype.bollocks = function() { }

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 12:50pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/8 "2003-05-07T12:50:31Z")

</div>

i don’t think so… but i haven’t tried it. :-\

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 1:08pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/9 "2003-05-07T13:08:26Z")

</div>

Hmm… so far so good. One last thing:

```auto

Recipe = function() {
        this.ingredientPref	= 1;
        this.loadVarsSend	= new LoadVars();
}

_global.Pancake = new Recipe();

```

Is it possible to use the prototype-thingie to add variables to the loadVarsSend object? I know the following doesn’t work, but is there a similar solution?

Recipe.loadVarsSend.prototype.variable = value;

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 1:23pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/10 "2003-05-07T13:23:32Z")

</div>

1. you can set up a function which will create a new Recipe and make it global …

```auto

_global.newGlobalRecipe = function(varName){
	this[varName] = new Recipe();
}
// to make:
newGlobalRecipe("Pancake");
// and now Pancake is a global variable that is a Recipe object.

```

1. for the loadVars object, you can either make a loadVars prototype (though that will effect ALL loadvars object) or keep the value in the prototype of the Recipe object and assign its value to the new loadVars instance in the constructor. i.e.

```auto

_global.Recipe = function() {
	this.ingredientPref	= 1;
	this.loadVarsSend	= new LoadVars();
	this.loadVarsSend.variable = this.lvsValue	
}
Recipe.prototype.lvsValue = "loadVars instance value";
newGlobalRecipe("Pancake");
trace(Pancake.loadVarsSend.variable); // "loadVars instance value"

```

🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 1:26pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/11 "2003-05-07T13:26:12Z")

</div>

```auto
LoadVars.prototype.myName = "kax";

```

?? 😛

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 1:29pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/12 "2003-05-07T13:29:35Z")

</div>

😛

thanks sen… you just saved me the trouble. 😉

and thanks for the ‘little favor’ too. =)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 1:32pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/13 "2003-05-07T13:32:58Z")

</div>

Ah, well I found a workaround that’s better in some ways for the rest of my code.

```auto

_global.Pancake = new Recipe();
_global.objName = "Pancake";

```

Since there is only one instance of the class at a time (I just want to make sure I don’t have to go changing code all over the place if I decide to change its name), I can refer to its specific functions and values like this:

```auto

_global[objName].loadVarsSend.variable = "value";

```

Let me know if this is a REALLY stupid way to deal with it.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 1:37pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/14 "2003-05-07T13:37:40Z")

</div>

not REALLY 😉

- does it work? Thats the #1 question to ask yourself. If it does GREAT!
- can you understand it? thats #2. If you can, GREAT!
- do other people need to and if so, could they? If other people dont have to ever see it, GREAT! - otherwise you need to think about making it comprehendable and understandable (and conform more to standards as a way to enforce that)… but like I said if you’re the only one messing with this… GREAT!

^ if those things are good, then who cares 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 7, 2003, 1:40pm UTC](https://forum.kirupa.com/t/object-inheritance/20311/15 "2003-05-07T13:40:01Z")

</div>

GREAT, then 🙂 Thanks.
