# Trouble with loop (simple i think)

**URL:** <https://forum.kirupa.com/t/trouble-with-loop-simple-i-think/222821>\
**Category:** flash\
**Created:** [April 17, 2007, 9:46am UTC](https://forum.kirupa.com/t/trouble-with-loop-simple-i-think/222821 "2007-04-17T09:46:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iamthejuggler](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Iamthejuggler](https://forum.kirupa.com/u/Iamthejuggler)\
**Post date:** [April 17, 2007, 9:46am UTC](https://forum.kirupa.com/t/trouble-with-loop-simple-i-think/222821/1 "2007-04-17T09:46:02Z")

</div>

Hi,

I have been stuck on this same problem a number of times and would really like to figure out the solution, which i have no doubt is simple once you know, but it currently eludes me!

Basically I want to assign a function on a number of buttons named “disc1”,“disc2” etc. I want them to have a mouseDown function that sets a global variable to 1,2,3 etc based on the disc number.

This is what i thought would work but obviously it doesn’t!

[INDENT][COLOR=Red]for (i=1;i\<5;i++)[/COLOR]  
[COLOR=Red]{[/COLOR]  
[COLOR=Red] name=“disc”+i;[/COLOR]  
[COLOR=Red] [name]onMouseDown = function(){[/COLOR]  
[COLOR=Red] activeDisc=i;[/COLOR]  
[COLOR=Red] }[/COLOR]  
[COLOR=Red]}[/COLOR]  
[/INDENT][COLOR=Red]  
[COLOR=Black]  
How should I do this instead?

Thanks for any help 🙂  
[/COLOR][/COLOR]
