I have a class file called “Character_Gen” that generates a lot of random numbers and stuff and displays them on the stage via text input boxes (for the time being), as well as scaling Movie Clips to provide a visual representation of the data. So far so good…
But recently I have been trying to add buttons so that you can increment and decrease values (variables) in the class file and update the stage to reflect these new values visually. I have written a setter function in my class file that requires two parameters (stat and stat1), it should in theory allow me to enter any two variables from the class file and increment them at the press of a button. But it doesn’t work, the values never change. However the aggravating thing is that it works fine if I don’t use the parameters and write the method with the variables I want. I plan on having a lot of pairs so writing a function for each would really suck…
Here’s some code snippits to help explain:
THIS WORKS!
//this is in my class file Character_Gen.as
public var bravery:Number;
public var cowardly:Number;
bravery = percentage();
trace("bravery " + percent + "%");
cowardly = 100-bravery;
trace("cowardly " + (cowardly) + "%");
}
public function setBraveryUp():Void{
if(bravery<100){
++bravery;
--cowardly;
}else{
//Do Nothing
}
}
//I then call this via my button using this code.
on(press){
_root.Roll_btn.a.setBraveryUp();
}
THIS DOESN’T!
//this is in my class file Character_Gen.as
public var stat:Number;
public var stat1:Number;
public function setStatUp(stat:Number, stat1:Number):Void{
if (stat<100){
++stat;
--stat1;
}else{
//Do nothing.
}
}
//I then call this via my button using this code.
on(press){
_root.Roll_btn.a.setStatUp(_root.Roll_btn.a.bravery, _root.Roll_btn.a.cowardly);
}
This is not the first function with parameters I have had trouble with, when I declared two parameters in my random number function and I called it with two it started throwing out errors claiming it only required one! But that’s a non issue atm…
If I write a getter function, with the same parameters it works fine so I can’t figure out why I can get but not set!