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

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);
}
}

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.


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

beautiful :slight_smile: I got it :slight_smile:
thanks Mirandir!