# Function in a loop

**URL:** <https://forum.kirupa.com/t/function-in-a-loop/164910>\
**Category:** flash\
**Created:** [October 5, 2005, 10:54pm UTC](https://forum.kirupa.com/t/function-in-a-loop/164910 "2005-10-05T22:54:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pastawoua](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@pastawoua](https://forum.kirupa.com/u/pastawoua)\
**Post date:** [October 5, 2005, 10:54pm UTC](https://forum.kirupa.com/t/function-in-a-loop/164910/1 "2005-10-05T22:54:41Z")

</div>

Hi everyone a problem that makes me nut.  
Have 5 movieclips named mc\_resto1, mc\_resto2, etc… and have this code

```php
for(i = 0; i < 2; i++){
	eval("mc_resto"+i).onRollover = function() {
		trace(i);
	}
}

```

The thing is when i’m doing my rollover on all the mc\_resto it’s tracing 3 and not 0 then 1 then 2.

have also tried something like

```php
for(i = 0; i < 2; i++){
	eval("var"+i) = i;
	eval("mc_resto"+i).onRollover = function() {
		trace(eval("var"+i));
	}
}

```

but it doesnt work

Do you have any idea please?  
Thanks!
