# Code doesn't work as it should .... help!

**URL:** <https://forum.kirupa.com/t/code-doesnt-work-as-it-should-help/186580>\
**Category:** Uncategorized\
**Created:** [April 22, 2006, 3:41pm UTC](https://forum.kirupa.com/t/code-doesnt-work-as-it-should-help/186580 "2006-04-22T15:41:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ovidio](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ovidio/32/2379_2.png) [@ovidio](https://forum.kirupa.com/u/ovidio)\
**Post date:** [April 22, 2006, 3:41pm UTC](https://forum.kirupa.com/t/code-doesnt-work-as-it-should-help/186580/1 "2006-04-22T15:41:47Z")

</div>

I’m trying to make a scroller for a photo gallery and the problem is that the code below should work properly but it doesn’t!!!  
when I “release” the mouse button after pressing over a thumbnail, instead of giving me it’s specific “i” it gives me “i” max +1 (in this case 37)… no matter on what thumbnail i press.  
Does anyone have an explanation for this?  
//////////////////////////////////////////////////////////////////////////////  
var thumbWidth:Number=30;  
var thumbInterspace:Number=10;  
var myPics:Array=Array(36);  
//filmStrip is an empty movieClip on stage

for (var i:Number = 1; i\<=myPics.length; i++) {  
filmStrip.attachMovie(“pic”+i, “thumb”+i, filmStrip.getNextHighestDepth());  
filmStrip[“thumb”+i].\_x = (i-1)\*(thumbWidth+thumbInterspace);  
filmStrip[“thumb”+i].\_y = 10;  
filmStrip[“thumb”+i].onRelease=function() {  
//code here  
trace(i);  
}  
}

---

<div class="post-metadata">

**Author:** ![Mirandir](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Mirandir](https://forum.kirupa.com/u/Mirandir)\
**Post date:** [April 22, 2006, 5:10pm UTC](https://forum.kirupa.com/t/code-doesnt-work-as-it-should-help/186580/2 "2006-04-22T17:10:21Z")

</div>

Well it returns 37 because “i” is 37 whe the onRelease event fires.

To get what you want you need to assign the current value of “i” to a variable on the movieclip. And then you use that in the onRelase event.

```auto

for (var i:Number = 1; i<=myPics.length; i++) {
   filmStrip.attachMovie("pic"+i, "thumb"+i, filmStrip.getNextHighestDepth());
   filmStrip["thumb"+i]._x = (i-1)*(thumbWidth+thumbInterspace);
   filmStrip["thumb"+i]._y = 10;
   filmStrip["thumb"+i].num = i;
   filmStrip["thumb"+i].onRelease=function() {
      //code here
      trace(this.num);
   }
}

```

/Mirandir

---

<div class="post-metadata">

**Author:** ![ovidio](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ovidio/32/2379_2.png) [@ovidio](https://forum.kirupa.com/u/ovidio)\
**Post date:** [April 22, 2006, 6:17pm UTC](https://forum.kirupa.com/t/code-doesnt-work-as-it-should-help/186580/3 "2006-04-22T18:17:53Z")

</div>

beautiful 🙂 I got it 🙂  
thanks Mirandir!
