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!
Recipe.prototype.ingredientPref = 1;

DOH
[FONT=courier new][COLOR=green] Oscar Alexander slaps himself around a bit with a large trout[/COLOR][/FONT]*
Thanks! 
::slaps oscar alexander with a large trout again:: :trout:

no problem. =)
One more thing though… is any instance of the Recipe class global by default?
Ok. Making the constructor global would?
_global.Recipe = function() { }
Recipe.prototype.bollocks = function() { }
i don’t think so… but i haven’t tried it. :-\
Hmm… so far so good. One last thing:
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;
- you can set up a function which will create a new Recipe and make it global …
_global.newGlobalRecipe = function(varName){
this[varName] = new Recipe();
}
// to make:
newGlobalRecipe("Pancake");
// and now Pancake is a global variable that is a Recipe object.
- 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.
_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"

LoadVars.prototype.myName = "kax";
?? 

thanks sen… you just saved me the trouble. 
and thanks for the ‘little favor’ too. =)
Ah, well I found a workaround that’s better in some ways for the rest of my code.
_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:
_global[objName].loadVarsSend.variable = "value";
Let me know if this is a REALLY stupid way to deal with it.
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 