# \[Flash8\] Help needed with as2

**URL:** <https://forum.kirupa.com/t/flash8-help-needed-with-as2/331067>\
**Category:** flash\
**Created:** [May 7, 2013, 3:09pm UTC](https://forum.kirupa.com/t/flash8-help-needed-with-as2/331067 "2013-05-07T15:09:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BigEnglisHoward](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@BigEnglisHoward](https://forum.kirupa.com/u/BigEnglisHoward)\
**Post date:** [May 7, 2013, 3:09pm UTC](https://forum.kirupa.com/t/flash8-help-needed-with-as2/331067/1 "2013-05-07T15:09:49Z")

</div>

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?
