# Forloop, a method to store i

**URL:** <https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769>\
**Category:** Uncategorized\
**Created:** [June 19, 2008, 1:46am UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769 "2008-06-19T01:46:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)\
**Post date:** [June 19, 2008, 1:46am UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/1 "2008-06-19T01:46:56Z")

</div>

i basically have a gallery with thumbs loaded in via xml.

and then a currentThumb.onRollover function depending on which thumb was clicked.

Now this is all within the forloop function on frame1.

what if I want the actions to occur on frame 2 of the main timeline after the coinciding thumb has been clicked. How can I determine which thumb was clicked?

I tried using a \_global.id = i; but that doesnt store the correct value from the loop.

any ideas?

---

<div class="post-metadata">

**Author:** ![DaRicardo](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@DaRicardo](https://forum.kirupa.com/u/DaRicardo)\
**Post date:** [June 19, 2008, 2:08am UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/2 "2008-06-19T02:08:08Z")

</div>

try this:

1. You could assign a “selected” variable to each movieClip. In other words, when you go through the whole for loop involving thumb.onRelease = functionToMakeItCurrentThumb, make it thumb.current = false;  
That way in frame 2 each thumb will have attached to it a value of true or false for whether it’s selected. just check with another for loop.

could either post the .fla or some of the code? its sorta difficult to get a sense of the issue

---

<div class="post-metadata">

**Author:** ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)\
**Post date:** [June 19, 2008, 2:15am UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/3 "2008-06-19T02:15:35Z")

</div>

function ScreenprintsLoad(screenprints\_xml) {

```
var screenprintsThumbs = screenprints_xml.firstChild.firstChild.childNodes;

maincontent.createEmptyMovieClip("holder",1);

for (var i = 0; i&lt;screenprintsThumbs.length; i++) {

	var currentPicture = screenprintsThumbs*;

	var currentThumb = maincontent.holder.createEmptyMovieClip("thumb_mc"+i, i);
	var containerThumb = currentThumb.createEmptyMovieClip("container"+i, i);

	currentThumb._x = i*100;

	var fabricName = currentThumb.createTextField("fabric_name"+i, i+1, -50, -80, 100, 100);

	fabricName.autoSize = "center";
	

	fabricName.text = currentPicture.attributes.fabricname;
	var style_fmt:TextFormat = new TextFormat();
	style_fmt.font = "Times New Roman";
	style_fmt.color = 0x666666;
	style_fmt.size = 12;
	fabricName.antiAliasType = "normal";
	fabricName.setTextFormat(style_fmt);

	currentThumb.attachMovie("thumb_bg_mc","thumb_bg_mc"+i,i-1);

	currentThumb.onRelease = function() { //heres where I want it to go to Frame 2

	

	};
	var mcl:MovieClipLoader = new MovieClipLoader();
	mcl.loadClip(currentPicture.attributes.largethumb,containerThumb);

	var container:Object = new Object();
	mcl.addListener(container);

	container.onLoadInit = function(target:MovieClip) {
		target._x = target._x-(target._width/2);
		target._y = target._y-(target._height/2);

	};
}

```

}

//create xml object and load the xml data  
var theContent:XML = new XML();

theContent.ignoreWhite = true;

theContent.load(“content.xml”);

theContent.onLoad = parseXMLData;

function parseXMLData(success:Boolean):Void {

```
//make sure the data is loaded and usable

if (success && this.status == 0) {
	ScreenprintsLoad(this);
}

```

}  
stop();

---

<div class="post-metadata">

**Author:** ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)\
**Post date:** [June 19, 2008, 11:32am UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/4 "2008-06-19T11:32:44Z")

</div>

create an array or something?

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 19, 2008, 12:31pm UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/5 "2008-06-19T12:31:42Z")

</div>

Assign the value of i to a property of each button:

> **[Saving the value of 'i' in a for loop](https://www.kirupa.com/forum/showthread.php?t=296221)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

Maybe this will work:  
var currentThumb = maincontent.holder.createEmptyMovieClip(“thumb\_mc” +i, i);  
this[“thumb\_mc” + i].button\_number = i;

---

<div class="post-metadata">

**Author:** ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)\
**Post date:** [June 19, 2008, 1:35pm UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/6 "2008-06-19T13:35:19Z")

</div>

Thanks but its not working for me…

I dont really understand it enough to make it work for my code. What is “this” referring to in this case? Cant I just use currentThumb.button\_number = i;?

in the end it just gives me that last value of i.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 19, 2008, 2:17pm UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/7 "2008-06-19T14:17:12Z")

</div>

“this” refers to the newly created movieclip. You could use currentThumb.button\_number instead.  
If you check that external link, it shows how to use it with an onRelease event and the question has also been asked here before:

> **[For Loop - simple question](https://www.kirupa.com/forum/showthread.php?t=299985)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

---

<div class="post-metadata">

**Author:** ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)\
**Post date:** [June 19, 2008, 4:44pm UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/8 "2008-06-19T16:44:00Z")

</div>

Great! thanks it worked.

in my currentThumb.onRelease function

I had currentThumb.id but it did not work. having this.id works.

Why is this? isn’t it technically the same thing?

---

<div class="post-metadata">

**Author:** ![DaRicardo](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@DaRicardo](https://forum.kirupa.com/u/DaRicardo)\
**Post date:** [June 20, 2008, 2:26am UTC](https://forum.kirupa.com/t/forloop-a-method-to-store-i/263769/9 "2008-06-20T02:26:44Z")

</div>

I’ve had issues with that sort of thing before… It has to do with the fact that currentThumb is a local variable created in the for loop. Even though your onRelease is also in the for loop, it works as if it’s outside. using “this” lets the onRelease function know to reference the MC that it’s a part of, so to speak. I’ll bet if you try to trace “currentThumb” within the onRelease, it will be undefined.
