# Need help with storing loop value in movieclip

**URL:** <https://forum.kirupa.com/t/need-help-with-storing-loop-value-in-movieclip/64583>\
**Category:** flash\
**Created:** [September 17, 2004, 4:58pm UTC](https://forum.kirupa.com/t/need-help-with-storing-loop-value-in-movieclip/64583 "2004-09-17T16:58:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gazc](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@gazc](https://forum.kirupa.com/u/gazc)\
**Post date:** [September 17, 2004, 4:58pm UTC](https://forum.kirupa.com/t/need-help-with-storing-loop-value-in-movieclip/64583/1 "2004-09-17T16:58:00Z")

</div>

This is really holding me up, so I hope someone can help me fast.

I need to store each value of my for loop in a separate instance of my movieclip, but the movieclip only seems to pick up the last value of the loop.

Why is this and can I do this any other way apart from storing the value in a textfield or creating a loop within the movieclip?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 17, 2004, 5:14pm UTC](https://forum.kirupa.com/t/need-help-with-storing-loop-value-in-movieclip/64583/2 "2004-09-17T17:14:29Z")

</div>

> [@gazc](#):
>
> This is really holding me up, so I hope someone can help me fast.
> 
> I need to store each value of my for loop in a separate instance of my movieclip, but the movieclip only seems to pick up the last value of the loop.
> 
> Why is this and can I do this any other way apart from storing the value in a textfield or creating a loop within the movieclip?

can show copy/paste the code

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 17, 2004, 6:51pm UTC](https://forum.kirupa.com/t/need-help-with-storing-loop-value-in-movieclip/64583/3 "2004-09-17T18:51:36Z")

</div>

In the end I got it to work by combining two methods. I used the following code:

in main timeline:

for (var i=0; i \< 3; i++){  
this.attachMovie(“mcClip”,“clip”+i,i);  
this[“clip”+i].count=i;  
}

in mcClip:

var loopval=count;  
// this was set to 0 previously, which blanked out the loaded value.  
this.onPress = function(){  
trace(loopval);  
}

thought this might help anyone who is having the same problem.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 18, 2004, 4:18am UTC](https://forum.kirupa.com/t/need-help-with-storing-loop-value-in-movieclip/64583/4 "2004-09-18T04:18:54Z")

</div>

attachMovie, Loadmovie, gotoplay etc all are executed after all the frame code is executed.

so do something like this

// frame 5  
for (var i=0; i \< 3; i++){  
this.attachMovie(“mcClip”,“clip”+i,i);  
}  
// frame 7  
for (var i=0; i \< 3; i++){  
this[“clip”+i].count=i;  
}
