I’ve a feeling this is a simple one. I have a number of buttons for which I generate very similar functions, for instance the machineW1 button generates a function which contains introduceMachine(1), machineW2 button is introduceMachine(2) etc etc.
So I decided to simplify things by using a for loop to create the functions, like this.
for (n=1;n<=8;n++){
target = [“machineW”+n];
_root.wheel.wheelInside.machineW1.onRelease = function(){
introduceMachine(n);}
}
The trouble with this is that the function doesn’t take the current value for n in the introduceMachine(n) part, instead it just uses introduceMachine(n) which when the loop is finished is always 9, so every button creates introduceMachine(9).
How do I get the =function() within the loop to use the current value of n rather than n?